An insert cursor that includes an INSERT statement with
the collection-derived table clause allows you to insert many elements
into a collection variable.
About this task
To insert elements, follow these steps:
Procedure
- Create a client collection variable in your program.
- 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).
Results
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 Insertion of many elements into a collection
host variable.