Open doberkofler opened 1 year ago
As far as I can tell, there is no syntax for recognizing commands.
What you want is a new grammar to recognize SQL *Plus.
https://docs.oracle.com/en/database/oracle/oracle-database/23/sqpug/index.html vs
https://docs.oracle.com/en/database/oracle/oracle-database/23/lnpls/database-pl-sql-language-reference.pdf https://docs.oracle.com/en/database/oracle/oracle-database/23/lnpls/index.html#Oracle%C2%AE-Database
1) When looking at the grammar, it looks a lot as if the parser should support sql*plus script:
sql_script
: sql_plus_command_no_semicolon? ((sql_plus_command | unit_statement) (SEMICOLON '/'? (sql_plus_command | unit_statement))* SEMICOLON? '/'?) EOF
;
sql_plus_command
: EXIT
| PROMPT_MESSAGE
| SHOW (ERR | ERRORS)
| whenever_command
| timing_command
| start_command
;
2) Independently from full sql*plus support the parser actually does not complain about the set echo off
statement but refuses to parse multiple sql blocks.
Well Oracle itself calls it two different products, with two different documentations, one for plsql and another for sql-plus. The current grammar implementation is confusing to say the least.
The grammar does not support the commands completely and methodically.
It would probably be best to reorganize this grammar. Those rules should be yanked out and placed in another grammar along side PlSqlParser/Lexer.g4 that includes PlSqlParser/Lexer.g4, reflecting the relationship between plsql and sql-plus.
I'm currently just evaluating the use of the Antlr4 for a large refactoring job in a PL/SQL code base and must say that at least some basic documentation would go a long way for new users.
Well Oracle itself calls it two different products, with two different documentations, one for plsql and another for sql-plus. The current grammar implementation is confusing to say the least.
I agree and was actually surprised to see that the grammar named PlSql seems to support SqlPlus.
The grammar does not support the commands completely and methodically.
I understand.
It would probably be best to reorganize this grammar. Those rules should be yanked out and placed in another grammar along side PlSqlParser/Lexer.g4 that includes PlSqlParser/Lexer.g4, reflecting the relationship between plsql and sql-plus.
I completely agree but would like to add that most Oracle code bases are in fact stored in SqlPlus scripts and it would be very helpful to have a grammar that understand SqlPlus.
My plan is to separate the two grammars. My timeframe is unclear as I am overloaded cleaning up other issues that accumulate with the current process.
I expect the PL/SQL grammar to parse sql scripts containing multiple blocks of sqlplus, pl/sql and sql but when trying to do so the
script.sql
example reports theline 12:0 mismatched input 'declare' expecting <EOF>
error.error:
test:
script: