Cursors

Cursors are defined in the Procedure Division or in the Data Division. For example:

EXEC SQL DECLARE MYCURSOR CURSOR FOR
   SELECT FIRST_NAME, LAST_NAME
   FROM TEST_TABLE
END-EXEC.

AcuSQL also supports the declaration of scroll cursors, and the use of the following FETCH extensions:

Extension Use
FETCH FIRST Returns the first row of query results.
FETCH LAST Returns the last row of query results.
FETCH PRIOR Returns the row immediately preceding the current curser row.
FETCH NEXT Returns the row immediately following the current curser row.
FETCH ABSOLUTE Returns a specific row identified by a constant or host variable*.
FETCH RELATIVE Moves the cursor forward or backward a specified number of times from its current position.

* If specifying a row position through a host variable, the host variable does not need to be declared in the DECLARE section of working-storage, and can be any numeric working-storage variable.

See Cursors for a brief introduction to cursors. Refer to any of the commercially available books on SQL for more complete details.