Output last row in a cursor : Cursor Not Found « Cursor « Oracle PL / SQL






Output last row in a cursor

  
SQL> CREATE TABLE emp(
  2      emp_ID NUMBER (6),
  3      START_DATE  DATE,
  4      END_DATE    DATE,
  5      JOB_ID  VARCHAR2 (10),
  6      DEPARTMENT_ID   NUMBER (4)
  7  );

Table created.

SQL> CREATE OR REPLACE PROCEDURE promotion_review_1
  2  IS
  3     nempid   NUMBER;
  4     dstartdate    DATE;
  5     denddate      DATE;
  6     sjobid        VARCHAR2 (20);
  7     CURSOR empCursor IS SELECT emp_id, start_date, end_date, job_id FROM emp;
  8  BEGIN
  9     OPEN empCursor;
 10     LOOP
 11        FETCH empCursor INTO nempid, dstartdate, denddate, sjobid;
 12        EXIT WHEN empCursor%NOTFOUND;
 13        DBMS_OUTPUT.put_line ('emp '||nempid||' had job '||sjobid||' for '||(denddate - dstartdate)||' days.');
 14     END LOOP;
 15     CLOSE empCursor;
 16  END;
 17  /

Procedure created.

SQL> show errors
No errors.
SQL> drop table emp;

Table dropped.

   
    
  








Related examples in the same category

1.If cursor not found, reset the value
2.Explicit Cursor and notfound
3.SQL%NOTFOUND and if statement
4.Exit When Cursor%NOTFOUND
5.Incorrect location of the EXIT WHEN statement.
6.Behavior of the NO_DATA_FOUND exception.
7.Use 'EXIT WHEN studentCursor%NOTFOUND' just after fetch statement
8.NO_DATA_FOUND vs. %NOTFOUND
9.Loop till exit when cursorName%notfound
10.fetch cursor till notfound