Oracle has supported the RETURNING clause in DML for years, but Oracle Database 23ai / 26ai significantly improves its usability by allowing direct access to OLD and NEW column values in INSERT UPDATE DELETE MERGE statements.
This makes it much easier to capture before-and-after data without triggers or extra queries.
Setup
Insert some test data:
UPDATE with RETURNING OLD and NEW
Oracle 23ai introduces explicit OLD and NEW references directly in the RETURNING clause—previously available mainly in triggers.
- No triggers required
- No extra
SELECTbefore or after DML - Perfect for auditing, logging, validation, and change tracking
DELETE with RETURNING OLD
For DELETE, the OLD keyword is optional, but Oracle 23ai allows it explicitly for clarity and consistency.
Both columns return the same pre-delete values, but explicit OLD improves readability—especially in complex codebase
INSERT with RETURNING NEW
Nothing special here all you can do is just add NEW keyword
SET SERVEROUTPUT ON
DECLARE
l_new_user_id number;
l_new_user_id1 number;
BEGIN
INSERT INTO test_tbl(user_id, user_name)
VALUES (10, 'tomasz10')
RETURNING
NEW user_id, --explicit NEW word
user_id --implicit NEW
INTO
l_new_user_id,
l_new_user_id1;
-- Display the results
DBMS_OUTPUT.PUT_LINE
(
', New user_id: $' || l_new_user_id ||
', New user_id: $' || l_new_user_id1
);
ROLLBACK;
END;
/
, New user_id: $10
, New user_id: $10
PL/SQL procedure successfully completed.
Have a fun 🙂
Tomasz