Was this helpful?
When the Result Column Data Types Are Unknown
In most instances, when executing a dynamically defined SELECT statement, the program does not know the number or types of result columns. To provide this information to the program, first prepare and then describe the SELECT statement. The DESCRIBE statement returns to the program the type description of the result columns of a prepared SELECT statement. After the select is described, the program must dynamically allocate (or reference) the correct number of result storage areas of the correct size and type to receive the results of the select.
If the statement is not a SELECT statement, describe returns a zero to the sqld and no sqlvar elements are used.
After the statement has been prepared and described and the result variables allocated, the program has two choices regarding the execution of the SELECT statement:
The program can associate the statement name with a cursor name, open the cursor, fetch the results into the allocated result storage area (one row at a time), and close the cursor.
The program can use EXECUTE IMMEDIATE, which allows you to define a select loop to process the returned rows. If the select will return only one row, then it is not necessary to define the select loop.
Last modified date: 11/28/2023