Repository navigation
Description
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 exceptionPRAGMA 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
- Upstream PR review: feat: add user-defined EXCEPTION support for PL/iSQL IvorySQL/IvorySQL#972 (comment)
- CodeRabbit review identified the same issue: feat: add user-defined EXCEPTION support for PL/iSQL IvorySQL/IvorySQL#972 (comment)
- Test branch:
test/user-exception
Related Issues
This blocks proper Oracle PL/SQL compatibility for user-defined exceptions with custom error codes.
Activity
fix: PRAGMA EXCEPTION_INIT grammar allows referencing declared except…
fix: PRAGMA EXCEPTION_INIT grammar allows referencing declared except…