8. OpenSQL Statements : FETCH : Syntax
 
Share this page                  
Syntax
The FETCH statement has the following formats:
Non-dynamic version:
EXEC SQL FETCH cursor_name
              INTO variable[:indicator_var] {, variable[:indicator_var]};
Dynamic version:
EXEC SQL FETCH cursor_name USING DESCRIPTOR descriptor_name;
cursor_name
Identifies an open cursor. Cursor_name can be either a string constant or a host language variable.
USING DESCRIPTOR descriptor_name
Identifies an SQLDA that contains type descriptions of one or more host language variables. Each element of the SQLDA is assigned the corresponding value in the current row of the cursor. For details, see the chapter “Working with Embedded SQL.”
The variables listed in the INTO clause or within the descriptor must be type-compatible with the values being retrieved. If a result expression is nullable, the host language variable that receives that value must have an associated null indicator.
If the statement does not fetch a row--a condition that occurs after all rows in the set have been processed--the sqlcode of the SQLCA is set to 100 (condition not found) and no values are assigned to the variables.
The statement must be terminated according to the rules of the host language.