Examples of Cursors in ANSI-Compliant Databases
In an ANSI-compliant database, a cursor associated with a SELECT statement is an update cursor by default.
The following example declares an update cursor in an
ANSI-compliant database:
EXEC SQL declare x_curs cursor for select * from customer_ansi;
To make it clear in the program documentation that this
cursor is an update cursor, you can specify the FOR UPDATE option
as in this example:
EXEC SQL declare x_curs cursor for
select * from customer_ansi for update;
If you want an update cursor to be able to modify only
some of the columns in a table, you must specify these columns in
the FOR UPDATE option. The following example declares an update cursor
and specifies that this cursor can update only the fname and lname columns
in the customer_ansi table:
EXEC SQL declare y_curs cursor for
select * from customer_ansi for update of fname, lname;
If you want a cursor to be a read-only cursor, you must
override the default behavior of the DECLARE statement by specifying
the FOR READ ONLY option in your DECLARE statement. The following
example declares a read-only cursor:
EXEC SQL declare z_curs cursor for
select * from customer_ansi for read only;