Using the RETURNING INTO Clause v12
The INSERT, UPDATE
, and DELETE
commands may be appended by the optional RETURNING INTO
clause. This clause allows the SPL program to capture the newly added, modified, or deleted values from the results of an INSERT, UPDATE
, or DELETE
command, respectively.
The following is the syntax.
insert
is a valid INSERT
command. update
is a valid UPDATE
command. delete
is a valid DELETE
command. If *
is specified, then the values from the row affected by the INSERT, UPDATE
, or DELETE
command are made available for assignment to the record or fields to the right of the INTO
keyword. (Note that the use of *
is an Advanced Server extension and is not compatible with Oracle databases.) expr_1, expr_2...
are expressions evaluated upon the row affected by the INSERT, UPDATE
, or DELETE
command. The evaluated results are assigned to the record or fields to the right of the INTO
keyword. record
is the identifier of a record that must contain fields that match in number and order, and are data type compatible with the values in the RETURNING
clause. field_1, field_2,...
are variables that must match in number and order, and are data type compatible with the set of values in the RETURNING
clause.
If the INSERT, UPDATE
, or DELETE
command returns a result set with more than one row, then an exception is thrown with SQLCODE 01422, query returned more than one row
. If no rows are in the result set, then the variables following the INTO
keyword are set to null.
Note
There is a variation of RETURNING INTO
using the BULK COLLECT
clause that allows a result set of more than one row that is returned into a collection. See Using the BULK COLLECT Clause for more information on the BULK COLLECT
clause.
The following example is a modification of the emp_comp_update
procedure introduced in UPDATE, with the addition of the RETURNING INTO
clause.
The following is the output from this procedure (assuming employee 9503
created by the emp_insert
procedure still exists within the table).
The following example is a modification of the emp_delete
procedure, with the addition of the RETURNING INTO
clause using record types.
The following is the output from this procedure.