Example 1: Setting session default attributes for holdable
cursors
SQL> ATTACH 'FILENAME mf_personnel';
SQL> --
SQL> -- Define the session default
SQL> --
SQL> SET HOLD CURSORS 'ON ROLLBACK';
SQL> --
SQL> -- Declare the cursor
SQL> --
SQL> DECLARE curs1 CURSOR FOR
cont> SELECT first_name, last_name FROM employees;
SQL> OPEN curs1;
SQL> FETCH curs1;
FIRST_NAME LAST_NAME
Terry Smith
SQL> FETCH curs1;
FIRST_NAME LAST_NAME
Rick O'Sullivan
SQL> DELETE FROM employees WHERE CURRENT OF curs1;
1 row deleted
SQL> ROLLBACK;
SQL> FETCH curs1;
FIRST_NAME LAST_NAME
Stan Lasch
SQL> COMMIT;
SQL> FETCH curs1;
%SQL-F-CURNOTOPE, Cursor CURS1 is not opened
Example 2: Overriding the session default attributes for holdable
cursors
SQL> -- Set the session default
SQL> --
SQL> SET HOLD CURSORS 'ALL';
SQL> --
SQL> -- Declare the cursor without a WITH HOLD clause
SQL> --
SQL> DECLARE curs2 CURSOR FOR
cont> SELECT first_name, last_name FROM employees;
SQL> OPEN curs2;
SQL> FETCH curs2;
FIRST_NAME LAST_NAME
Terry Smith
SQL> FETCH curs2;
FIRST_NAME LAST_NAME
Rick O'Sullivan
SQL> ROLLBACK;
SQL> FETCH curs2;
FIRST_NAME LAST_NAME
Stan Lasch
SQL> COMMIT;
SQL> FETCH curs2;
FIRST_NAME LAST_NAME
Susan Gray
SQL> CLOSE curs2;
SQL> FETCH curs2;
%SQL-F-CURNOTOPE, Cursor CURS2 is not opened
SQL> --
SQL> -- Declare the cursor overriding the session default by
SQL> -- specifying the WITH HOLD clause
SQL> --
SQL> DECLARE curs3 CURSOR
cont> WITH HOLD PRESERVE ON COMMIT
cont> FOR SELECT first_name, last_name FROM employees;
SQL> OPEN curs3;
SQL> FETCH curs3;
FIRST_NAME LAST_NAME
Terry Smith
SQL> FETCH curs3;
FIRST_NAME LAST_NAME
Rick O'Sullivan
SQL> COMMIT;
SQL> FETCH curs3;
FIRST_NAME LAST_NAME
Stan Lasch
SQL> ROLLBACK;
SQL> FETCH curs3;
%SQL-F-CURNOTOPE, Cursor CURS3 is not opened