SQL support / Result set processing |
A database result set is a group of rows produced by an SQL statement such as SELECT. The result set is maintained by the database server. In a program, you handle a result set with a database cursor.
Figure 1. Database result set
Figure 2. FETCH instruction
Figure 3. FREE instruction
The scope of reference of a database cursor is local to a module, so a cursor that was declared in one source file cannot be referenced in a statement in another file.
The language supports sequential cursors and scrollable cursors. Sequential cursors, which are unidirectional, are used to retrieve rows for a REPORT, for example. Scrollable cursors allow you to move backwards or to an absolute or relative position in the result set. Specify whether a cursor is scrollable with the SCROLL option of the DECLARE instruction.