An update cursor
An update cursor permits you to delete or
update the current row; that is, the most recently fetched row. The
following example in
Informix® ESQL/C shows
the declaration of an update cursor:
EXEC SQL
DECLARE names CURSOR FOR
SELECT fname, lname, company
FROM customer
FOR UPDATE;
The program that uses this cursor can fetch rows in the
usual way.
EXEC SQL
FETCH names INTO :FNAME, :LNAME, :COMPANY;
If the program then decides that the row needs to be changed,
it can do so.
if (strcmp(COMPANY, "SONY") ==0)
{
EXEC SQL
UPDATE customer
SET fname = 'Midori', lname = 'Tokugawa'
WHERE CURRENT OF names;
}
The words CURRENT OF names
take the place
of the usual test expressions in the WHERE clause. In other respects,
the UPDATE statement is the same as usual, even including the specification
of the table name, which is implicit in the cursor name but still
required.