In SQL Server, you can do things like this:
INSERT INTO some_table (...) OUTPUT INSERTED.*
VALUES (...)
So that you can insert arbitrary sets of columns/values and get those results back. Is there any way to do this in Oracle?
The best I can come up with is this:
INSERT INTO some_table (...)
VALUES (...)
RETURNING ROWID INTO :out_rowid
...using :out_rowid as a bind variable. And then using a second query like this:
SELECT *
FROM some_table
WHERE ROWID = :rowid
...but this isn't quite the same as it returns everything within the column, not just the columns I inserted.
Is there any better way to do this without using a lot of PL/SQL and preferably with only one query?
Maybe I don't understand the question, but wouldn't this do it? (you must know what you want back)
@Vincent returning bulk collect into for multi-row insert works only in conjunction with forall (in another words if you insert from collection you can retrieve "results" into another)
The
RETURNING
clause supports the BULK COLLECT INTO synthax. Consider (10g):It works with multi-row
UPDATE
andDELETE
with my version (10.2.0.3.0) but NOT withINSERT
:Maybe you have a more recent version (11g?) and the
BULK COLLECT INTO
is supported for multi-rowINSERT
s ?