SQL/MX 2.x Reference Manual (H06.04+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-39
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 on the next row of
the result table defined by the cursor specification and retrieves values from that row,
leaving the cursor 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.
cursor-name
is an SQL identifier—the name of the cursor being used to fetch a row of values.
The cursor must be open. See Identifiers on page 6-52.
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]
C/COBOL
C/COBOL
C/COBOL