slider raise last record?

Hello expert...
After the cursor to the folder of emp table... but finally view record displayinmg 2 time why?

declare
cursor c1 is
Select empno, ename from emp;
l emp.empno%type;
m emp.ename%type;
Start
Open c1;
loop
extract the c1 in l, m;
-When exit c1% notfound;
dbms_output.put_line(l||) e -'|| (m);
/ * If c1% notfound then
"exit";
end if; */
When exit c1% notfound;
end loop;
Close c1;
end;

MONOSTABLE:
7369 SMITH
7499-ALLEN
7521 WARD
7566 JONES
7654-MARTIN
7698 BLAKE
7782-CLARK
7788-SCOTT
7839 KING
7844-TURNER
7876 ADAMS
7900-JAMES
7902 FORD
7934 MILLER
7934 MILLER
PL/SQL procedure successfully completed.

Why?

Thank you best regards n
Yoann

yash_08031983 wrote:

After the cursor to the folder of emp table... but finally view record displayinmg 2 time why?

Because it is explicitly indicated by the source code.

-extraction of the last line.
-display the family name.
-East of expressions of folklore for the whole of the cursor? No - the fact ' pointer' cursor still refers to a valid line
-loop iterates again
-Retrieves the next line - does not exist, then the cursor of the folklore about
-display the family name. Once again.
-East of expressions of folklore for the whole of the cursor? Yes - put end loop

Tags: Database

Similar Questions

  • Cursor does not properly... Gives entry each record last records.

    Hi all.

    a simple for someone, I'm sure...

    I've just added the cursor:

    -- ***************************************************
    -The cursor for Oracle_Loc_Code de SU CHRIS vs ORACLE table locations in a variable...
    -- ***************************************************

    CURSOR csr_ora_loc_code IS
    SELECT sil. ORACLE_LOC_CODE
    OF std, sil SU_IEXP_LOCATIONS SU_TEMPLOYEE_DETAILS
    WHERE STDS. STD_LOCATION_ID = sil. CHRIS_LOC_code;

    .. the script I paste below in order to complete each record with what in LIS. Field ORACLE_LOC_CODE.

    But, although it works fine when you have 1 card to run at, where several records need to be loaded together, the script, well between records in ORACLE thin, fills all records with the same store code - whatevers in the last record (instead of dealing with each of them individually). How can I fix?

    Thanks for looking...

    The code...
    /* Formatted on 2009/04/29 11:52 (Formatter Plus v4.8.7) */
    SET serveroutput ON SIZE 1000000 FORMAT WRAPPED
    SET verify OFF
    SET feedback OFF
    
    DECLARE
    -- *********
    -- Debugging/error handling
    -- *********
    -- *********
    -- Work variables
    -- *********
    
       ora_loc_code number                     := 0;
       p_emp_number                     VARCHAR2 (14);
       v_rec_cnt                        NUMBER                          := 0;
       insert_flag                      VARCHAR2 (8);
       err_num                          NUMBER;
       err_msg                          VARCHAR2 (150);
       err_line                         VARCHAR2 (350);
       err_seq                          NUMBER                          := 0;
       l_validate                       BOOLEAN                     DEFAULT FALSE;
       l_std_business_group_id          NUMBER                          := '0';
       l_default_code_comb_id           NUMBER                        := '217269';
       l_organization_id                NUMBER                          := '0';
       l_set_of_books_id                NUMBER                          := '1';
       l_job_id                         NUMBER                          := '10';
       l_obj                            NUMBER;
       l_datetrack_update_mode          VARCHAR2 (30)             := 'CORRECTION';
       l_assignment_sequence            NUMBER;
       l_name_combination_warning       BOOLEAN                         := FALSE;
       l_assign_payroll_warning         BOOLEAN                         := FALSE;
       l_org_now_no_manager_warning     BOOLEAN;
       l_other_manager_warning          BOOLEAN;
       l_spp_delete_warning             BOOLEAN;
       l_entries_changed_warning        VARCHAR2 (30);
       l_tax_district_changed_warning   BOOLEAN;
       l_person_id                      NUMBER;
       l_assignment_id                  NUMBER;
       l_special_ceiling_step_id        NUMBER;
       l_per_effective_end_date         DATE:= TO_DATE ('11-Jul-2049', 'DD-MON-YYYY');
       l_people_group_id                NUMBER;
       l_group_name                     VARCHAR2 (30);
       l_assignment_number              VARCHAR2 (35);
       l_effective_end_date             DATE := TO_DATE ('11-Jul-2049', 'DD-MON-YYYY');
       l_date                           DATE                           := SYSDATE;
       ip_p_address_id                  per_addresses.address_id%TYPE;
       ip_p_object_version_number       NUMBER;
       ip_p_party_id                    per_addresses.party_id%TYPE;
       l_per_object_version_number      NUMBER;
       l_asg_object_version_number      NUMBER;
       l_full_name                      VARCHAR2 (240);
       l_per_comment_id                 NUMBER;
       l_per_effective_start_date       DATE;
       l_concatenated_segments          VARCHAR2 (240);
       l_soft_coding_keyflex_id         NUMBER;
       l_comment_id                     NUMBER;
       l_no_managers_warning            BOOLEAN;
    
    -- ***********************************
    -- Get employee details info from work table
    -- ***********************************
       CURSOR get_employee_details
       IS
          SELECT std_hire_date, std_last_name, std_sex, std_date_of_birth,
                 std_email_address,
                 LPAD (std_employee_number, 8, '0') std_employee_number,
                 std_first_name, std_marital_status, std_middle_names,
                 std_nationality, std_title, std_national_identifier,
                 std_address_line1, std_address_line2, std_address_line3,
                 std_address_line4, std_post_code, std_telephone_1, std_country,
                 std_region, std_location_id, std_organization_id,
                 std_supervisor_id, std_person_id, std_position_id
            FROM SU_TEMPLOYEE_DETAILS;
    
    -- *****************************************
    -- checks employee details info from PER_ALL_PEOPLE_F table
    -- *****************************************
       CURSOR c_check_employee (p_emp_number VARCHAR2)
       IS
          SELECT per.person_id, per.business_group_id, per.last_name,
                 per.start_date, per.date_of_birth, per.email_address,
                 per.employee_number, per.first_name, per.marital_status,
                 per.middle_names, per.nationality, per.national_identifier,
                 per.sex, per.title, padd.address_id, padd.primary_flag,
                 padd.address_line1, padd.address_line2, padd.address_line3,
                 padd.town_or_city, padd.postal_code, padd.telephone_number_1,
                 paas.assignment_number, paas.object_version_number
            --  padd.telephone_number_2, padd.telephone_number_3, paas.job_id, paas.location_id,
            --  paas.organization_id, paas.assignment_type, paas.supervisor_id,
            --  paas.default_code_comb_id, paas.set_of_books_id, paas.period_of_service_id,
          FROM   per_all_people_f per,
                 per_all_assignments_f paas,
                 per_addresses padd
           WHERE per.employee_number = p_emp_number
             AND per.person_id = padd.person_id
             AND paas.person_id(+) = per.person_id;
    
       emp_rec                          c_check_employee%ROWTYPE;
    
    -- ***************************************************
    -- Cursor retrieves latest Object Version Number from per_assignments_f table..
    -- ***************************************************
       CURSOR csr_ovn (cp_person_id IN per_all_people_f.person_id%TYPE)
       IS
          SELECT MAX (paas.object_version_number)
            FROM per_assignments_f paas, per_all_people_f per
           WHERE paas.person_id = per.person_id
             AND per.employee_number = paas.assignment_number
             AND per.person_id = cp_person_id;
    
    
    -- ***************************************************
    -- Cursor to get Oracle_Loc_Code from SU CHRIS vs ORACLE Locations Table into a variable..
    -- ***************************************************
    
         CURSOR csr_ora_loc_code IS
          SELECT sil.ORACLE_LOC_CODE
         -- INTO ora_loc_code
         FROM SU_TEMPLOYEE_DETAILS std, SU_IEXP_LOCATIONS sil
         WHERE std.STD_LOCATION_ID = sil.CHRIS_LOC_code;
    
    
    BEGIN
    -- ***********************************
    -- Process each record in the work table
    -- ***********************************
       FOR v_emp IN get_employee_details
       LOOP
    -- ************************************
    -- determine whether customer already exists
    -- ************************************
          OPEN c_check_employee (v_emp.std_employee_number);
    
          FETCH c_check_employee
           INTO emp_rec;
    
          IF c_check_employee%NOTFOUND
          THEN
             insert_flag := 'I';
             DBMS_OUTPUT.PUT_LINE ('Employee No: ' || v_emp.std_employee_number);
          ELSE
             DBMS_OUTPUT.PUT (CHR (10));
             insert_flag := 'X';
           RAISE_APPLICATION_ERROR (-20001,  'Employee No: ' || v_emp.std_employee_number  || '  already 
    
    exists - please  UPDATE  manually..'    );
           END IF;
    
          CLOSE c_check_employee;
    
    -- ************************************
    -- Obtain the most recent Object Version Number..
    -- ************************************
          OPEN csr_ovn (v_emp.std_person_id);
    
          FETCH csr_ovn
           INTO l_obj;
    
          -- IF csr_ovn%NOTFOUND     THEN        RAISE NO_DATA_FOUND;   END IF;
          CLOSE csr_ovn;
    
    -- ************************************
    -- Open Oracle Location Code cursor 
    -- ************************************
          OPEN csr_ora_loc_code;   -- (v_emp.std_person_id);
          FETCH csr_ora_loc_code
           INTO ora_loc_code;
          CLOSE csr_ora_loc_code;
    
    
    -- ***********************************
    -- Create new PER_ALL_PEOPLE_F and PER_ADDRESSES record from
    --            info in  table record
    -- ***********************************
          IF insert_flag = 'I'
          THEN
    --         BEGIN                             -- Importing Employee Procedure --
             Hr_Employee_Api.create_gb_employee
                     (p_validate                       => l_validate,
                      p_hire_date                      => v_emp.std_hire_date,
                      p_business_group_id              => l_std_business_group_id,
                      p_date_of_birth                  => v_emp.std_date_of_birth,
                      p_email_address                  => v_emp.std_email_address,
                      p_first_name                     => v_emp.std_first_name,
                      p_middle_names                   => v_emp.std_middle_names,
                      p_last_name                      => v_emp.std_last_name,
                      p_sex                            => v_emp.std_sex,
                      p_ni_number                      => v_emp.std_national_identifier,
                      p_employee_number                => v_emp.std_employee_number,
                      p_person_id                      => l_person_id,
                      p_title                          => v_emp.std_title,
                      p_assignment_id                  => l_assignment_id,
                      p_per_object_version_number      => l_per_object_version_number,
                      p_asg_object_version_number      => l_asg_object_version_number,
                      p_per_effective_start_date       => l_per_effective_start_date,
                      p_per_effective_end_date         => l_per_effective_end_date,
                      p_full_name                      => l_full_name,
                      p_per_comment_id                 => l_per_comment_id,
                      p_assignment_sequence            => l_assignment_sequence,
                      p_assignment_number              => l_assignment_number,
                      p_name_combination_warning       => l_name_combination_warning,
                      p_assign_payroll_warning         => l_assign_payroll_warning
                     );
             Hr_Person_Address_Api.create_person_address
                                      (p_validate                     => l_validate,
                                       p_effective_date               => v_emp.std_hire_date,
                                       p_pradd_ovlapval_override      => NULL,
                                       p_validate_county              => NULL,
                                       p_person_id                    => l_person_id,
                                       p_primary_flag                 => 'Y',
                                       p_style                        => 'GB_GLB',
                                       p_date_from                    => SYSDATE,
                                       p_date_to                      => NULL,
                                       p_address_type                 => NULL,
                                       p_comments                     => NULL,
                                       p_address_line1                => v_emp.std_address_line1,
                                       p_address_line2                => v_emp.std_address_line2,
                                       p_address_line3                => v_emp.std_address_line3,
                                       p_town_or_city                 => v_emp.std_address_line4,
                                       p_region_1                     => NULL,
                                       p_region_2                     => NULL,
                                       p_region_3                     => NULL,
                                       p_postal_code                  => v_emp.std_post_code,
                                       p_country                      => v_emp.std_nationality,
                                       p_telephone_number_1           => NULL,
                                       p_telephone_number_2           => NULL,
                                       p_telephone_number_3           => NULL,
                                       p_party_id                     => ip_p_party_id,
                                       p_address_id                   => ip_p_address_id,
                                       p_object_version_number        => l_obj
                                      );
             Hr_Assignment_Api.update_emp_asg
                            (p_validate                    => l_validate,
                             p_effective_date              => SYSDATE,  -- l_date,
                             p_datetrack_update_mode       => l_datetrack_update_mode,
                             p_assignment_id               => l_assignment_id,
                             p_object_version_number       => l_obj,
                             p_supervisor_id               => v_emp.std_supervisor_id,
                             p_default_code_comb_id        => l_default_code_comb_id,
                             p_set_of_books_id             => l_set_of_books_id,
                             p_concatenated_segments       => l_concatenated_segments,
                             --IN/OUT
                             p_soft_coding_keyflex_id      => l_soft_coding_keyflex_id,
                             --IN/OUT
                             p_comment_id                  => l_comment_id,
                             --IN/OUT
                             p_effective_start_date        => l_date,     --IN/OUT
                             p_effective_end_date          => l_effective_end_date,
                             --IN/OUT
                             p_no_managers_warning         => l_no_managers_warning,
                             --IN/OUT
                             p_other_manager_warning       => l_other_manager_warning
                            --IN/OUT
                            );
             Hr_Assignment_Api.update_emp_asg_criteria
                 (p_validate                          => l_validate,
                  p_effective_date                    => SYSDATE,       -- l_date,
                  p_datetrack_update_mode             => l_datetrack_update_mode,
                  p_assignment_id                     => l_assignment_id,
                  p_object_version_number             => l_obj,
                  p_organization_id                   => l_organization_id,
                  p_location_id                       => ora_loc_code,
                  p_job_id                            => l_job_id,
                  p_position_id                       => v_emp.std_position_id,
                  p_special_ceiling_step_id           => l_special_ceiling_step_id,
                  p_effective_start_date              => l_date,
                  --per_effective_start_date,
                  p_effective_end_date                => l_effective_end_date,
                  --IN/OUT
                  p_people_group_id                   => l_people_group_id,
                  --IN/OUT
                  p_group_name                        => l_group_name,    --IN/OUT
                  p_org_now_no_manager_warning        => l_org_now_no_manager_warning,
                  --IN/OUT
                  p_other_manager_warning             => l_other_manager_warning,
                  --IN/OUT
                  p_spp_delete_warning                => l_spp_delete_warning,
                  --IN/OUT
                  p_entries_changed_warning           => l_entries_changed_warning,
                  --IN/OUT
                  p_tax_district_changed_warning      => l_tax_district_changed_warning
                 --IN/OUT
                 );
             v_rec_cnt := v_rec_cnt + 1;
             DBMS_OUTPUT.PUT (CHR (10));
             DBMS_OUTPUT.PUT_LINE (   'There were '
                                   || v_rec_cnt
                                   || '  records read in..'
                                  );
             DBMS_OUTPUT.PUT (CHR (10));
    -- ******************************
    -- End of customer related details
    -- ******************************
          END IF;
       END LOOP;
    
       COMMIT;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          ROLLBACK;
       WHEN OTHERS
       THEN
          ROLLBACK;
          err_num := TO_CHAR (SQLCODE);
          err_msg := SUBSTR (SQLERRM, 1, 150);
          err_line :=   'ORACLE error occurred processing record.. ' ||  err_msg;
          DBMS_OUTPUT.PUT_LINE (err_line);
    
          INSERT INTO SU_SL_ERRORS  VALUES (err_num, err_msg, SYSTIMESTAMP);
    END;
    /
    
    EXIT;

    CURSOR csr_ora_loc_code IS

    SELECT sil. ORACLE_LOC_CODE
    -BY ora_loc_code
    OF std, sil SU_IEXP_LOCATIONS SU_TEMPLOYEE_DETAILS
    WHERE STDS. STD_LOCATION_ID = sil. CHRIS_LOC_code; OPEN csr_ora_loc_code. -(v_emp.std_person_id);
    EXTRACTION csr_ora_loc_code
    IN ora_loc_code;
    CLOSE Csr_ora_loc_code;

    Of course Yes.

    He chooses a sil. ORACLE_LOC_CODE, you are to pick up a. Which may be one of the sil. ORACLE_LOC_CODE, you don't like Oracle to choose an individual.
    If you want to get a few specific sil. ORACLE_LOC_CODE, you need to put a filter on it.

         CURSOR csr_ora_loc_code(p_your_parameter NUMBER) IS -- whatever datatype you wan to pass
          SELECT sil.ORACLE_LOC_CODE
         -- INTO ora_loc_code
         FROM SU_TEMPLOYEE_DETAILS std, SU_IEXP_LOCATIONS sil
         WHERE std.STD_LOCATION_ID = sil.CHRIS_LOC_code
         AND your_column = p_your_parameter;
    
          OPEN csr_ora_loc_code(v_emp.std_person_id);   -- (v_emp.std_person_id); -- I'm not sure why did you comment this out.
          FETCH csr_ora_loc_code
           INTO ora_loc_code;
          CLOSE csr_ora_loc_code;
    

    By
    VAMSi

  • Cursor Oracle return only the last record

    I am a newbie in oracle stored proc. I tried to select data using the slider, but it only return last record. The recording must be greater than 1.

    CREATE or REPLACE procedure MySchema.Test (myrefcur on sys_refcursor)
    Is

    Begin
    declare

    Cursor C1 IS

    Select mySerialNum from TableA;
    MyRecord C1% rowtype;

    Begin
    Open C1;
    Loop
    Fetch C1 into myrecord;
    When the output C1% NotFound;

    Open for Myrefcur
    Select SerialNumB from TableB where SerialNumB = myrecord.mySerialNum;

    End loop;
    Close C1;
    End;
    end;

    However, it only returns the last record in the list.

    Original case *.
    The original code is as below:

    1st, I'll need to select a list of ImageSerialNum of ImageSerial

    * 1 query:
    Select A.ImageSerialNum from ImageSerial A, ProductionOrder B, Bom C
    Where A.ProductionOrderID = B.ProductionOrderID And B.Assembly_Num = C.Model_Num and
    B.Revision = C.Revision And B.EngRevision = C.EngRevision and
    C.Bom_ID = passInVariable* and C.FactoryID = "7"

    2nd, I'll need to check the process of EACH series with the code below:

    * Low code a return process for 1 series only.

    Select t.processid, t.processname, t.assembly_num, t.revision, t.engrevision of
    (Select p.ProcessID, p.ProcessName, in. Assembly_Num, in. review, in. EngRevision, im.imageserialnum
    Process p, Routesequence rs, Imageserial im, ProductionOrder in.
    Where im. ImageserialNum = SerialNum* and p.ProcessID = rs. ProcessID
    And rs. RouteID = in. RouteID and rs. SequenceID = im. NextRouteSequence
    And in. ProductionOrderID = im. ProductionOrderID AND IM. STATUS OF '0'
    UNION
    SELECT A.REWORKROUTEID AS PROCESSID PROCESSNAME AS B.ROUTENAME, C.ASSEMBLY_NUM, C.REVISION, C.ENGREVISION, a.imageserialnum
    OF IMAGESERIAL A, B OF ROAD, PRODUCTIONORDER C
    WHERE A.REWORKROUTEID = B.ROUTEID AND A.IMAGESERIALNUM = SerialNum*.
    AND A.PRODUCTIONORDERID = C.PRODUCTIONORDERID and a.status = '0') t

    After that, I would like to combine the two in 1 stored proc code.

    in this case, you just want to join the two applications to use in the FROM clause
    As I don't have your tables, I created two tables, each representing the results of your queries. Substitute the names of table with your queries

    SQL> drop table master
      2  /
    
    Table dropped.
    
    SQL> drop table details
      2  /
    
    Table dropped.
    
    SQL>
    SQL> create table master
      2  (ImageSerialNum varchar2(25));
    
    Table created.
    
    SQL>
    SQL>
    SQL> insert into master values ('Serial1');
    
    1 row created.
    
    SQL> insert into master values ('Serial2');
    
    1 row created.
    
    SQL> insert into master values ('Serial3');
    
    1 row created.
    
    SQL> insert into master values ('Serial4');
    
    1 row created.
    
    SQL> insert into master values ('Serial5');
    
    1 row created.
    
    SQL>
    SQL> create table details
      2  (ImageSerialNum  varchar2(25)
      3  ,ProcessID  number
      4  ,ProcessName varchar2(25)
      5  );
    
    Table created.
    
    SQL>
    SQL> insert into details values ('Serial1',  1, 'Process1');
    
    1 row created.
    
    SQL> insert into details values ('Serial3',  3, 'Process3');
    
    1 row created.
    
    SQL> insert into details values ('Serial5',  5, 'Process5');
    
    1 row created.
    
    SQL>
    SQL> select m.imageserialnum
      2       , d.processid
      3       , d.processname
      4    from master m
      5    left outer
      6    join details d
      7      on (m.imageSerialnum = d.imageserialnum)
      8   order by m.imageserialnum
      9  /
    
    IMAGESERIALNUM             PROCESSID PROCESSNAME
    ------------------------- ---------- -------------------------
    Serial1                            1 Process1
    Serial2
    Serial3                            3 Process3
    Serial4
    Serial5                            5 Process5
    

    your query will be something like

    select m.imageserialnum
         , d.processid
         , d.processname
      from () m
      left outer
      join (
    
  • Properties of the file - Date of the last recorded

    Hello.

    I'm having trouble understanding the properties of the file, as "Last record Date" (DLS) and "Date modified" (MD).

    I asked that the last of them, MD, has been changed whenever the content has changed. But Distribution lists must be updated also.

    However, I have a file which has the DLS on 2007 and MD 2014 and the 'last impression"also is 2014.

    How is that possible?

    What has changed the date the content of the file was really the last?

    I would be grateful if someone could help me understand this.

    Thank you,

    Nuno Roque

    Modification date is when the file got changed on that hard drive.  Even if you have never opened the file, just drag-and - drop it to drive flash (for an example) would last updated date change, because the file on this disk changed really.

    Properties such as "Date of last recorded" and "date printed" are stored in the file itself, such as metadata and are updated no not by disk or operating system, but by the design (such as Word) program.

  • Select the last record of each month

    Hello

    to select the last docnumber and qty of every month

    Structure

    Name Null?    Type

    ------------------------------- -------- ----

    PRODUCTCODE NUMBER

    NUMBER NUMBER

    DATE OF PLANFORMONTH

    NUMBER OF CLEXPECTEDQTY

    NUMBER OF CLCONFIRMQTY

    NUMBER OF CLFGBUFFERQTY

    NUMBER OF CLTOTPRINTBUFFER

    in this select query if I take the sum he required all records where, as I want the last record of each month

    SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.

    SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)

    GROUP BY productcode, (planformonth)

    Sandy

    Hello

    Thanks its working now the code is written as below:

    SELECT * FROM

    (SELECT

    e.*,

    ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r

    Of

    E FGSALESPLAN)

    WHERE r = 1 AND

    entryvalid = 'Y '.

    order by Number

    Sandy

  • Add a string to the last record

    Hello
    I was just trying to format an o/p to a table, and looking at the result, I thought it would be nice to add a piece of a chain to the last record. For example
    with dat as (
    select 'First Record' as COL from DUAL
    union all
    select 'Second Record'  from DUAL
    union all
    select 'Third Record'  from DUAL
    union all
    select 'Nth Record'  from DUAL )
    select * from dat
    
    o/p                                             Desired o/p
    COL                                            COL            
    -------------                                 -------------
    first RECORD                             first RECORD
    second RECORD                            second RECORD  
    THIRD RECORD                            THIRD RECORD 
    NTH RECORD                             This is the last record NTH RECORD   
    with dat as
    (
    select 'First Record' as COL from DUAL
    union all
    select 'Second Record'  from DUAL
    union all
    select 'Third Record'  from DUAL
    union all
    select 'Nth Record'  from DUAL
    ),
    ord as
    (
      select count(*) rn
        from dat
    )
    select decode(rownum, rn, 'This is Last Record ' || col, col)
      from ord, dat;
    
  • Ask the deptno 20 last record at the end show

    Oracle 9i Database

    I want to create a query that shows records, Deptno 20 last record at the end.
    application of shot show all records that are in the emp table.
     SQL> select empno,ename,job,deptno, row_number() over (order by deptno) rno from emp;
    
         EMPNO ENAME      JOB           DEPTNO        RNO
    ---------- ---------- --------- ---------- ----------
          7782 CLARK      MANAGER           10          1
          7839 KING       PRESIDENT         10          2
          7934 MILLER     CLERK             10          3
          7369 SMITH      CLERK             20          4
          7876 ADAMS      CLERK             20          5
          7902 FORD       ANALYST           20          6
          7788 SCOTT      ANALYST           20          7
          7566 JONES      MANAGER           20          8
          7499 ALLEN      SALESMAN          30          9
          7698 BLAKE      MANAGER           30         10
          7654 MARTIN     SALESMAN          30         11
    
         EMPNO ENAME      JOB           DEPTNO        RNO
    ---------- ---------- --------- ---------- ----------
          7900 JAMES      CLERK             30         12
          7844 TURNER     SALESMAN          30         13
          7521 WARD       SALESMAN          30         14
    
    14 rows selected.
    
    SQL> 
    I want the result
    EMPNO ENAME      JOB           DEPTNO        RNO
    ---------- ---------- --------- ---------- ----------
    7566 JONES      MANAGER           20          8
    7499 ALLEN      SALESMAN          30          9
    7698 BLAKE      MANAGER           30         10
    7654 MARTIN     SALESMAN          30         11
    7900 JAMES      CLERK             30         12
    7844 TURNER     SALESMAN          30         13
    7521 WARD       SALESMAN          30         14
    Concerning
    with t as
     ( select    7782  e1,'CKING '  e2  ,  ' PRESIDENT '  e3     ,   10  e4    from dual union all
       select    7934, 'MILLER'  ,  'CLERK  '        ,    10       from dual union all
       select    7369, 'SMITH '  ,  'CLERK  '        ,    20       from dual union all
       select    7876, 'ADAMS'   , 'CLERK '        ,     20       from dual union all
       select    7902, 'FORD '   ,  'ANALYST '       ,  20       from dual union all
       select    7788, 'SCOTT'   , 'ANALYST '       ,  20       from dual union all
       select    7788 ,' SCOTT '  ,'ANALYST '  ,       20       from dual union all
       select    7566, 'JONES ',    'MANAGER '   ,     20       from dual union all
       select    7499, 'ALLEN ' ,    'SALESMAN'   ,    30       from dual union all
       select    7698, 'BLAKE ' ,    'MANAGER '    ,   30       from dual union all
       select    7654, 'MARTIN' ,  'SALESMAN '  ,    30       from dual union all
       select    7900, 'JAMES ' ,   'CLERK '      ,       30       from dual union all
       select    7844, 'TURNER' ,  'SALESMAN ' ,     30       from dual union all
       select    7521 ,'WARD ' ,    'SALESMAN ' ,     30       from dual
    )
    SELECT o.*
      FROM (SELECT p.*,
                   MAX (CASE
                           WHEN p.e4 = 20
                              THEN p.rno
                        END) OVER (ORDER BY p.e4) AS mx
              FROM (SELECT a.*, ROW_NUMBER () OVER (ORDER BY e4) rno
                      FROM t a) p) o
     WHERE o.rno >= o.mx
    
  • How to find the last record of the extracted records

    Dear members,

    I have an OFA Page in which I view record master detail. For each master record can one or more detail records.

    In the page I got the button NEXT. If the user clicks the next button, I'm populating the next record of the master and its corresponding detail records.

    To achieve this, I wrote the code below in AM:_


    Public Sub findNextRec()
    *{*
    String headerID = null;
    Rank rank is getMaster_VO1 () .next ();.
    if(Row!=null)
    *{*

    headerID = row.getAttribute ("HeaderId") m:System.NET.SocketAddress.ToString ();
    getDetail_VO1 (.setMaxFetchSize(-1));
    getDetail_VO1 () .setWhereClause (null);
    getDetail_VO1 () .addWhereClause ("header_id in (: 1)" ");
    getDetail_VO1 () .setWhereClauseParams (null);
    getDetail_VO1 (.setWhereClauseParam(0,headerID));
    getDetail_VO1 () .executeQuery ();

    *}*
    *}*

    My CO code in processFormRequest method is as follows:_


    If (PageContext.GetParameter ("Next")! = null)
    *{*
    am.invokeMethod ("findNextRec");
    *}*

    Here my requirement is that if it's a last drive, I want to show the user a message saying it's last recording. To achieve this please let me know what the code should be written.

    Thanks in advance.

    Best regards
    Arun D. Reddy

    Arun,

    If my interpretation is correct, then you can achieve the same thing by making some minor changes to your existing code.

    public void findNextRec()
    {
    String headerID=null;
    Row row = getMaster_VO1().next();
    if(row!=null) //your code will return null when if there is no record
    {
    headerID=row.getAttribute("HeaderId").toString();
    getDetail_VO1().setMaxFetchSize(-1);
    getDetail_VO1().setWhereClause(null);
    getDetail_VO1().addWhereClause("header_id in (:1)");
    getDetail_VO1().setWhereClauseParams(null);
    getDetail_VO1().setWhereClauseParam(0,headerID);
    getDetail_VO1().executeQuery();
    }
    else{
    //write down the message that there exist no more rows (custom message)
    
         }
    }
    

    Kind regards
    GYAN

  • How to find inserted last record in the table.

    Version: Oracle 10g

    I have a table called 'Manufacturing' and 3 columns as mfno, itemname, quantity.
    How to find inserted last record in the table 'manufacturing '.

    As I got to know that the Rowid is not a result perfect result. Please provide your inputs.

    user13416294 wrote:
    Version: Oracle 10g

    This is not a version. It's a product name. A version is 10.1.0.2 or 10.2.0.4, etc.

    I have a table called 'Manufacturing' and 3 columns as mfno, itemname, quantity.
    How to find inserted last record in the table 'manufacturing '.

    Not possible as your data model do not answer for him. As simple as that.

    If there is a need to determine an order or associate some time to an entity, then that should be part of the data model - and a relationship, or one or several attributes are necessary to represent this information. Your data model in this case is therefore unable to meet your requirements.

    If the requirements are valid, set the data model. In other words - your question has nothing to do with Oracle and nothing to do with the other pseudo columns in Oracle, the rowscn or the rowid. It is a question of pure data modeling. Nothing more.

  • How to get the first and last record

    Hai All

    I have a table called T1 and there are more than 8 lakhs Archives and I have a column named Timestamp, so I need to get the first record value and time stampvalue and last record and time stamp value so that I can conclude that for example
    form June 13 to 15 June data are here


    Kind regards

    SrikkanthM

    What is the problem with:

    select min(timestamp),max(timestamp)
    from T1;
    

    ?

  • second last record

    Hello
    my request is to go looking for records. I want to know the second last record.
    for example. Select * from emp by empno.
    I want to know second last empname.

    can someone help me?

    thnx in advance.

    Hello

    It is a special case of a Query of paging , which itself is a variation of a Query of Top - N .
    Do a search on these terms to other techniques and discussion.

    Here's one way:

    WITH     got_rnum     AS
    (
         SELECT     ename     -- or whatever columns you want
         ,     RANK () OVER (ORDER BY empno DESC)     AS rnum
         FROM     emp
    )
    SELECT     *     -- or list all columns except rnum
    FROM     got_rnum
    WHERE     rnum     = 2
    ;
    

    For your specific problem, another way may be a bit simpler, but only a little.
    I suggest you to master this technique first, because it can very easily be extended to cover the problems associated with, such as "who has the 2nd empno higher in each Department?

  • Insert correctly last record to the child table in the multi user environment.

    Hello
    I have the following situation.

    Two Tables
    Table1 has a primary key named ID column
    Tabel2 contains a column named table1_id, this is a foreign key to table1.

    I have a tabular report that contains an add record button and a button submit to table1. (this table has other columns that require attribution)

    I want to insert a record into table2 automatically whenever the user presses submit.

    I have a query like this to get the last record in table1:
    SELECT MAX(id) 
      FROM table1
    and I would use it in a submit after procedure like this:
    DECLARE v_id NUMBER;
    
    BEGIN
    
        SELECT MAX(id)
          INTO v_id
          FROM table1
    
        INSERT
          INTO table2(table1_id)
        VALUES (v_id);
    
    END;
    The thing that worries me, is that the application that I use is a multi user environment. I'm afraid that if two or more people use as MAX recording is not the right one.
    It's a legitimate concern?
    If so, is there a best way to do this kind of thing.

    Ben:

    The triggers are usually avoidable IMO. But, there is always a but, you already use triggers elsewhere in your application, and probably your form the apex uses the routines of APEX MRU for DML and thus leaves the trigger as the only viable option to achieve what you're trying to do.

    CITY

  • calculation of ratios and rounding - how the sum of last record to give 1

    I'm putting in a single query to calculate the reports for an unknown number of records. I want to turn the ratios to 5 decimal places and I want the total reports of equal to 1.

    for example

    If I have 3 folders with Qty total overal 4,5,6 is 15
    I note 3 lines
    Round (4/15.5),
    Round (5/15.5),
    Round (6/15.5)

    but I want to ensure total = 1
    so I will try to do something like

    Round (4/15.5),
    Round (5/15.5),
    1 - round(4/15,5) - round(5/15,5)

    can someone help show me the sql construction? I've been trying and failing using where clause

    of course this example would add to 1 but other unknown ratios may not match up to 1.

    Published by: user12154024 on November 2, 2009 22:32

    Hello 12154024,

    Welcome to the forum. May not be a more elegant solution, but it shows how it works step by step

    WITH t AS (
    SELECT 4 n FROM dual
    UNION ALL
    SELECT  5 n FROM dual
    UNION ALL
    SELECT 6 n FROM dual
    )
    ,t1 AS (
    SELECT  n
           ,ROUND(RATIO_TO_REPORT(n) OVER (),5) AS rr
           ,COUNT(n) OVER () AS c
           ,ROW_NUMBER() OVER (ORDER BY n) AS rn
    FROM    t
    )
    ,t2 AS (
    SELECT  n
           ,rr
           ,SUM(rr) OVER (ORDER BY n) s
           ,c
           ,rn
    FROM t1
    )
    SELECT  n
           ,rr
           ,CASE WHEN c = rn THEN
                rr + (1 - s)
            ELSE
                rr
            END rr2
           ,s
    FROM    t2
    ORDER BY rn;
    
    N   RR        RR2       S
    --- --------- --------- --------
    4   0.26667   0.26667   0.26667
    5   0.33333   0.33333   0.6
    6   0.4       0.4       1        
    
    3 rows selected
    

    The part "WITH t AS" generates data
    T1 calculate the ratio, counts the number of records and signs a current issue
    T2 to calculate a cumulative ratio
    the last part takes these data and for the last record (number = count running) it allows to adjust the ratio.

    You can see if you are using other data

    WITH t AS (
    SELECT 4.78 n FROM dual
    UNION ALL
    SELECT  5 n FROM dual
    UNION ALL
    SELECT 6 n FROM dual
    )
    ...
    
    N    RR       RR2      S
    ---- -------- -------- --------
    4.78 0.30292  0.30292  0.30292
    5    0.31686  0.31686  0.61978
    6    0.38023  0.38022  1.00001  
    
    3 rows selected
    

    Concerning
    Marcus

  • remove the last record from the plsql table

    TYPE r_LOOPElement IS RECORD (TermID   NUMBER 
                                          );
    
    TYPE t_LOOPType IS TABLE OF r_LOOPElement INDEX BY BINARY_INTEGER;
    i_CustomerLoop      t_LOOPType ;
    
    i_CustomerLoop(1).TermID=1;
    i_CustomerLoop(2).TermID=2;
    i_CustomerLoop(3).TermID=3;
    Under certain conditions, I need to remove the last record from i_CustomerLoop

    whichi s the best way to do it. because I sometimes get duplicates for TermID in this plsql table.

    Hello

    See [removing items from Collection (DELETE method) | http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/collections.htm#CJAFGFIG]

    Kind regards

  • get the last record

    What is the best way to get the last record in a table?
    ... in addition to select * from tbl by id Desc... & then set = 1 maxrow in cfoutput.

    I want a quick way.
    I tried "Max (id), columns, but not worked.
    If I ' Max (id) as V ' & then turn around and make another request for ' where id = #V # "to get the rest of the record, there's more action.

    Quote:
    Posted by: paross1
    One way...

    SELECT all your columns
    From your_table
    WHERE your_engagement_appid = (SELECT MAX (your_id)
    From your_table)

    Phil

    Thank you guys. It worked great.
    I also tried the front joined query where the... I would have thought that.
    Thank you!

Maybe you are looking for