7.5.18 FETCH

Table of Contents Previous Next



7.5.18 FETCH
Use the FETCH statement to return rows from a cursor into an SQLDA descriptor or a target list of host variables. Before using a FETCH statement to retrieve information from a cursor, you must prepare the cursor using DECLARE and OPEN statements. The statement syntax is:
EXEC SQL [FOR array_size] FETCH cursor
{ USING
DESCRIPTOR SQLDA_descriptor }|{ INTO target_list };
array_size is an integer value or a host variable that contains an integer value specifying the number of rows to fetch. If you omit the FOR clause, the statement is executed once for each member of the array.
cursor is the name of the cursor from which rows are being fetched, or a host variable that contains the name of the cursor.
If you include a USING clause, the FETCH statement will populate the specified SQLDA descriptor with the values returned by the server.
If you include an INTO clause, the FETCH statement will populate the host variables (and optional indicator variables) specified in the target_list.
The following code fragment declares a cursor named employees that retrieves the employee number, name and salary from the emp table:


Table of Contents Previous Next