Both Oracle and PostgreSQL support SQLERRM variable that contains the error message for the last exception. Note that error messages for the same errors can be different.
Oracle:
CREATE TABLE t1 (c1 INT NOT NULL); BEGIN -- Try to insert NULL into non-nullable column INSERT INTO t1 VALUES (NULL); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Error message is ' || SQLERRM); END; / # Error message is ORA-01400: cannot insert NULL into ("T1"."C1") # PL/SQL procedure successfully completed.
PostgreSQL:
CREATE TABLE t1 (c1 INT NOT NULL); DO $$ BEGIN -- Try to insert NULL into non-nullable column INSERT INTO t1 VALUES (NULL); EXCEPTION WHEN OTHERS THEN RAISE NOTICE '%','Error message is ' || SQLERRM; END; $$; # NOTICE: Error message is null value in column "c1" violates not-null constraint
For more information, see Oracle to PostgreSQL Migration.