Select one element
The SELECT statement and the collection-derived table clause allow you to select one element into a collection.
The INTO clause identifies the variable in which to store the element value that is selected from the collection variable. The data type of the host variable in the INTO clause must be compatible with the element type of the collection.
EXEC SQL BEGIN DECLARE SECTION;
client collection set(integer not null) a_set;
int an_element, set_size;
EXEC SQL END DECLARE SECTION;
EXEC SQL allocate collection :a_set;
EXEC SQL select set_col, cardinality(set_col)
into :a_set, :set_size from tab_set
where id_col = 3;
if (set_size == 1)
EXEC SQL select * into :an_element from table(:a_set);
For more information about how to use a select cursor, see Selecting more than one element.
If the element of the collection is itself a complex type (collection or row type), the collection is a nested collection. For information about how to use a cursor to select elements from a nested collection, see Select values from a nested collection. The following section describes how to use a row variable to select a row element from a collection.