Declaring a cursor v17
Before you can use a cursor, you must first declare it in the declaration section of the SPL program. A cursor declaration appears as follows:
CURSOR <name> IS <query>;
Where:
name
is an identifier used to reference the cursor and its result set later in the program.query
is a SQLSELECT
command that determines the result set retrievable by the cursor.
Note
An extension of this syntax allows the use of parameters. For details, see Parameterized cursors.
This example shows some cursor declarations:
CREATE OR REPLACE PROCEDURE cursor_example IS CURSOR emp_cur_1 IS SELECT * FROM emp; CURSOR emp_cur_2 IS SELECT empno, ename FROM emp; CURSOR emp_cur_3 IS SELECT empno, ename FROM emp WHERE deptno = 10 ORDER BY empno; BEGIN ... END;