To put elements, one at a time, into the insert cursor,
use the PUT statement and the FROM clause.
The PUT statement identifies the insert cursor that is
associated with the collection variable. The FROM clause identifies
the element value to be inserted into the cursor. The data type of
any host variable in the FROM clause must be compatible with the element
type of the collection.
To indicate that the collection element
is to be provided later by the FROM clause of the PUT statement, use
an input parameter in the VALUES clause of the INSERT statement. You
can use the PUT statement with an insert cursor following either a
static DECLARE statement or the PREPARE statement. The following example
uses a PUT following a static DECLARE statement.
EXEC SQL DECLARE list_curs cursor FOR INSERT INTO table
(:alist);
EXEC SQL open list_curs;
EXEC SQL PUT list_curs from :asmint;
No input parameters
can appear in the DECLARE statement.
The following figure contains
a code fragment that demonstrates how to insert elements into the collection variable a_list and
then to update the list_col column of the tab_list table
(which Sample tables with collection columns defines)
with this new collection.
In Insertion of many elements into a collection
host variable,
the first statement that accesses the a_list variable is the OPEN
statement. Therefore, in the code, must be able
to determine the data type of the a_list variable. Because
the a_list host variable is a typed collection variable, can determine
the data type from the variable declaration. However, if a_list was
declared an untyped collection variable, you would need a SELECT
statement before the DECLARE statement executes to return the definition
of the associated collection column.
automatically
saves the contents of the insert cursor into the collection variable
when you put them into the insert cursor with the PUT statement.