Step 5b: Delete the current row

When your program has retrieved the current row, you can delete the row by using the DELETE statement. To do this, you issue a DELETE statement designed for use with a cursor; the WHERE CURRENT OF clause specifies a cursor that points to the row you want to delete.

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

EXEC SQL
 DELETE FROM table-name
   WHERE CURRENT OF cursor-name
END-EXEC.

When used with a cursor, the DELETE statement:

After you delete a row, you cannot update or delete another row using that cursor until you issue a FETCH statement to position the cursor.

You can use the DELETE statement to delete all rows that meet a specific search condition. You can also use the FETCH and DELETE. WHERE CURRENT OF statements when you want to obtain a copy of the row, examine it, then delete it.