SQL/MX 2.x Reference Manual (G06.24+, H06.03+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual523725-004
3-40
FETCH Statement
FETCH Statement
Considerations for FETCH
C Examples of FETCH
COBOL Examples of FETCH
The FETCH statement is an SQL statement that positions a cursor or an SQLJ iterator
on the next row of the result table defined by the cursor specification or the iterator and
retrieves values from that row, leaving the cursor or iterator positioned at that row.
When you use the FETCH statement with rowset host variables or descriptors with
appropriate rowset fields set, it retrieves values from multiple, consecutive rows in the
result table. The number of rows from which values are retrieved is the given by the
declared length of the rowset and the number of rows in the result table, whichever is
smaller. After the values have been retrieved NonStop SQL/MX positions the cursor on
the last row that was read.
In dynamic SQL, the cursor name is provided at execution time, and the USING or
INTO clause can specify a target list of host variables or an SQL descriptor area for the
output values. In static SQL, the INTO clause provides a target list of host variables.
Otherwise, there is no difference in the static and dynamic forms of FETCH.
FETCH is one of several statements (including COMMIT, ROLLBACK, and SET
TRANSACTION) that do not generate a system-defined transaction.
Use FETCH only in embedded SQL programs.
FETCH {cursor-name | ext-cursor-name}
{USING | INTO} {argument-list | descriptor-spec}
ext-cursor-name is:
[GLOBAL | LOCAL] value-specification
argument-list is:
variable-spec [,variable-spec]...
descriptor-spec is:
SQL DESCRIPTOR descriptor-name
variable-spec is:
:variable-name [[INDICATOR] :indicator-name]
FETCH iterator-name
INTO argument-list
argument-list is:
variable-spec [,variable-spec]...
variable-spec is:
:variable-name
C/COBOL
C/COBOL
Java