Suppose your program examines data about people in department D11. The following examples show the SQL statements you would include in a program to define and use a serial and a scrollable cursor.
These cursors can be used to obtain information about the department from the CORPDATA.EMPLOYEE table.
For the serial cursor example, the program processes all of the rows from the table, updating the job for all members of department D11 and deleting the records of employees from the other departments.
Serial cursor SQL statement | Described in section |
---|---|
EXEC SQL |
Step 1: Define the cursor. |
EXEC SQL |
Step 2: Open the cursor. |
EXEC SQL |
Step 3: Specify what to do when end-of-data is reached. |
EXEC SQL |
Step 4: Retrieve a row using a cursor. |
... for all employees |
Step 5a: Update the current row. |
... for other employees, |
Step 5b: Delete the current row. |
Branch back to fetch and process the next row. | |
CLOSE-THISEMP. |
Step 6: Close the cursor. |
For the scrollable cursor example, the program uses the RELATIVE position option to obtain a representative sample of salaries from department D11.
Scrollable cursor SQL statement | Described in section |
---|---|
EXEC SQL |
Step 1: Define the cursor. |
EXEC SQL |
Step 2: Open the cursor. |
EXEC SQL |
Step 3: Specify what to do when end-of-data is reached. |
...initialize program summation |
Step 4: Retrieve a row using a cursor. |
...calculate the average |
|
CLOSE-THISEMP. |
Step 6: Close the cursor. |