Updating Through Cursors
Go Up to Declaring a Cursor
In many applications, data retrieval and update may be interdependent. DECLARE CURSOR
supports an optional FOR UPDATE
clause that optionally lists columns in retrieved rows that can be modified. For example, the following statement declares such a cursor:
EXEC SQL DECLARE H CURSOR FOR SELECT CUST_NO FROM CUSTOMER WHERE ON_HOLD = '*' FOR UPDATE OF ON_HOLD;
If a column list after FOR UPDATE
is omitted, all columns retrieved for each row may be updated. For example, the following query enables updating for two columns:
EXEC SQL DECLARE H CURSOR FOR SELECT CUST_NAME CUST_NO FROM CUSTOMER WHERE ON_HOLD = '*';
For more information about updating columns through a cursor, see Updating Multiple Rows.