grammars-v4
grammars-v4 copied to clipboard
[PL/SQL] PlSqlParser $$ or Predefined Inquiry Directives is not supported
When i use the g4 file https://github.com/antlr/grammars-v4/blob/master/sql/plsql/PlSqlParser.g4
and parse the sql like below
CREATE OR REPLACE PROCEDURE p
AUTHID DEFINER IS
i PLS_INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE('Inside p');
i := $$PLSQL_LINE;
DBMS_OUTPUT.PUT_LINE('i = ' || i);
DBMS_OUTPUT.PUT_LINE('$$PLSQL_LINE = ' || $$PLSQL_LINE);
DBMS_OUTPUT.PUT_LINE('$$PLSQL_UNIT = ' || $$PLSQL_UNIT);
DBMS_OUTPUT.PUT_LINE('$$PLSQL_UNIT_OWNER = ' || $$PLSQL_UNIT_OWNER);
DBMS_OUTPUT.PUT_LINE('$$PLSQL_UNIT_TYPE = ' || $$PLSQL_UNIT_TYPE);
END;
I got the error:
line 11:51 token recognition error at: '$'
line 11:52 token recognition error at: '$'
Can anyone help to fix the issue?
you guys can reference this link
https://docs.oracle.com/en/database/oracle/oracle-database/19/lnpls/plsql-language-fundamentals.html#GUID-6CDF1EB6-913D-48E7-AFDA-DB4DE45209CE
temporary workaroud solution change parser to
constant
: TIMESTAMP (quoted_string | bind_variable) (AT TIME ZONE quoted_string)?
| INTERVAL (quoted_string | bind_variable | general_element_part)
(YEAR | MONTH | DAY | HOUR | MINUTE | SECOND)
('(' (UNSIGNED_INTEGER | bind_variable) (',' (UNSIGNED_INTEGER | bind_variable) )? ')')?
(TO ( DAY | HOUR | MINUTE | SECOND ('(' (UNSIGNED_INTEGER | bind_variable) ')')?))?
| numeric
| DATE quoted_string
| quoted_string
| NULL_
| TRUE
| FALSE
| DBTIMEZONE
| SESSIONTIMEZONE
| MINVALUE
| MAXVALUE
| DEFAULT
| STATIC_EXPRESSION
;
and add to lexer :
STATIC_EXPRESSION: '$''$' SIMPLE_LETTER (SIMPLE_LETTER | '$' | '_' | '#' | [0-9])*;