DB2 10.5 for Linux, UNIX, and Windows

Describing a SELECT statement in a dynamically executed SQL program

After you allocate sufficient space for the second SQLDA (in this example, called fulsqlda), you must code the application to describe the SELECT statement.

Procedure

Code your application to perform the following steps:

  1. Store the value 20 in the SQLN field of fulsqlda (the assumption in this example is that the result table contains 20 columns, and none of these columns are LOB columns).
  2. Obtain information about the SELECT statement using the second SQLDA structure, fulsqlda. Two methods are available:
    • Use another PREPARE statement, specifying fulsqlda instead of minsqlda.
    • Use the DESCRIBE statement specifying fulsqlda.

What to do next

Using the DESCRIBE statement is preferred because the costs of preparing the statement a second time are avoided. The DESCRIBE statement reuses information previously obtained during the prepare operation to fill in the new SQLDA structure. The following statement can be issued:

     EXEC SQL DESCRIBE STMT INTO :fulsqlda

After this statement is executed, each SQLVAR element contains a description of one column of the result table.