FETCH statement [ESQL] [SP]
524
The server returns in SQLCOUNT the number of records fetched, and
always returns a SQLCOUNT greater than zero unless there is an error or
warning. A SQLCOUNT of zero with no error condition indicates that one
valid row has been fetched.
If the SQLSTATE_NOTFOUND warning is returned on the fetch, the
sqlerrd[2] field of the SQLCA (SQLCOUNT) contains the number of rows
by which the attempted fetch exceeded the allowable cursor positions. The
value is 0 if the row was not found but the position is valid; for example,
executing FETCH RELATIVE 1 when positioned on the last row of a cursor.
The value is positive if the attempted fetch was beyond the end of the cursor,
and negative if the attempted fetch was before the beginning of the cursor.
After successful execution of the fetch statement, the sqlerrd[1] field of the
SQLCA (SQLIOCOUNT) is incremented by the number of input/output
operations required to perform the fetch. This field is actually incremented
on every database statement.
Single row fetch One row from the result of the SELECT statement is put
into the variables in the variable list. The correspondence is one-to-one from
the select list to the host variable list.
Multi-row fetch One or more rows from the result of the SELECT
statement are put into either the variables in variable-list or the program data
areas described by sqlda-name. In either case, the correspondence is one-to-
one from the select-list to either the host-variable-list or the sqlda-name
descriptor array.
INTO The INTO clause is optional. If it is not specified, the FETCH
statement positions the cursor only. The host-variable-list is for Embedded
SQL use only.
cursor position An optional positional parameter allows the cursor to be
moved before a row is fetched. If the fetch includes a positioning parameter
and the position is outside the allowable cursor positions, the
SQLE_NOTFOUND warning is issued and the SQLCOUNT field indicates
the offset from a valid position.
The OPEN statement initially positions the cursor before the first row.
♦
NEXT Next is the default positioning, and causes the cursor to be
advanced one row before the row is fetched.
♦
PRIOR Causes the cursor to be backed up one row before fetching.
Parameters