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:

  1. Declare the cursor with the SENSITIVE STATIC SCROLL keywords.
  2. Open the cursor.
  3. Execute a FETCH statement to position the cursor at the end of the result table.
  4. FETCH statements that move the cursor backward, until you reach the row that you want to update.
  5. Execute the UPDATE WHERE CURRENT OF statement to update the current row.
  6. Repeat steps 4 and 5 until you have update all the rows that you need to.
  7. When you have retrieved and updated all the data, close the cursor.