ALLOCATE COLLECTION statement
Use the ALLOCATE COLLECTION statement to allocate memory for a variable of a collection data type (such as LIST, MULTISET, or SET) or for an untyped collection variable.
Syntax
Element | Description | Restrictions | Syntax |
---|---|---|---|
variable | Name of the typed or untyped collection variable to allocate | Must be an unallocated collection-type host variable | Language-specific rules for names |
Usage
This statement is an extension to the ANSI/ISO standard for SQL. Use this statement with ESQL/C.
The ALLOCATE COLLECTION statement allocates memory for an ESQL/C variable that can store the value of a collection data type.
To create a collection variable for programs:
- Declare the collection variable as a client collection variable
in the program.
The collection variable can be a typed or untyped collection variable.
- Allocate memory for the collection variable with the ALLOCATE COLLECTION statement.
The ALLOCATE COLLECTION statement sets SQLCODE (that is, sqlca.sqlcode) to zero (0) if the memory allocation was successful, or to a negative error code if the allocation failed.
Examples
EXEC SQL BEGIN DECLARE SECTION; client collection a_set; EXEC SQL END DECLARE SECTION; . . . EXEC SQL allocate collection :a_set;
EXEC SQL BEGIN DECLARE SECTION; client collection set(integer not null) a_typed_set; EXEC SQL END DECLARE SECTION; . . . EXEC SQL allocate collection :a_typed_set;