In the dynamic SQL statements described up to this point, the number and data types of the placeholders and derived columns for a dynamically compilable SQL statement or a dynamic cursor description were known at the time the ESQL program was compiled. So-called descriptor areas are available in SQL to allow you to use any number and type of input parameters and to process any results from queries in ESQL programs.
A descriptor area is an area in memory in which values and information on the number and data types of inputs (placeholders) and outputs (derived columns) in dynamically compiled SQL statements or cursor descriptions are stored.
Every descriptor area comprises a number of items. One item is created for every simple column or value or, in the case of multiple columns or aggregates, for every column element or every occurrence. Every item is subdivided into fields. The values in these fields can be set with DESCRIBE or SET DESCRIPTOR or read with GET DESCRIPTOR. Depending on the type of the item, only certain fields are assigned values. Every descriptor area has a field with the name COUNT, which contains the number of entries in the descriptor area.
The descriptor area contains the following fields for a given item:
Keyword | Meaning | Can be set |
COUNT | Number of items in the descriptor area | yes |
TYPE | Data type of item: | yes |
LENGTH | Length or maximum length in characters in the case of | yes |
OCTET_LENGTH | Maximum memory requirement in bytes in the case of | No, |
PRECISION | Only for numeric data types and TIME and | yes |
SCALE | Only for integers and fixed-point numbers: | yes |
DATETIME_ | Only for time and date data types (TYPE =9): | yes |
REPETITIONS | For multiple columns and aggregates: contains the | yes |
NULLABLE |
| no |
INDICATOR |
| yes |
DATA | Value of an item. The data type is defined in by the | yes |
NAME | Column name | no |
UNNAMED |
| no |
Tabelle 37: Fields of a descriptor area
The COUNT field occurs once in every descriptor area. The data type of NAME is CHAR( n) or VARCHAR(n) with n >= 128 and the data type of DATA is determined by the entries in TYPE, LENGTH, PRECISION and SCAL. The remaining fields have the data type SMALLINT.
Users do not need to concern themselves with the internal structure of the SQL descriptor area, but can address the fields of the descriptor area using SQL statements. Depending on the statement concerned, only certain fields in the descriptor area are addressed.
There are a number of SQL statements and variants of the EXECUTE, OPEN and FETCH statements available for working with an SQL descriptor area:
Creating a descriptor area
A descriptor area must first be created with ALLOCATE DESCRIPTOR. This statement specifies the maximum number of items in the descriptor area. The items in the descriptor area are undefined after the ALLOCATE DESCRIPTOR statement has been executed.Describe the number and data types of the placeholders
DESCRIBE INPUT allows you to describe the number and data types in a dynamically compiled SQL statement or cursor description and to store these in a descriptor area.Pass values for placeholders
The values for the placeholders in a dynamically compiled statement are taken from a descriptor area in the EXECUTE... USING SQL DESCRIPTOR statement. The values for the placeholders in a dynamically compiled cursor description are taken from a descriptor area in the OPEN... USING SQL DESCRIPTOR statement. In both cases, the required values must first be set using SET DESCRIPTOR.Describe the number and data types of the derived columns
DESCRIBE OUTPUT allows you to describe the number and data types of the derived columns in a dynamically compiled SELECT statement or cursor description and to store these in a descriptor area.Store column values from a derived row
The column values from a derived row in a dynamically compiled SELECT statement are stored in a descriptor area with EXECUTE... INTO SQL DESCRIPTOR. The column values of a row of the derived table in a dynamic cursor are stored in a descriptor area with FETCH... INTO SQL DESCRIPTOR.Modifying the descriptor area
The number of items or the contents of an item of the descriptor area can be modified with SET DESCRIPTOR.Querying the descriptor area
The number of items or the contents of fields in an item of a descriptor area can be queried with GET DESCRIPTOR.Releasing the descriptor area
The memory occupied by a descriptor area can be released with DEALLOCATE DESCRIPTOR.