# BNF for WolfSQLParser.jj

## NON-TERMINALS

Start | ::= | ( ExplainPlan )? ( ( DML | DDL | DOL ) ( <SEMICOLON> )? )+
ExplainPlan | ::= | <EXPLAIN> <PLAN> ( <SET> tableIdentifier <EQUAL> Literal )? ( <INTO> ( tableIDDot )? tableIdentifier )? <FOR>
DML | ::= | ( SelectBase | UpdateStatement | DeleteStatement | InsertStatement )
DDL | ::= | ( Alter | Create | Drop | Truncate | Grant | Revoke )
DOL | ::= | ( Analyze | Comment )
Analyze | ::= | <ANALYZE> ( <TABLE> | <INDEX> | <CLUSTER> ) ( tableIDDot )? tableIdentifier ( ( <COMPUTE> <STATISTICS> ) | ( <ESTIMATE> <STATISTICS> ( <SAMPLE> <INTEGER_LITERAL> ( <ROWS> | <PERCENT> ) )? ) )
Comment | ::= | <COMMENT> <ON> ( ( <TABLE> ( tableIDDot )? tableIdentifier ) | ( <COLUMN> SchemaTableColumn ) ) <IS> <CHARACTER_LITERAL>
Create | ::= | <CREATE> ( <OR> <REPLACE> )? ( CreateTable | CreateUser | CreateTrigger | CreateProcedure | CreateFunction )
Drop | ::= | <DROP> ( ( <TABLE> ( IDDot )? Identifier ( ( <CASCADE> ( <CONSTRAINTS> )? ) | <RESTRICT> ) ) | ( <INDEX> ( IDDot )? Identifier ) )
Truncate | ::= | <TRUNCATE> <TABLE> ( IDDot )? tableIdentifier
Grant | ::= | <GRANT> ( ( <ADMIN> | <DBA_DDL> | <RESOURCE> ) | ( ( <INSERT> | <DELETE> | <UPDATE> | <SELECT> | <REFERENCES> ) <ON> Identifier ) ) <TO> Identifier ( <COMMA> Identifier )*
Revoke | ::= | <REVOKE> ( ( <ADMIN> | <DBA_DDL> | <RESOURCE> ) | ( ( <INSERT> | <DELETE> | <UPDATE> | <SELECT> | <REFERENCES> ) <ON> Identifier ) ) <FROM> Identifier ( <COMMA> Identifier )*
CreateTrigger | ::= | <TRIGGER> ( IDDot )? Identifier ( <BEFORE> | <AFTER> | ( <INSTED> <OF> ) ) Dml_eventClause ( <WHEN> <OPENPAREN> Condition <CLOSEPAREN> )? Sub_program_body
Dml_eventClause | ::= | Dml_eventClauseUnit1 ( <OR> Dml_eventClauseUnit1 )* <ON> ( IDDot )? Identifier ( <FOR> <EACH> <ROW> )?
Dml_eventClauseUnit1 | ::= | ( <DELETE> | <INSERT> | ( <UPDATE> ( <OF> Identifier ( <COMMA> Identifier )* )? ) )
CreateFunction | ::= | <FUNCTION> ( IDDot )? tableIdentifier RelationalListWithIO <RETURN> <COLUMN_TYPE> ( <IS> | <AS> ) Sub_program_body <RETURN> Expr <SEMICOLON> <END> <SEMICOLON>
CreateProcedure | ::= | <PROCEDURE> ( IDDot )? tableIdentifier RelationalListWithIO ( <IS> | <AS> ) Sub_program_body <END> <SEMICOLON>
Sub_program_body | ::= | ( AssignmentStatements )? <BEGIN> ( ( PLSQLStatement | LoopStatement ) )+
PLSQLStatement | ::= | ( DML | DDL | DOL | AssignmentExpr ) <SEMICOLON>
AssignmentExpr | ::= | ( Identifier <ASSIGN> )? Expr
LoopStatement | ::= | <FOR> Identifier <IN> NumberLiteral ".." NumberLiteral <LOOP> ( PLSQLStatement )+ <END> <LOOP>
AssignmentStatements | ::= | ( <DECLARE> )? ( AssignmentStatementSub )+
AssignmentStatementSub | ::= | SchemaTableColumn ( FullType )? ( <ASSIGN> Expr )? <SEMICOLON>
CreateTable | ::= | ( <GLOBAL> <TEMPORARY> )? <TABLE> ( IDDot )? tableIdentifier RelationalList ( <ON> <COMMIT> ( <DELETE> | <PRESERVE> ) <ROWS> )? ( PhysicalPropertiesClause )? ( TablePropertiesClause )?
TablePropertiesClause | ::= | ( <CACHE> | <NOCACHE> )
PhysicalPropertiesClause | ::= | ( ( SegmentAttributesClause | TableCompressionClause )+ | ( <ORGANIZATION> ( ( <HEAP> ( SegmentAttributesClause | TableCompressionClause )* ) | ( <INDEX> ( SegmentAttributesClause | IndexOrgTableClause )* ) ) ) | ( <CLUSTER> tableIdentifier <OPENPAREN> tableIdentifier ( <COMMA> tableIdentifier )* <CLOSEPAREN> ) )
IndexOrgTableClause | ::= | ( ( <PCTTHRESHOLD> NumberLiteral ) | TableCompressionClause )
TableCompressionClause | ::= | ( ( <COMPRESS> NumberLiteral ) | <NOCOMPRESS> )
SegmentAttributesClause | ::= | ( PhysicalAttributesClause | LoggingClause | ( <TABLESPACE> tableIdentifier ) )
CreateUser | ::= | <USER> tableIdentifier <IDENTIFIED> <BY> Identifier
RelationalList | ::= | <OPENPAREN> RelationalProperties ( <COMMA> RelationalProperties )* <CLOSEPAREN>
RelationalListWithIO | ::= | <OPENPAREN> RelationalPropertiesIO ( <COMMA> RelationalPropertiesIO )* <CLOSEPAREN>
RelationalPropertiesIO | ::= | tableIdentifier ( <IN> )? ( <OUT> )? ( <NOCOPY> )? <COLUMN_TYPE>
RelationalProperties | ::= | ( ( ( DefineColumn ( ColumnConstraint )* ) ) | TableConstraint )
TableConstraint | ::= | ( <CONSTRAINT> tableIdentifier )? ( ( ( <UNIQUE> | ( <PRIMARY> <KEY> ) ) <OPENPAREN> tableIdentifier ( <COMMA> tableIdentifier )* <CLOSEPAREN> ) | ForeignKeyClause | ( <CHECK> ) ) ( ConstraintState )?
ColumnConstraint | ::= | ( ( ( <NOT> )? <NULL> ) | <UNIQUE> | ( <PRIMARY> <KEY> ) | ( ReferencesClause ) | ( <CHECK> ) ) ( ConstraintState )*
ForeignKeyClause | ::= | <FOREIGN> <KEY> <OPENPAREN> tableIdentifier ( <COMMA> tableIdentifier )* <CLOSEPAREN> ReferencesClause
ConstraintState | ::= | ( <ENABLE> | <DISABLE> | ( ( <NOT> )? <DEFERRABLE> ) | UsingIndexClause )
UsingIndexClause | ::= | <USING> <INDEX> ( PhysicalAttributesClause | LoggingClause | ( <TABLESPACE> tableIdentifier | <DEFAULT2> ) )*
PhysicalAttributesClause | ::= | ( ( <PCTFREE> NumberLiteral ) | ( <PCTUSED> NumberLiteral ) | ( <INITRANS> NumberLiteral ) | ( <MAXTRANS> NumberLiteral ) | StorageClause )
LoggingClause | ::= | ( <LOGGING> | <NOLOGGING> )
StorageClause | ::= | <STORAGE> <OPENPAREN> ( ( <INITIAL> Size ) | ( <NEXT> Size ) | ( <MINEXTENTS> NumberLiteral ) | ( <MAXEXTENTS> ( NumberLiteral | <UNLIMITED> ) ) | ( <PCTINCREASE> NumberLiteral ) | ( <FREELIST> <GROUPS> NumberLiteral ) | ( <FREELISTS> NumberLiteral ) | ( <OPTIMAL> ( ( NumberLiteral | <NULL> ) )? ) | ( <BUFFER_POOL> ( <KEEP> | <RECYCLE> | <DEFAULT2> ) ) )+ <CLOSEPAREN>
Size | ::= | ( <SIZE_LITERAL> | NumberLiteral )
Alter | ::= | <ALTER> <TABLE> ( tableIDDot )? tableIdentifier ( AlterSimple | AlterMulti )
AlterSimple | ::= | ( ( <RENAME> <TO> tableIdentifier ) | RecordsPerBlockClause )
RecordsPerBlockClause | ::= | ( <MINIMIZE> | <NOMINIMIZE> ) <RECORDS_PER_BLOCK>
AlterMulti | ::= | ( ( <ADD> ( ( <OPENPAREN> AddColumnOptions <CLOSEPAREN> ) | ( AddColumnOptions ) ) ) | ( <MODIFY> <OPENPAREN> ModifyColumnOptions <CLOSEPAREN> ) )+
AddColumnOptions | ::= | DefineColumn ( ColumnRefConstraint )? ( ColumnConstraint )* ( <COMMA> DefineColumn ( ColumnRefConstraint )? ( ColumnConstraint )* )*
ModifyColumnOptions | ::= | ModifyColumnOptionsSub ( <COMMA> ModifyColumnOptionsSub )*
ModifyColumnOptionsSub | ::= | DefineColumn ( ColumnConstraint )?
DefineColumn | ::= | tableIdentifier FullType ( <DEFAULT2> ( Identifier | Literal ) )? ( <GENERATED> <BY> <DEFAULT2> <AS> <IDENTITY> )?
ColumnRefConstraint | ::= | ( ( <SCOPE> <IS> ( tableIDDot )? tableIdentifier ) | ( <WITH> <ROWID> ) | ( ( <CONSTRAINT> tableIdentifier )? ReferencesClause ) )
ReferencesClause | ::= | <REFERENCES> ( IDDot )? tableIdentifier ( <OPENPAREN> tableIdentifier <CLOSEPAREN> )? ( <ON> <DELETE> ( <CASCADE> | <SET> <NULL> ) )?
FullType | ::= | <COLUMN_TYPE> ( <OPENPAREN> NumberLiteral ( <COMMA> NumberLiteral )? <CLOSEPAREN> )?
SelectBase | ::= | ( SelectBaseAndUnion ( OrderByClause )? ( ForUpdateClause )? )
SelectBaseAndUnion | ::= | ( SelectSecond ( UnionPart SelectSecond )* )
Subquery | ::= | SelectBase
SelectSecond | ::= | ( SelectThird | <OPENPAREN> Subquery <CLOSEPAREN> )
UnionPart | ::= | ( ( <UNION> ( <ALL> )? ) | <INTERSECT> | <MINUS2> )
ForUpdateClause | ::= | <FOR> <UPDATE> ( <OF> ForUpdateClauseElement ( <COMMA> ForUpdateClauseElement )* )? ( <NOWAIT> )?
ForUpdateClauseElement | ::= | ( Identifier <DOT> )? Identifier <DOT> Identifier
PreColumnsClause | ::= | ( <ALL> | ( <DISTINCT> | <UNIQUE> ) )
SelectThird | ::= | <SELECT> ( Hint )? ( PreColumnsClause )? SelectColumns ( SelectIntoStatement )? ( From ) ( WhereClause )? ( HierarchicalQueryClause )? ( GroupByClause )?
SelectIntoStatement | ::= | <INTO> Identifier ( <COMMA> Identifier )*
From | ::= | <FROM> ( TableRefference ( <COMMA> TableRefference )* )
Hint | ::= | <HINT_COM_START> <HINT_COM_END>
SelectColumns | ::= | ( <ASTERISK> | ( SelectColumnsElement ( <COMMA> SelectColumnsElement )* ) )
SelectColumnsElement | ::= | ( Expr ( ( <AS> )? ( Identifier | Literal ) )? )
TableRefference | ::= | QueryTableExpressionClause ( JoinedTable )*
FlashBackClause | ::= | ( ( <VERSIONS> <BETWEEN> ( <SCAN> | <TIMESTAMP3> ) ( <MINVALUE> | Expr ) <AND> ( <MAXVALUE> | Expr ) ) | ( <AS> <OF> ( <SCAN> | <TIMESTAMP3> ) Expr ) )
JoinedTable | ::= | ( ( JoinType <JOIN> TableRefference ( ( ( <ON> Condition ) | ( <USING> <OPENPAREN> tableIdentifier ( <COMMA> tableIdentifier )* <CLOSEPAREN> ) ) ) ) | ( ( <CROSS> <JOIN> ) | ( <NATURAL> ( JoinType )? <JOIN> TableRefference ) ) )
JoinType | ::= | ( <INNER> | ( ( <LEFT> | <RIGHT> | <FULL> ) ( <OUTER> )? ) )
QueryTableExpressionClause | ::= | ( ( ( Subquery ) | ( ( tableIDDot )? tableIdentifier ( AtID )? ) ) ( FlashBackClause )? ( tableIdentifier )? )
UpdateStatement | ::= | <UPDATE> ( Hint )? QueryTableExpressionClause SetClause ( WhereClause )? ( ReturningClause )?
SetClause | ::= | <SET> SetClauseElement ( <COMMA> SetClauseElement )*
SetClauseElement | ::= | ( ( ( <OPENPAREN> ExpressionList <CLOSEPAREN> <EQUAL> <OPENPAREN> Subquery <CLOSEPAREN> ) ) | ( tableIdentifier <EQUAL> ( Expr | ( <OPENPAREN> Subquery <CLOSEPAREN> ) ) ) )
ReturningClause | ::= | <RETURNING> Expr ( <COMMA> Expr )* <INTO> tableIdentifier ( <COMMA> tableIdentifier )*
DeleteStatement | ::= | <DELETE> ( Hint )? ( <FROM> )? QueryTableExpressionClause ( WhereClause )? ( ReturningClause )?
InsertStatement | ::= | <INSERT> ( Hint )? <INTO> QueryTableExpressionClause ( InsertColumns )? ValueClauses
InsertColumns | ::= | <OPENPAREN> tableIdentifier ( <COMMA> tableIdentifier )* <CLOSEPAREN>
ValueClauses | ::= | ( ValueClause | Subquery ) ( <COMMA> ( ValueClause | Subquery ) )*
ValueClause | ::= | <VALUES> <OPENPAREN> ( ExpressionList | Subquery ) <CLOSEPAREN>
WhereClause | ::= | <WHERE> ( Condition )
HierarchicalQueryClause | ::= | ( <START> <WITH> Condition )? <CONNECT> <BY> Condition
GroupByClause | ::= | <GROUP> <BY> ( ( Expr ( <COMMA> Expr )* ) | ( ( <CUBE> | <ROLLUP> ) <OPENPAREN> ExpressionList <CLOSEPAREN> ) ) ( <HAVING> Condition )?
OrderByClause | ::= | <ORDER> <BY> OrderByElement ( <COMMA> OrderByElement )*
OrderByElement | ::= | Expr ( <ASC> | <DESC> )? ( <NULLS> ( <FIRST> | <LAST> ) )?
Condition | ::= | ConditionElement ( ( <AND> | <OR> ) ConditionElement )*
ConditionElement | ::= | ( CompoundCondition | ( <OPENPAREN> ExpressionList <CLOSEPAREN> ( SimpleComparisonConditionList | GroupComparisonConditionList | MembershipConditionList ) ) | ( Expr ( SimpleComparisonCondition | GroupComparisonCondition | MembershipCondition | RangeCondition | NULLCondition | EXISTSCondition | LIKECondition ) ) )
SimpleComparisonCondition | ::= | CompareOperator ConditionR3
GroupComparisonCondition | ::= | CompareOperator AnySomeAll ConditionR2
MembershipCondition | ::= | ( <NOT> )? <IN> ConditionR2
RangeCondition | ::= | ( <NOT> )? <BETWEEN> Expr <AND> Expr
NULLCondition | ::= | <IS> ( <NOT> )? <NULL>
EXISTSCondition | ::= | <EXISTS> <OPENPAREN> Subquery <CLOSEPAREN>
LIKECondition | ::= | ( <NOT> )? <LIKE> ( <CHARACTER_LITERAL> | <QUESTIONMARK> | <BIND_LITERAL> ) ( <ESCAPE> <CHARACTER_LITERAL> )?
SimpleComparisonConditionList | ::= | CompareEqualableOperator <OPENPAREN> Subquery <CLOSEPAREN>
GroupComparisonConditionList | ::= | CompareEqualableOperator AnySomeAll ConditionR1
MembershipConditionList | ::= | ( <NOT> )? <IN> ConditionR1
ConditionR1 | ::= | <OPENPAREN> ( Subquery | ExpressionList ) <CLOSEPAREN>
ConditionR2 | ::= | ( <OPENPAREN> ExpressionList <CLOSEPAREN> | ( <OPENPAREN> Subquery <CLOSEPAREN> ) )
ConditionR3 | ::= | ( Expr | ( <OPENPAREN> Subquery <CLOSEPAREN> ) )
AnySomeAll | ::= | ( <ANY> | <SOME> | <ALL> )
CompoundCondition | ::= | ( ( <NOT> Condition ) | ( <OPENPAREN> Condition <CLOSEPAREN> ) )
Expr | ::= | ( ExprComp ( ( Operator ) ExprComp )* )
ExprComp | ::= | ( UserFunction | SimpleExpression | CompoundExpression | BuiltInFunctionExpression | DecodeExpression | CaseExression )
DecodeExpression | ::= | <DECODE> <OPENPAREN> Expr ( <COMMA> Expr )* <CLOSEPAREN>
ExpressionList | ::= | Expr ( <COMMA> Expr )*
UserFunction | ::= | SchemaTableColumn <OPENPAREN> Expr ( <COMMA> Expr )* <CLOSEPAREN>
SimpleExpression | ::= | ( SchemaTableColumn | Literal | <NULL> )
SchemaTableColumn | ::= | ( PseudoColumn | ( ( IDDot )? ( IDDot )? ( <ASTERISK> | <CURRVAL> | <NEXTVAL> | <QUESTIONMARK> | <BIND_LITERAL> | Identifier ) ( <JOINPLUS> )? ) )
AtID | ::= | <ATMARK> Identifier
IDDot | ::= | Identifier <DOT>
PseudoColumn | ::= | ( <LEVEL> | <ROWID> | <ROWNUM> )
CompoundExpression | ::= | ( ( <OPENPAREN> Expr <CLOSEPAREN> ) | ( ( <PLUS> | <MINUS> | <PRIOR> ) Expr ) )
Operator | ::= | ( <PLUS> | <MINUS> | <CONCAT> | <SLASH> | <ASTERISK> )
BuiltInFunctionExpression | ::= | Function ( <OPENPAREN> ( <ALL> | <DISTINCT> )? Expr ( <COMMA> Expr )* <CLOSEPAREN> )?
Function | ::= | ( AggregateFunction | SingleRowFunction )
SingleRowFunction | ::= | ( Interval | DateTimeFunction | CharactorFunction | ConvertFunction | MiscellaneousFunction )
MiscellaneousFunction | ::= | ( Nvl | AbcFunction )
CaseExression | ::= | <CASE> ( Expr )? <WHEN> Expr <THEN> Expr ( <WHEN> Expr <THEN> Expr )* ( <ELSE> Expr )? <END>
Nvl | ::= | ( ( <NVL2> <OPENPAREN> Expr <COMMA> Expr <COMMA> Expr <CLOSEPAREN> ) | ( <NVL> <OPENPAREN> Expr <COMMA> Expr <CLOSEPAREN> ) )
AbcFunction | ::= | ( ( ( <ABS> | <ACOS> | <ASCIISTR> | <ASCII> | <ASIN> | <ATAN> | <CARDINALITY> | <CEIL> | <CHARTOROWID> | <COS> | <COSH> | <EXP> | <FLOOR> | <LAST_DAY> | <LENGTH> | <LENGTHB> | <LN> ) <OPENPAREN> Expr <CLOSEPAREN> ) | ( ( <BIN_TO_NUM> | <COALESCE> ) <OPENPAREN> Expr ( <COMMA> Expr )* <CLOSEPAREN> ) | ( ( <ATAN2> | <BITAND> | <CONCAT> | <LOG> ) <OPENPAREN> Expr <COMMA> Expr <CLOSEPAREN> ) | ( <CHR> <OPENPAREN> ( <USING> <NCHAR_CS> )? <CLOSEPAREN> ) | ( <PI> <OPENPAREN> <CLOSEPAREN> ) )
CharactorFunction | ::= | ( ( ( <LPAD> | <RPAD> ) <OPENPAREN> ( Identifier | Literal ) <COMMA> Expr ( <COMMA> Literal )? <CLOSEPAREN> ) | ( ( <SUBSTR> | <SUBSTRB> | <REPLACE> | <TRANSLATE> ) <OPENPAREN> Expr <COMMA> Literal ( <COMMA> Literal )? <CLOSEPAREN> ) | ( ( <UPPER> | <LOWER> ) <OPENPAREN> Expr <CLOSEPAREN> ) | ( ( <LTRIM> | <RTRIM> ) <OPENPAREN> Expr ( <COMMA> Literal )? <CLOSEPAREN> ) | ( <TRIM> <OPENPAREN> ( Literal <FROM> )? Expr <CLOSEPAREN> ) )
ConvertFunction | ::= | ( ( ( <TO_CHAR> | <TO_DATE> | <TO_NUMBER> | <ROUND> ) <OPENPAREN> Expr ( <COMMA> Literal ( <COMMA> Literal )? )? <CLOSEPAREN> ) | ( <CAST> <OPENPAREN> Expr <AS> FullType <CLOSEPAREN> ) )
Interval | ::= | <INTERVAL> Literal ( <DAY> | <HOUR> | <MINUTE> | <SECOND> )
DateTimeFunction | ::= | ( <SYSDATE> | <CURRENT_DATE> | <CURRENT_TIMESTAMP> | ( ( <ADD_MONTHS> | <MONTHS_BETWEEN> ) <OPENPAREN> Expr <COMMA> Expr <CLOSEPAREN> ) | <DATEDIFF> <OPENPAREN> Expr <COMMA> Expr <COMMA> Expr <CLOSEPAREN> | <CURDATE> <OPENPAREN> <CLOSEPAREN> )
AggregateFunction | ::= | ( Count | MaxMinSum | RowNumber | Rank ) ( AnalyticClause )?
AnalyticClause | ::= | <OVER> <OPENPAREN> ( <PARTITION> <BY> ExpressionList )? ( OrderByClause ( WindowingClause )? )? <CLOSEPAREN>
WindowingClause | ::= | ( <ROWS> | <RANGE> ) ( ( <BETWEEN> ( ( <UNBOUNDED> <PRECEDING> ) | ( <CURRENT> <ROW> ) | ( NumberLiteral ( <PRECEDING> | <FOLLOWING> ) ) ) <AND> ( ( <UNBOUNDED> <FOLLOWING> ) | ( <CURRENT> <ROW> ) | ( NumberLiteral ( <PRECEDING> | <FOLLOWING> ) ) ) ) | ( ( <UNBOUNDED> <PRECEDING> ) | ( <CURRENT> <ROW> ) | ( NumberLiteral <PRECEDING> ) ) )
RowNumber | ::= | <ROW_NUMBER> <OPENPAREN> <CLOSEPAREN>
Rank | ::= | ( <RANK> | <DENSE_RANK> ) <OPENPAREN> <CLOSEPAREN>
Count | ::= | <COUNT> <OPENPAREN> ( <ASTERISK> | ( ( <ALL> | <DISTINCT> )? Expr ) ) <CLOSEPAREN>
MaxMinSum | ::= | ( <MAX> | <MIN> | <SUM> | <AVG> ) <OPENPAREN> ( ( <ALL> | <DISTINCT> )? Expr ) <CLOSEPAREN>
tableIDDot | ::= | tableIdentifier <DOT>
tableIdentifier | ::= | ( ( <IDENTIFIER> | <STRING_LITERAL> ) ( <SHARP> )? )
Identifier | ::= | ( ( <IDENTIFIER> | <COUNT> | <FLOOR> ) ( <SHARP> )? )
Literal | ::= | ( <STRING_LITERAL> | <CHARACTER_LITERAL> | NumberLiteral | <CHR_DEF> )
NumberLiteral | ::= | ( ( <INTEGER_LITERAL> ) ( ( <DOT> <INTEGER_LITERAL> )? ) )
CompareOperator | ::= | ( CompareEqualableOperator | ( <GREATER> | <GREATEREQUAL> | <LESS> | <LESSEQUAL> ) )
CompareEqualableOperator | ::= | ( <EQUAL> | <NOTEQUAL> | <NOTEQUAL2> | <NOTEQUAL3> )