Use the FETCH DESCRIPTOR
statement to retrieve rows from a cursor into an SQL descriptor. The syntax is:
EXEC SQL [FOR array_size] FETCH cursor
INTO [SQL] DESCRIPTOR descriptor_name;
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.
is the name of the cursor from which rows are fetched, or a host variable that contains the name of the cursor. The client must DECLARE
the cursor before calling the FETCH DESCRIPTOR
Include the INTO clause to specify an SQL descriptor into which the EXECUTE statement will write the results returned by the prepared statement. descriptor_name specifies the name of a descriptor (as a single-quoted string literal), or a host variable that contains the name of a descriptor. Prior to use, the descriptor must be allocated using an ALLOCATE DESCRIPTOR statement.
The following example allocates a descriptor named row_desc
that will hold the description and the values of a specific row in the result set. It then declares and opens a cursor for a prepared statement (my_cursor
), before looping through the rows in result set, using a FETCH
to retrieve the next row from the cursor into the descriptor: