Host language variables can be used within expressions in the values clause or in the search condition of the subselect. Variables used in search conditions must denote constant values, and cannot represent names of database columns or include any operators. A host string variable can also replace the complete search condition of the subselect, as when it is used in the forms system query mode. Host language variables that correspond to column expressions can include null indicator variables.
The columns in the subselect must correspond in sequence to the columns into which values are being inserted. For example:
insert into emps (entryclerk, sicktime, ename)
select :yourname, 0, newename from newemps
In the previous example, the entryclerk column is filled from the form field, yourname, the sicktime column is initialized to 0 using a constant; and the ename column is filled from the names in the newename column of the newemps table.
The values clause can include structure variables that substitute for some or all of the expressions. The structure is expanded by the preprocessor into the names of its individual members; therefore, placing a structure name in the values clause is equivalent to enumerating all members of the structure in the order in which they were declared.
You must own the table or have insert privilege. To insert into a view you must be able to insert into the underlying base tables or views. If you do not own the view, you must have insert privilege for the view.
The keyword repeated directs the DBMS Server to encode the insert and save its execution plan when it is first executed. This encoding can account for significant performance improvements on subsequent executions of the same insert.
Do not specify the repeated option for insert statements that are constructed using dynamic SQL. A dynamic where clause cannot be used in a repeated insert: the query plan is saved when the query is first executed, and subsequent changes to the where clause are ignored.
The sqlerrd(3) of the SQLCA indicates the number of rows inserted by the statement. If no rows are inserted (for example, if no rows satisfied the subselect search condition), the sqlcode variable of the SQLCA is set to 100.
If an insert statement attempts to add a duplicate key to a column that has a unique constraint, a duplicate key error is returned, the current transaction is aborted, and any open cursors are closed.
Pages affected by the insert are locked in exclusive mode. When necessary, locking is escalated to the table level.