Fetch cursor till notfound : Fetch « Cursor « Oracle PL/SQL Tutorial






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.








25.4.Fetch
25.4.1.Fetch data into PL/SQL table
25.4.2.Fetch cursor value into column type variable
25.4.3.Fetch cursor till cursorName%NOTFOUND
25.4.4.Using a simple UPDATE statement without locking for rows fetched from Cursors
25.4.5.To lock all the records while you're working on them. This is done using a SELECT FOR UPDATE command
25.4.6.Fetching Across Commits
25.4.7.Fetching Across Commits, Example 2
25.4.8.Populating a Record with FETCH INTO
25.4.9.cursor bulk
25.4.10.Compare the performance differences between row-at-a-time processing and bulk processing
25.4.11.Raise no data found exception if cursor is empty
25.4.12.Fetch cursor to three variables
25.4.13.Nested cursor open
25.4.14.Fetch cursor till notfound
25.4.15.Fetch cursor to table collection of row type
25.4.16.Fetch cursor value to three variables
25.4.17.Fetch row by row