PRAGMA EXCEPTION_INIT Grammar Bug - Incorrect Use of decl_varname
Summary
PRAGMA EXCEPTION_INIT fails with "duplicate declaration" error when trying to associate an already-declared exception with an error code. This is caused by incorrect grammar production using decl_varname instead of any_identifier.
Test Case
DECLARE
zero_excep exception;
PRAGMA exception_init(zero_excep, -1476);
var1 integer;
BEGIN
var1 := 100 / 0;
exception
WHEN zero_excep THEN
raise info 'handle zero excep';
end;
/
Expected Behavior (Oracle 23c)
handle zero excep
PL/SQL procedure successfully completed.
Actual Behavior (IvorySQL)
ERROR: duplicate declaration at or near "zero_excep"
LINE 3: PRAGMA exception_init(zero_excep, -1476);
^
Root Cause
In src/pl/plisql/src/pl_gram.y, the PRAGMA EXCEPTION_INIT production incorrectly uses decl_varname:
| K_PRAGMA K_EXCEPTION_INIT '(' decl_varname ',' ICONST ')' ';'
Problem: decl_varname enforces "name must NOT already be declared" and raises "duplicate declaration" error if the name exists.
But: PRAGMA EXCEPTION_INIT must reference an ALREADY declared exception variable.
This creates an impossible situation:
zero_excep exception; - Declares the exception
PRAGMA exception_init(zero_excep, ...) - ERROR: "duplicate declaration"!
Proposed Solution
Change the grammar to use any_identifier instead of decl_varname:
| K_PRAGMA K_EXCEPTION_INIT '(' any_identifier ',' exception_error_code ')' ';'
This allows PRAGMA EXCEPTION_INIT to reference existing exception variables without triggering duplicate declaration checks.
References
Related Issues
This blocks proper Oracle PL/SQL compatibility for user-defined exceptions with custom error codes.
PRAGMA EXCEPTION_INIT Grammar Bug - Incorrect Use of
decl_varnameSummary
PRAGMA EXCEPTION_INIT fails with "duplicate declaration" error when trying to associate an already-declared exception with an error code. This is caused by incorrect grammar production using
decl_varnameinstead ofany_identifier.Test Case
Expected Behavior (Oracle 23c)
Actual Behavior (IvorySQL)
Root Cause
In
src/pl/plisql/src/pl_gram.y, the PRAGMA EXCEPTION_INIT production incorrectly usesdecl_varname:Problem:
decl_varnameenforces "name must NOT already be declared" and raises "duplicate declaration" error if the name exists.But: PRAGMA EXCEPTION_INIT must reference an ALREADY declared exception variable.
This creates an impossible situation:
zero_excep exception;- Declares the exceptionPRAGMA exception_init(zero_excep, ...)- ERROR: "duplicate declaration"!Proposed Solution
Change the grammar to use
any_identifierinstead ofdecl_varname:This allows PRAGMA EXCEPTION_INIT to reference existing exception variables without triggering duplicate declaration checks.
References
test/user-exceptionRelated Issues
This blocks proper Oracle PL/SQL compatibility for user-defined exceptions with custom error codes.