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