This Oracle documentation page says that Oracle fully supports E171 SQLSTATE.
In PostgreSQL I can read this Standard SQL SQLSTATE variable (see it in db<>fiddle):
DO $$
DECLARE
v_1 int;
BEGIN
v_1 := 1/0;
EXCEPTION
WHEN DIVISION_BY_ZERO THEN RAISE EXCEPTION '<%> - % ', SQLSTATE, SQLERRM;
END;
$$
But when I try to read it in Oracle (see it in db<>fiddle):
BEGIN
DBMS_OUTPUT.PUT_LINE(1/0);
EXCEPTION
WHEN ZERO_DIVIDE THEN DBMS_OUTPUT.PUT_LINE('Error: ' || SQLSTATE || ' - ' || SQLERRM);
END;
/
it isn't recognized:
ORA-06550: line 4, column 59:
PLS-00201: identifier 'SQLSTATE' must be declared
ORA-06550: line 4, column 25:
PL/SQL: Statement ignored
The SQLCODE, deprecated by SQL-92, works in Oracle:
BEGIN
DBMS_OUTPUT.PUT_LINE(1/0);
EXCEPTION
WHEN ZERO_DIVIDE THEN DBMS_OUTPUT.PUT_LINE('Error: ' || SQLCODE || ' - ' || SQLERRM);
END;
/
I get:
dbms_output: Error: -1476 - ORA-01476: divisor is equal to zero
How can I obtain SQLSTATE in Oracle?