INSERT v11
The INSERT
command available in the SQL language can also be used in SPL programs.
An expression in the SPL language can be used wherever an expression is allowed in the SQL INSERT
command. Thus, SPL variables and parameters can be used to supply values to the insert operation.
The following is an example of a procedure that performs an insert of a new employee using data passed from a calling program.
If an exception occurs all database changes made in the procedure are automatically rolled back. In this example the EXCEPTION
section with the WHEN OTHERS
clause catches all exceptions. Two variables are displayed. SQLCODE
is a number that identifies the specific exception that occurred. SQLERRM
is a text message explaining the error. See Exception Handling for more information on exception handling.
The following shows the output when this procedure is executed.
Note
The INSERT
command can be included in a FORALL
statement. A FORALL
statement allows a single INSERT
command to insert multiple rows from values supplied in one or more collections. See Using the FORALL Statement for more information on the FORALL
statement.