http://qs321.pair.com?node_id=1194008


in reply to Re^5: SELECT LAST_INSERT_ID does not work
in thread SELECT LAST_INSERT_ID does not work

Oracle's RETURNING clause is simply the best way to do it.

I think PostgreSQL's RETURNING clause is far, far better.

Oracle's way forces you to read the values into variables that you also have to define beforehand:

(Oracle12 docs:) "For each expression in the RETURNING list, you must specify a corresponding type-compatible PL/SQL variable or host variable in the INTO list."

Yuck, that's awful. That's really not handy.

It seems the objections mentioned in this old SO thread are still valid.

By the way, postgres has had INSERT ... RETURNING since v8.2 (2006). I rather suspect that Oracle's kludgy PL/SQL-based imitation was bolted on after that, and because of it. (Well, maybe 'kludgy' is too harsh. But the above disadvantages certainly make it imperfect compared with Postgres.)

INSERT - Oracle

INSERT - PostgreSQL