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/14/2024