DB2 Version 9.7 for Linux, UNIX, and Windows

DESCRIBE INPUT statement

The DESCRIBE INPUT statement obtains information about the input parameter markers of a prepared statement.

Invocation

This statement can only be embedded in an application program. It is an executable statement that cannot be dynamically prepared.

Authorization

None required.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-DESCRIBE INPUT--statement-name--INTO--descriptor-name-------><

Description

statement-name
Identifies the prepared statement. When the DESCRIBE INPUT statement is executed, the name must identify a statement that has been prepared by the application process at the current server.

For a CALL statement, the information returned describes the input parameters, defined as IN or INOUT, of the procedure. Input parameter markers are always considered nullable, regardless of usage.

INTO descriptor-name
Identifies an SQL descriptor area (SQLDA). Before the DESCRIBE INPUT statement is executed, the following variable in the SQLDA must be set:
SQLN
Specifies the number of SQLVAR occurrences provided in the SQLDA. SQLN must be set to a value greater than or equal to zero before the DESCRIBE INPUT statement is executed.
When the DESCRIBE INPUT statement is executed, the database manager assigns values to the variables of the SQLDA as follows:
SQLDAID
The first 6 bytes are set to 'SQLDA ' (that is, 5 letters followed by the space character).
The seventh byte, defined as SQLDOUBLED, is set based on the parameter markers described:
  • If the SQLDA contains two SQLVAR entries for every input parameter, the seventh byte is set to '2'. This technique is used to accommodate LOB or structured type input parameters.
  • Otherwise, the seventh byte is set to the space character.

The seventh byte is set to the space character if there is not enough room in the SQLDA to contain the description of all input parameter markers.

The eighth byte is set to the space character.

SQLDABC
Length of the SQLDA in bytes.
SQLD
The number of IN and INOUT parameters of the procedure.
SQLVAR
If the value of SQLD is 0, or greater than the value of SQLN, no values are assigned to occurrences of SQLVAR.

If the value of SQLD is n, where n is greater than 0 but less than or equal to the value of SQLN, values are assigned to the first n occurrences of SQLVAR. The values describe parameter markers for the input parameters of the procedure. The first occurrence of SQLVAR describes the first input parameter marker, the second occurrence of SQLVAR describes the second input parameter marker, and so on.

Base SQLVAR
SQLTYPE
A code showing the data type of the parameter and whether or not it can contain null values.
SQLLEN
A length value depending on the data type of the parameter. SQLLEN is 0 for LOB data types.
SQLNAME
The sqlname is derived as follows:
  • If the SQLVAR corresponds to a parameter marker that is in the parameter list of a procedure and is not part of an expression, sqlname contains the name of the parameter if one was specified on the CREATE PROCEDURE statement.
  • If the SQLVAR corresponds to a named parameter marker, sqlname contains the name of the parameter marker.
  • Otherwise, sqlname contains an ASCII numeric literal value that represents the SQLVAR's position within the SQLDA.

Secondary SQLVAR

These variables are only used if the number of SQLVAR entries are doubled to accommodate LOB, distinct type, structured type, or reference type parameters.
SQLLONGLEN
The length attribute of a BLOB, CLOB, or DBCLOB parameter.
SQLDATATYPE_NAME
For any user-defined type (distinct or structured) parameter, the database manager sets this to the fully qualified user-defined type name. For a reference type parameter, the database manager sets this to the fully qualified user-defined type name of the target type of the reference. Otherwise, schema name is SYSIBM and the type name is the name in the TYPENAME column of the SYSCAT.DATATYPES catalog view.

Notes

Example

Execute a DESCRIBE INPUT statement with an SQLDA that has enough SQLVAR occurrences to describe any number of input parameters a prepared statement might have. Assume that five parameter markers at most will need to be described and that the input data does not contain LOBs.
       /* STMT1_STR contains INSERT statement with VALUES clause */
   EXEC SQL PREPARE STMT1_NAME FROM :STMT1_STR;
   ... /* code to set SQLN to 5 and to allocate the SQLDA        */
   EXEC SQL DESCRIBE INPUT STMT1_NAME INTO :SQLDA;
   .
   .
   .
This example uses the first technique described under "Allocating the SQLDA" in "DESCRIBE OUTPUT".