An insert cursor that includes an INSERT statement with
the collection-derived table clause allows you to insert many elements
into a collection variable.
To insert elements, follow these steps:
- Create a client collection variable in your IBM®
Informix® ESQL/C program.
For more information, see Declaring collection variables and Manage memory for collections.
- Declare the insert cursor for the collection variable
with the DECLARE statement and open the cursor with the OPEN statement.
- Put the element or elements into the collection variable
with the PUT statement and the FROM clause.
- Close the insert cursor with the CLOSE statement, and if
you no longer need the cursor, free it with the FREE statement.
- After the collection variable contains all the elements,
you then use the UPDATE statement or the INSERT statement on a table
name to save the contents of the collection variable in a collection
column (SET, MULTISET, or LIST).
For more information,
see Operate on a collection column.
Tip: Instead of an insert cursor, you can use
an INSERT statement to insert elements one at a time into a collection variable.
However, an insert cursor is more efficient for large insertions.
For
more information, see Insert one element.
For
sample code that inserts several elements into a collection variable,
see Figure 1.