FETCH
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Moves the position of the cursor to the next row of the active set and fetches the column values of the current row into the specified host variables.
Syntax
|
Parameters
- cursor_name
-
A name identified in an earlier
DECLARE CURSORstatement and anOPEN CURSORstatement. -
USING SQL DESCRIPTORstructure_name -
Directs the SQL engine to
FETCHdata into storage addressed by an SQLDA structure. -
INTO:host_var_ref[[INDICATOR] :ind_var_ref] -
Directs the SQL engine to
FETCHdata into the identified host variables, and to set values in the identified indicator variables.
Notes
- A
FETCHoperation requires that the cursor be open. - The positioning of the cursor for each
FETCHoperation is as follows:- The first time you execute a
FETCHstatement after opening the cursor, the cursor is positioned to the first row of the active set. - Subsequent
FETCHoperations advance the cursor position in the active set. The next row becomes the current row. - When the current row is deleted using a positioned
DELETEstatement, the cursor is positioned before the row after the deleted row in the active set.
- The first time you execute a
- The cursor can only be moved forward in the active set by executing
FETCHstatements. To move the cursor to the beginning of the active set, you mustCLOSEthe cursor andOPENit again. - If the cursor is positioned on the last row of the active set
or if the active set does not contain any rows, executing a
FETCHwill return the status codeSQL_NOT_FOUNDin the SQLDA. - After a successful
FETCH, the total row count fetched so far for this cursor is returned insqlca.sqlerrd[2]. The count is set to zero after anOPENcursor operation. - You can
FETCHmultiple rows in oneFETCHoperation by using array variables in theINTOclause. TheSQL_NOT_FOUNDstatus code is returned in theSQLCAwhen the end of the active set is reached, even if the currentFETCHstatement returns one or more rows. - If you use array variables in a
FETCHstatement, the array sizes are set to the number of rows fetched after theFETCHstatement is executed.
Example
|