A cursor is a database object that helps in accessing and manipulating data in given result set.
The main advantage is that we can process the data row-by -row.
There are four types' cursors.
1. Static: It always displays the result set as it was when the cursor opened. Static cursors are always read-only.
2. Dynamic: Dynamic cursors are opposite of static cursors. It refers all changes made to the rows in their result set when scrolling through the cursor.
3. Forward- Only: The forward only cursor does not support; it supports only fetching the rows serially from the start to end of the cursors.
4. Keyset-driven: The keyset is the set of key values from all the rows that qualified for the select statement at the time the cursor was opened.
*Declare a Cursor
Exec SQL DECLARE c1 CURSOR FOR Select name, dept from table1 where job='Mgr' END-EXEC.;
*Open the Cursor
EXEC SQL OPEN c1 END-EXEC;
*Fetch rows from the 'table1' table
Perform Fetch-Loop thru End-Fetch-Loop until SQLCODE not equal 0;
*Close the Cursor
EXEC SQL CLOSE c1 END-EXEC.
MOVE "CLOSE CURSOR" to errloc.