Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL inserting multiple rows and returning something

In Oracle, one can insert multiple rows by doing a query like

INSERT ALL
   INTO mytable (column1, column2, column3) VALUES ('val1.1', 'val1.2', 'val1.3')
   INTO mytable (column1, column2, column3) VALUES ('val2.1', 'val2.2', 'val2.3')
   INTO mytable (column1, column2, column3) VALUES ('val3.1', 'val3.2', 'val3.3')
SELECT * FROM dual;

And with a prepared statement, doing a single insert like this one

BEGIN INSERT 
   INTO mytable (column1, column2, column3) VALUES (null, 'val1.2', 'val1.3')
RETURNING column1 INTO ?; END;

will result in returning column1's value (supposing there is a trigger assigning a value to it before insert).

Is there a way, if possible at all, to combine both? Meaning, inserting multiple values while still returning all the column1 values (a resultset) with a single query?

like image 635
Yanick Rochon Avatar asked Nov 05 '22 23:11

Yanick Rochon


1 Answers

From the documentation (at least through the 21c version), one of the restrictions to the returning clause:

You cannot specify the returning_clause for a multitable insert.

like image 126
Craig Avatar answered Nov 09 '22 15:11

Craig