You use DESCRIBE to write the data type descriptions of input/output values of a dynamic statement or cursor description to an SQL descriptor area.
The SQL descriptor area must be created beforehand with ALLOCATE DESCRIPTOR.
You must prepare the dynamic statement or cursor description with PREPARE before the DESCRIBE statement is executed.
DESCRIBE [INPUT | OUTPUT]
statement_id USING SQL DESCRIPTOR GLOBAL
descriptor
INPUT
Determines the number of input values of a dynamic statement or cursor description and describes the data type of the input values.
OUTPUT
Determines the number of output values of a dynamic SELECT statement or cursor description and describes the data type of the output values.
statement_id
Dynamic statement or cursor description.
descriptor
Name of the SQL descriptor area into which the type descriptions are to be written (see "Descriptor area field values").
You can specify the name as an alphanumeric literal or with an alphanumeric host variable.
You cannot use this SQL descriptor area if there is an open cursor with block mode activated (see section "PREFETCH pragma") and a FETCH NEXT... statement whose INTO clause contains the name of the same SQL descriptor area has been executed for this cursor.
Descriptor area field values
The fields of the SQL descriptor area are supplied with the following values:
The COUNT field contains the number of input values (DESCRIBE INPUT) or the number of output values (DESCRIBE OUTPUT).
In the case of DESCRIBE INPUT, the number is calculated from the number of placeholders in the dynamic statement or cursor description as follows:
Number of placeholders for unqualified values +
Number of aggregate elements of each placeholder for aggregates
For DESCRIBE OUTPUT, the number is calculated from the number of derived columns of the dynamic SELECT statement or cursor description as follows:
Number of unqualified derived columns +
Number of column elements of each multiple derived column
If the number calculated is 0, no other descriptor area fields are set.
If the number is greater than the maximum number of item descriptors specified for ALLOCATE DESCRIPTOR, no other descriptor area fields are set and an appropriate SQLSTATE is set.
Otherwise, the following fields in the SQL descriptor area are supplied with values:
For each input value for DESCRIBE INPUT:
TYPE
LENGTH (for alphanumeric data type, national data type and time data type)
PRECISION (for numeric data type and for TIME and TIMESTAMP)
SCALE (for NUMERIC, DECIMAL, INTEGER and SMALLINT)
DATETIME_INTERVAL_CODE (for time data type)
OCTET_LENGTH
NULLABLE with the value 1
REPETITIONS
UNNAMED with the value 1
For each output value for DESCRIBE OUTPUT:
TYPE
LENGTH (for alphanumeric data type, national data type and time data type)
PRECISION (for numeric data type and for TIME and TIMESTAMP)
SCALE (for NUMERIC, DECIMAL, INTEGER and SMALLINT)
DATETIME_INTERVAL_CODE (for time data type)
OCTET_LENGTH
NULLABLE
REPETITIONS
NAME
UNNAMED
The values assigned to the above-mentioned fields are described in section "Descriptor area fields".
All the other fields in the SQL descriptor area are undefined.
Example
DESCRIBE OUTPUT cur_description
USING SQL DESCRIPTOR GLOBAL 'DESCR_AREA'
See also
ALLOCATE DESCRIPTOR, DEALLOCATE DESCRIPTOR, GET DESCRIPTOR, SET DESCRIPTOR