For each row in a cursor : CURSOR FOR Loop « Cursor « Oracle PL / SQL






For each 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>
SQL>
SQL>
SQL> CREATE OR REPLACE PROCEDURE promotion_review_2
  2  IS
  3     CURSOR empCursor IS SELECT emp_id, start_date, end_date, job_id FROM emp;
  4  BEGIN
  5     FOR jh_rec IN empCursor
  6     LOOP
  7        DBMS_OUTPUT.put_line(jh_rec.emp_id||' had job '||jh_rec.job_id||' for '|| (jh_rec.end_date - jh_rec.start_date)||' days.');
  8  END LOOP;
  9  END;
 10  /

Procedure created.

SQL> drop table emp;

Table dropped.

   
    
  








Related examples in the same category

1.Create a cursor in for statement
2.The %FOUND, %NOTFOUND, and %ROWCOUNT cursor attributes can be used to guide a loop
3.A function that uses a CURSOR FOR Loop
4.Use 'for loop' to loop through the cursor
5.A subquery in the FROM clause of a cursor within a cursor FOR loop
6.Assign value from cursor to a table collection by index
7.Calculation based on cursor value
8.Output value in cursor one by one
9.Simple Loop and fetch cursor
10.Use pl/sql, cursor and for loop to count table