When you write code in which the results set returned by a SELECT statement includes more than one row of data, you must declare and use a cursor. A cursor indicates the current position in a results set, in the same way that the cursor on a screen indicates the current position.
A cursor enables you to:
The example below demonstrates the following sequence of events:
EXEC SQL DECLARE Cursor1 CURSOR FOR SELECT au_fname, au_lname FROM authors END-EXEC . . . EXEC SQL OPEN Cursor1 END-EXEC . . . perform until sqlcode not = zero EXEC SQL FETCH Cursor1 INTO :first_name,:last_name END-EXEC display first_name, last_name end-perform . . . EXEC SQL CLOSE Cursor1 END-EXEC