This help section showed how to use a cursor to update a table in the database. The following code:
EXEC SQL DECLARE COBCUR1 CURSOR FOR SELECT C_FIRST_NAME, C_LAST_NAME FROM CUSTOMER WHERE C_LAST_NAME = 'Snead' FOR UPDATE END-EXEC. EXEC SQL OPEN COBCUR1 END-EXEC. perform until SQLCODE not equal 0 EXEC SQL FETCH COBCUR1 INTO :C-FIRST-NAME, :C-LAST-NAME END-EXEC IF sqlcode EQUAL 0 DISPLAY "Updating " C-FIRST-NAME , C-LAST-NAME EXEC SQL UPDATE CUSTOMER SET C_INFO = 'Revised' WHERE CURRENT OF COBCUR1 END-EXEC end-if end-perform. EXEC SQL CLOSE COBCUR1 END-EXEC.
instructs the program to perform these steps:
The figure in Updating Data – update.sqb showed the output of the update program. If you want, run the select3 program to see the contents of the updated fields.