Static cursors (PL/SQL)
A static cursor is a cursor whose associated query is fixed at compile time. Declaring a cursor is a prerequisite to using it. Declarations of static cursors using PL/SQL syntax within PL/SQL contexts are supported by the Db2® data server.
Syntax
Description
- cursor-name
- Specifies an identifier for the cursor that can be used to reference the cursor and its result set.
- query
- Specifies a SELECT statement that determines a result set for the cursor.
Example
The following example shows a procedure
that contains multiple static 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
OPEN emp_cur_1;
...
END;