Using Cursors to Delete Data
To delete a row from a table, use the delete cursor statement:
## delete cursor cursor_name
This statement deletes the current row. The cursor does not have to be declared for update to use a delete cursor. The cursor must have been positioned to the row using retrieve cursor. Once the row is deleted, a retrieve cursor must be issued to advance the cursor to the next row.
The following example illustrates the use of a cursor to update and delete rows:
## name character_string(15)
## salary float
## ingres personnel
## declare cursor c1 for
## retrieve (employee.empname, employee.#salary)
## for update of (#salary)
## open cursor c1
loop while more rows
## retrieve cursor c1 (name, salary)
print name, salary
/* Increase salaries of all employees earning less
** than 60,000. */
if salary < 60,000 then
print "updating", name
## replace cursor c1 (#salary = salary * 1.1)
/* Fire all employees earning more than 300,000. */
else if salary > 300,000 then
print "terminating ", name
## delete cursor c1
end if
end loop
## close cursor c1
## exit
Last modified date: 04/03/2024