Execute an INSERT that is associated with a cursor
You can also use an sqlda structure to handle an
INSERT that is associated with an insert cursor. In this case, you
do not execute the statement with the EXECUTE...USING DESCRIPTOR statement.
Instead, you must declare and open an insert cursor and execute the
insert cursor with the PUT...USING DESCRIPTOR statement, as follows:
- Prepare the INSERT statement and associate it with an insert cursor with the DECLARE statement. All multirow INSERT statements must have a declared insert cursor.
- Create the cursor for the INSERT statement with the OPEN statement.
- Insert the first set of column values into the insert buffer with a PUT statement and its USING DESCRIPTOR clause. After this PUT statement, the column values stored in the specified sqlda structure are stored in the insert buffer. Repeat the PUT statement within a loop until there are no more rows to insert.
- After all the rows are inserted, exit the loop and flush the insert buffer with the FLUSH statement.
- Close the insert cursor with the CLOSE statement.
You handle the insert cursor in much the same way as you handle the cursor associated with a SELECT statement. For more information about how to use an insert cursor, see the PUT statement in the HCL OneDB™ Guide to SQL: Syntax.