Example: Cursor Processing
The following is an example of cursor processing:
exec sql include sqlca;
exec sql begin declare section;
name character_string(15);
salary float;
exec sql end declare section;
exec sql whenever sqlerror stop;
exec sql connect personnel;
exec sql declare c1 cursor for
select ename, sal
from employee
for update of sal;
exec sql open c1;
exec sql whenever not found goto closec1;
loop while more rows
/* The WHENEVER NOT FOUND statement causes
the loop to be broken as soon as a row
is not fetched. */
exec sql fetch c1 into :name, :salary;
print name, salary;
if salary less than 10000 then
exec sql update employee
set salary = 10000
where current of c1;
end if;
end loop;
closec1:
exec sql close c1;
exec sql disconnect;
Last modified date: 08/28/2024