Step 5a: Updating the current row

When your program has positioned the cursor on a row, you can update the row by using the UPDATE statement with the WHERE CURRENT OF clause. The WHERE CURRENT OF clause specifies a cursor that points to the row that you want to update.

The UPDATE ... WHERE CURRENT OF statement looks like this:

EXEC SQL
 UPDATE table-name
   SET column-1 = value [, column-2 = value] ...
   WHERE CURRENT OF cursor-name
END-EXEC.

When used with a cursor, the UPDATE statement:

  • Updates only one row—the current row
  • Identifies a cursor that points to the row to be updated
  • Requires that the columns updated be named previously in the FOR UPDATE OF clause of the DECLARE CURSOR statement, if an ORDER BY clause was also specified

After you update a row, the cursor's position remains on that row (that is, the current row of the cursor does not change) until you issue a FETCH statement for the next row.