SQL FETCH Statement

PURPOSE:  This statement retrieves one row from a group of rows that were identified by the SQL SELECT statement.  After a SELECT statement executes, you can use the FETCH statement to sequentially retrieve one row at a time from the selected rows.

Syntax

SQL [FOR CURSOR cursor_name] FETCH NEXT ROW
    [HUSH]

FOR CURSOR cursor_name

Specifies which cursor if multiple cursors are being used.

FETCH NEXT ROW

No rows from the cursor are retrieved until the FETCH statement is issued.  The cursor is a temporary object associated with a previous SELECT operation using the same cursor name.  Cursors allow for the rows of a set operation to be picked off one by one.

The cursor is positioned just before the first row in the set if the FETCH statement has not been previously issued.  The cursor is advanced as successive rows are retrieved from the set.

All cursors in a PM object are closed when the PM is initialized or exited.

HUSH

shuts off warning, error, auxiliary, and SQL messages for the execution of that statement only.  The text of the error message can be found in the system function @ERROR_MESSAGE.

Example

SQL FOR CURSOR BOOK SELECT * FROM BOOKS_ORA WHERE
"BOOKS_ORA.TYPE_CODE='for_lang'"

START:10

SQL FOR CURSOR BOOK FETCH NEXT ROW

LEAVE:10 IF @SQLCODE # 0

TYPE TITLE_TEXT:BOOKS_ORA

REPEAT:10

NOTES:  The system field @SQLCODE contains the return status of the SQL FETCH statement.

SQL Delete Statement    SQL Insert Statement