Updating previously retrieved data
To scroll backward through data and update it, use a scrollable cursor that is declared with the FOR UPDATE clause.
About this task
Question: How can you scroll backward and update data that was retrieved previously?
Answer: Use a scrollable cursor that is declared with the FOR UPDATE clause.
Procedure
To update previously retrieved data:
- Declare the cursor with the SENSITIVE STATIC SCROLL keywords.
- Open the cursor.
- Execute a FETCH statement to position the cursor at the end of the result table.
- FETCH statements that move the cursor backward, until you reach the row that you want to update.
- Execute the UPDATE WHERE CURRENT OF statement to update the current row.
- Repeat steps 4 and 5 until you have update all the rows that you need to.
- When you have retrieved and updated all the data, close the cursor.