-
Notifications
You must be signed in to change notification settings - Fork 8
/
PlSqlParser.g4
9633 lines (8377 loc) · 225 KB
/
PlSqlParser.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Oracle(c) PL/SQL 11g Parser
*
* Copyright (c) 2009-2011 Alexandre Porcelli <alexandre.porcelli@gmail.com>
* Copyright (c) 2015-2019 Ivan Kochurkin (KvanTTT, kvanttt@gmail.com, Positive Technologies).
* Copyright (c) 2017-2018 Mark Adams <madams51703@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
parser grammar PlSqlParser;
options {
tokenVocab=PlSqlLexer;
superClass=PlSqlParserBase;
}
@parser::postinclude {
#include <PlSqlParserBase.h>
}
sql_script
: (
(sql_plus_command | unit_statement) SEMICOLON?
| SEMICOLON
)* EOF
;
unit_statement
: alter_analytic_view
| alter_attribute_dimension
| alter_audit_policy
| alter_cluster
| alter_database
| alter_database_link
| alter_dimension
| alter_diskgroup
| alter_flashback_archive
| alter_function
| alter_hierarchy
| alter_index
| alter_inmemory_join_group
| alter_java
| alter_library
| alter_lockdown_profile
| alter_materialized_view
| alter_materialized_view_log
| alter_materialized_zonemap
| alter_operator
| alter_outline
| alter_package
| alter_pmem_filestore
| alter_procedure
| alter_resource_cost
| alter_role
| alter_rollback_segment
| alter_sequence
| alter_session
| alter_synonym
| alter_table
| alter_tablespace
| alter_tablespace_set
| alter_trigger
| alter_type
| alter_user
| alter_view
| create_analytic_view
| create_attribute_dimension
| create_audit_policy
| create_cluster
| create_context
| create_controlfile
| create_database
| create_database_link
| create_dimension
| create_directory
| create_diskgroup
| create_edition
| create_flashback_archive
| create_function_body
| create_hierarchy
| create_index
| create_inmemory_join_group
| create_java
| create_library
| create_lockdown_profile
| create_materialized_view
| create_materialized_view_log
| create_materialized_zonemap
| create_operator
| create_outline
| create_package
| create_package_body
| create_pmem_filestore
| create_procedure_body
| create_profile
| create_restore_point
| create_role
| create_rollback_segment
| create_sequence
| create_spfile
| create_synonym
| create_table
| create_tablespace
| create_tablespace_set
| create_trigger
| create_type
| create_user
| create_view
| drop_analytic_view
| drop_attribute_dimension
| drop_audit_policy
| drop_cluster
| drop_context
| drop_database
| drop_database_link
| drop_directory
| drop_diskgroup
| drop_edition
| drop_flashback_archive
| drop_function
| drop_hierarchy
| drop_index
| drop_indextype
| drop_inmemory_join_group
| drop_java
| drop_library
| drop_lockdown_profile
| drop_materialized_view
| drop_materialized_zonemap
| drop_operator
| drop_outline
| drop_package
| drop_pmem_filestore
| drop_procedure
| drop_restore_point
| drop_role
| drop_rollback_segment
| drop_sequence
| drop_synonym
| drop_table
| drop_tablespace
| drop_tablespace_set
| drop_trigger
| drop_type
| drop_user
| drop_view
| administer_key_management
| analyze
| anonymous_block
| associate_statistics
| audit_traditional
| comment_on_column
| comment_on_materialized
| comment_on_table
| data_manipulation_language_statements
| disassociate_statistics
| flashback_table
| grant_statement
| noaudit_statement
| purge_statement
| rename_object
| revoke_statement
| transaction_control_statements
| truncate_cluster
| truncate_table
| unified_auditing
| call_statement // put call statement after all statements.
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/ALTER-DISKGROUP.html
alter_diskgroup
: ALTER DISKGROUP ( id_expression (((add_disk_clause | drop_disk_clause)+ | resize_disk_clause) rebalance_diskgroup_clause?
| ( replace_disk_clause
| rename_disk_clause
| disk_online_clause
| disk_offline_clause
| rebalance_diskgroup_clause
| check_diskgroup_clause
| diskgroup_template_clauses
| diskgroup_directory_clauses
| diskgroup_alias_clauses
| diskgroup_volume_clauses
| diskgroup_attributes
| drop_diskgroup_file_clause
| convert_redundancy_clause
| usergroup_clauses
| user_clauses
| file_permissions_clause
| file_owner_clause
| scrub_clause
| quotagroup_clauses
| filegroup_clauses
)
)
| (id_expression (',' id_expression)* | ALL) (undrop_disk_clause | diskgroup_availability | enable_disable_volume)
)
;
add_disk_clause
: ADD ( (SITE sn=id_expression)? quorum_regular? (FAILGROUP fgn=id_expression)? DISK qualified_disk_clause (',' qualified_disk_clause)*)+
;
drop_disk_clause
: DROP ( quorum_regular? DISK id_expression force_noforce? (',' id_expression force_noforce?)*
| DISKS IN quorum_regular? FAILGROUP id_expression force_noforce? (',' id_expression force_noforce?)*
)
;
resize_disk_clause
: RESIZE ALL (SIZE size_clause)?
;
replace_disk_clause
: REPLACE DISK id_expression WITH CHAR_STRING force_noforce? (',' id_expression WITH CHAR_STRING force_noforce?)*
(POWER numeric)?
wait_nowait?
;
wait_nowait
: WAIT
| NOWAIT
;
rename_disk_clause
: RENAME ( DISK id_expression TO id_expression (',' id_expression TO id_expression)*
| DISKS ALL
)
;
disk_online_clause
: ONLINE ( (quorum_regular? DISK id_expression (',' id_expression)* | DISKS IN quorum_regular? FAILGROUP id_expression (',' id_expression)*)+
| ALL
)
(POWER numeric)?
wait_nowait?
;
disk_offline_clause
: OFFLINE ( quorum_regular? DISK id_expression (',' id_expression)*
| DISKS IN quorum_regular? FAILGROUP id_expression (',' id_expression)*
) timeout_clause?
;
timeout_clause
: DROP AFTER numeric (M_LETTER | H_LETTER)
;
rebalance_diskgroup_clause
: REBALANCE ( ((WITH | WITHOUT) phase+)? (POWER numeric) (WAIT | NOWAIT)?
| MODIFY POWER numeric?
)
;
phase
: id_expression //TODO
;
check_diskgroup_clause
: CHECK ALL? (REPAIR | NOREPAIR)? //inconsistent documentation
;
diskgroup_template_clauses
: (ADD | MODIFY) TEMPLATE id_expression qualified_template_clause (',' id_expression qualified_template_clause)*
| DROP TEMPLATE id_expression (',' id_expression)*
;
qualified_template_clause
: ATTRIBUTES '(' redundancy_clause? striping_clause? ')' //inconsistent documentation
;
redundancy_clause
: MIRROR
| HIGH
| UNPROTECTED
| PARITY
| DOUBLE
;
striping_clause
: FINE
| COARSE
;
force_noforce
: FORCE
| NOFORCE
;
diskgroup_directory_clauses
: ADD DIRECTORY filename (',' filename)*
| DROP DIRECTORY filename force_noforce? (','filename force_noforce?)*
| RENAME DIRECTORY dir_name TO dir_name (',' dir_name TO dir_name)*
;
dir_name
: CHAR_STRING
;
diskgroup_alias_clauses
: ADD ALIAS CHAR_STRING FOR CHAR_STRING (',' CHAR_STRING FOR CHAR_STRING)*
| DROP ALIAS CHAR_STRING (',' CHAR_STRING)*
| RENAME ALIAS CHAR_STRING TO CHAR_STRING (',' CHAR_STRING TO CHAR_STRING)*
;
diskgroup_volume_clauses
: add_volume_clause
| modify_volume_clause
| RESIZE VOLUME id_expression SIZE size_clause
| DROP VOLUME id_expression
;
add_volume_clause
: ADD VOLUME id_expression SIZE size_clause redundancy_clause?
(STRIPE_WIDTH numeric (K_LETTER | M_LETTER))?
(STRIPE_COLUMNS numeric)?
;
modify_volume_clause
: MODIFY VOLUME id_expression (MOUNTPATH CHAR_STRING)?
(USAGE CHAR_STRING)?
;
diskgroup_attributes
: SET ATTRIBUTE CHAR_STRING '=' CHAR_STRING
;
modify_diskgroup_file
: MODIFY FILE CHAR_STRING ATTRIBUTE '(' disk_region_clause ')' (',' CHAR_STRING ATTRIBUTE '(' disk_region_clause ')')*
;
disk_region_clause
:
;
drop_diskgroup_file_clause
: DROP FILE filename (',' filename)*
;
convert_redundancy_clause
: CONVERT REDUNDANCY TO FLEX
;
usergroup_clauses
: ADD USERGROUP CHAR_STRING WITH MEMBER CHAR_STRING (',' CHAR_STRING)*
| MODIFY USERGROUP CHAR_STRING (ADD | DROP) MEMBER CHAR_STRING (',' CHAR_STRING)*
| DROP USERGROUP CHAR_STRING
;
user_clauses
: ADD USER CHAR_STRING (',' CHAR_STRING)*
| DROP USER CHAR_STRING (',' CHAR_STRING)* CASCADE?
| REPLACE USER CHAR_STRING WITH CHAR_STRING (',' CHAR_STRING WITH CHAR_STRING)*
;
file_permissions_clause
: SET PERMISSION (OWNER | GROUP | OTHER) '=' (NONE | READ (ONLY | WRITE)) (',' (OWNER | GROUP | OTHER) '=' (NONE | READ (ONLY | WRITE)))*
FOR FILE CHAR_STRING (',' CHAR_STRING)*
;
file_owner_clause
: SET OWNERSHIP (OWNER | GROUP) '=' CHAR_STRING (',' (OWNER | GROUP) '=' CHAR_STRING)* FOR FILE CHAR_STRING (',' CHAR_STRING)*
;
scrub_clause
: SCRUB (FILE CHAR_STRING | DISK id_expression)?
(REPAIR | NOREPAIR)?
(POWER (AUTO | LOW | HIGH | MAX))?
wait_nowait?
force_noforce?
STOP?
;
quotagroup_clauses
: ADD QUOTAGROUP id_expression (SET property_name '=' property_value)?
| MODIFY QUOTAGROUP id_expression SET property_name '=' property_value
| MOVE QUOTAGROUP id_expression TO id_expression
| DROP QUOTAGROUP id_expression
;
property_name
: id_expression
;
property_value
: id_expression
;
filegroup_clauses
: add_filegroup_clause
| modify_filegroup_clause
| move_to_filegroup_clause
| drop_filegroup_clause
;
add_filegroup_clause
: ADD FILEGROUP id_expression ((DATABASE | CLUSTER | VOLUME) id_expression | TEMPLATE) (FROM TEMPLATE id_expression)?
(SET CHAR_STRING '=' CHAR_STRING)?
;
modify_filegroup_clause
: MODIFY FILEGROUP id_expression
SET CHAR_STRING '=' CHAR_STRING
;
move_to_filegroup_clause
: MOVE FILE CHAR_STRING TO FILEGROUP id_expression
;
drop_filegroup_clause
: DROP FILEGROUP id_expression CASCADE?
;
quorum_regular
: QUORUM
| REGULAR
;
undrop_disk_clause
: UNDROP DISKS
;
diskgroup_availability
: MOUNT (RESTRICTED | NORMAL)? (FORCE | NOFORCE)?
| DISMOUNT (FORCE | NOFORCE)?
;
enable_disable_volume
: (ENABLE | DISABLE) VOLUME ( id_expression (',' id_expression)* | ALL)
;
// DDL -> SQL Statements for Stored PL/SQL Units
// Function DDLs
drop_function
: DROP FUNCTION function_name ';'
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/ALTER-FLASHBACK-ARCHIVE.html
alter_flashback_archive
: ALTER FLASHBACK ARCHIVE fa=id_expression
( SET DEFAULT
| (ADD | MODIFY) TABLESPACE ts=id_expression flashback_archive_quota?
| REMOVE TABLESPACE rts=id_expression
| MODIFY /*RETENTION*/ flashback_archive_retention // inconsistent documentation
| PURGE (ALL | BEFORE (SCN expression | TIMESTAMP expression))
| NO? OPTIMIZE DATA
)
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/ALTER-HIERARCHY.html
alter_hierarchy
: ALTER HIERARCHY (schema_name '.')? hn=id_expression (RENAME TO nhn=id_expression | COMPILE)
;
alter_function
: ALTER FUNCTION function_name COMPILE DEBUG? compiler_parameters_clause* (REUSE SETTINGS)? ';'
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/ALTER-JAVA.html
alter_java
: ALTER JAVA (SOURCE | CLASS) (schema_name '.')? o=id_expression
(RESOLVER '(' ('(' match_string ','? (schema_name | '-') ')')+ ')')?
(COMPILE | RESOLVE | invoker_rights_clause)
;
match_string
: DELIMITED_ID
| '*'
;
create_function_body
: CREATE (OR REPLACE)? FUNCTION function_name ('(' parameter (',' parameter)* ')')?
RETURN type_spec (invoker_rights_clause | parallel_enable_clause | result_cache_clause | DETERMINISTIC)*
((PIPELINED? (IS | AS) (DECLARE? seq_of_declare_specs? body | call_spec))
| (PIPELINED | AGGREGATE) USING implementation_type_name
| sql_macro_body
) ';'
;
sql_macro_body
: SQL_MACRO IS BEGIN RETURN quoted_string SEMICOLON END
;
// Creation Function - Specific Clauses
parallel_enable_clause
: PARALLEL_ENABLE partition_by_clause?
;
partition_by_clause
: '(' PARTITION expression BY (ANY | (HASH | RANGE | LIST) paren_column_list) streaming_clause? ')'
;
result_cache_clause
: RESULT_CACHE relies_on_part?
;
relies_on_part
: RELIES_ON '(' tableview_name (',' tableview_name)* ')'
;
streaming_clause
: (ORDER | CLUSTER) expression BY paren_column_list
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/ALTER-OUTLINE.html
alter_outline
: ALTER OUTLINE (PUBLIC | PRIVATE)? o=id_expression
outline_options+
;
outline_options
: REBUILD
| RENAME TO non=id_expression
| CHANGE CATEGORY TO ncn=id_expression
| ENABLE
| DISABLE
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/ALTER-LOCKDOWN-PROFILE.html
alter_lockdown_profile
: ALTER LOCKDOWN PROFILE id_expression (lockdown_feature | lockdown_options | lockdown_statements)
(USERS '=' (ALL | COMMON | LOCAL))?
;
lockdown_feature
: disable_enable FEATURE ( '=' '(' string_list ')'
| ALL (EXCEPT '=' '(' string_list ')')?
)
;
lockdown_options
: disable_enable OPTION ( '=' '(' string_list ')'
| ALL (EXCEPT '=' '(' string_list ')')?
)
;
lockdown_statements
: disable_enable STATEMENT ( '=' '(' string_list ')'
| '=' '(' CHAR_STRING ')' statement_clauses
| ALL (EXCEPT '=' '(' string_list ')')?
)
;
statement_clauses
: CLAUSE ( '=' '(' string_list ')'
| '=' '(' CHAR_STRING ')' clause_options
| ALL (EXCEPT '=' '(' string_list ')')?
)
;
clause_options
: OPTION ( '=' '(' string_list ')'
| '=' '(' CHAR_STRING ')' option_values+
| ALL (EXCEPT '=' '(' string_list ')')?
)
;
option_values
: VALUE '=' '(' string_list ')'
| (MINVALUE | MAXVALUE) '=' CHAR_STRING
;
string_list
: CHAR_STRING (',' CHAR_STRING)*
;
disable_enable
: DISABLE
| ENABLE
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/DROP-LOCKDOWN-PROFILE.html
drop_lockdown_profile
: DROP LOCKDOWN PROFILE p=id_expression
;
// Package DDLs
drop_package
: DROP PACKAGE BODY? (schema_object_name '.')? package_name ';'
;
alter_package
: ALTER PACKAGE package_name COMPILE DEBUG? (PACKAGE | BODY | SPECIFICATION)? compiler_parameters_clause* (REUSE SETTINGS)? ';'
;
create_package
: CREATE (OR REPLACE)? PACKAGE (schema_object_name '.')? package_name invoker_rights_clause? (IS | AS) package_obj_spec* END package_name? ';'
;
create_package_body
: CREATE (OR REPLACE)? PACKAGE BODY (schema_object_name '.')? package_name (IS | AS) package_obj_body* (BEGIN seq_of_statements)? END package_name? ';'
;
// Create Package Specific Clauses
package_obj_spec
: pragma_declaration
| exception_declaration
| variable_declaration
| subtype_declaration
| cursor_declaration
| type_declaration
| procedure_spec
| function_spec
;
procedure_spec
: PROCEDURE identifier ('(' parameter ( ',' parameter )* ')')? ';'
;
function_spec
: FUNCTION identifier ('(' parameter ( ',' parameter)* ')')?
RETURN type_spec PIPELINED? DETERMINISTIC? (RESULT_CACHE)? ';'
;
package_obj_body
: exception_declaration
| subtype_declaration
| cursor_declaration
| variable_declaration
| type_declaration
| procedure_body
| function_body
| procedure_spec
| function_spec
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/alter-pmem-filestore.html
alter_pmem_filestore
: ALTER PMEM FILESTORE fsn=id_expression
( RESIZE size_clause
| autoextend_clause
| MOUNT (MOUNTPOINT file_path)? (BACKINGFILE filename)? FORCE? //inconsistent documentation
| DISMOUNT
)
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/drop-pmem-filestore.html
drop_pmem_filestore
: DROP PMEM FILESTORE fsn=id_expression
((FORCE? INCLUDING | EXCLUDING) CONTENTS)?
;
// Procedure DDLs
drop_procedure
: DROP PROCEDURE procedure_name ';'
;
alter_procedure
: ALTER PROCEDURE procedure_name COMPILE DEBUG? compiler_parameters_clause* (REUSE SETTINGS)? ';'
;
function_body
: FUNCTION identifier ('(' parameter (',' parameter)* ')')?
RETURN type_spec (invoker_rights_clause | parallel_enable_clause | result_cache_clause | DETERMINISTIC)*
((PIPELINED? DETERMINISTIC? (IS | AS) (DECLARE? seq_of_declare_specs? body | call_spec)) | (PIPELINED | AGGREGATE) USING implementation_type_name) ';'
;
procedure_body
: PROCEDURE identifier ('(' parameter (',' parameter)* ')')? (IS | AS)
(DECLARE? seq_of_declare_specs? body | call_spec | EXTERNAL) ';'
;
create_procedure_body
: CREATE (OR REPLACE)? PROCEDURE procedure_name ('(' parameter (',' parameter)* ')')?
invoker_rights_clause? (IS | AS)
(DECLARE? seq_of_declare_specs? body | call_spec | EXTERNAL) ';'
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/ALTER-RESOURCE-COST.html
alter_resource_cost
: ALTER RESOURCE COST ((CPU_PER_SESSION | CONNECT_TIME | LOGICAL_READS_PER_SESSION | PRIVATE_SGA) UNSIGNED_INTEGER)+
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/DROP-OUTLINE.html
drop_outline
: DROP OUTLINE o=id_expression
;
// Rollback Segment DDLs
//https://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_2011.htm#SQLRF00816
alter_rollback_segment
: ALTER ROLLBACK SEGMENT rollback_segment_name (ONLINE | OFFLINE | storage_clause | SHRINK (TO size_clause)?)
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-RESTORE-POINT.html
drop_restore_point
: DROP RESTORE POINT rp=id_expression (FOR PLUGGABLE DATABASE pdb=id_expression)?
;
drop_rollback_segment
: DROP ROLLBACK SEGMENT rollback_segment_name
;
drop_role
: DROP ROLE role_name ';'
;
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/create-pmem-filestore.html
create_pmem_filestore
: CREATE PMEM FILESTORE fsn=id_expression
pmem_filestore_options+
;
pmem_filestore_options
: MOUNTPOINT file_path
| BACKINGFILE filename REUSE?
| (SIZE | BLOCKSIZE) size_clause
| autoextend_clause
;
file_path
: CHAR_STRING
;
create_rollback_segment
: CREATE PUBLIC? ROLLBACK SEGMENT rollback_segment_name (TABLESPACE tablespace | storage_clause)*
;
// Trigger DDLs
drop_trigger
: DROP TRIGGER trigger_name ';'
;
alter_trigger
: ALTER TRIGGER alter_trigger_name=trigger_name
((ENABLE | DISABLE) | RENAME TO rename_trigger_name=trigger_name | COMPILE DEBUG? compiler_parameters_clause* (REUSE SETTINGS)?) ';'
;
create_trigger
: CREATE ( OR REPLACE )? TRIGGER trigger_name
(simple_dml_trigger | compound_dml_trigger | non_dml_trigger)
trigger_follows_clause? (ENABLE | DISABLE)? trigger_when_clause? trigger_body ';'
;
trigger_follows_clause
: FOLLOWS trigger_name (',' trigger_name)*
;
trigger_when_clause
: WHEN '(' condition ')'
;
// Create Trigger Specific Clauses
simple_dml_trigger
: (BEFORE | AFTER | INSTEAD OF) dml_event_clause referencing_clause? for_each_row?
;
for_each_row
: FOR EACH ROW
;
compound_dml_trigger
: FOR dml_event_clause referencing_clause?
;
non_dml_trigger
: (BEFORE | AFTER) non_dml_event (OR non_dml_event)* ON (DATABASE | (schema_name '.')? SCHEMA)
;
trigger_body
: COMPOUND TRIGGER
| CALL identifier
| trigger_block
;
routine_clause
: routine_name function_argument?
;
compound_trigger_block
: COMPOUND TRIGGER seq_of_declare_specs? timing_point_section+ END trigger_name
;
timing_point_section
: bk=BEFORE STATEMENT IS trigger_block BEFORE STATEMENT ';'
| bk=BEFORE EACH ROW IS trigger_block BEFORE EACH ROW ';'
| ak=AFTER STATEMENT IS trigger_block AFTER STATEMENT ';'
| ak=AFTER EACH ROW IS trigger_block AFTER EACH ROW ';'
;
non_dml_event
: ALTER
| ANALYZE
| ASSOCIATE STATISTICS
| AUDIT
| COMMENT
| CREATE
| DISASSOCIATE STATISTICS
| DROP
| GRANT
| NOAUDIT
| RENAME
| REVOKE
| TRUNCATE
| DDL
| STARTUP
| SHUTDOWN
| DB_ROLE_CHANGE
| LOGON
| LOGOFF
| SERVERERROR
| SUSPEND
| DATABASE
| SCHEMA
| FOLLOWS
;
dml_event_clause
: dml_event_element (OR dml_event_element)* ON dml_event_nested_clause? tableview_name
;
dml_event_element
: (DELETE | INSERT | UPDATE) (OF column_list)?
;
dml_event_nested_clause
: NESTED TABLE tableview_name OF
;
referencing_clause
: REFERENCING referencing_element+
;
referencing_element
: (NEW | OLD | PARENT) column_alias
;
// DDLs
drop_type
: DROP TYPE BODY? type_name (FORCE | VALIDATE)? ';'
;
alter_type
: ALTER TYPE type_name
(compile_type_clause
| replace_type_clause
//TODO | {input.LT(2).getText().equalsIgnoreCase("attribute")}? alter_attribute_definition
| alter_method_spec
| alter_collection_clauses
| modifier_clause
| overriding_subprogram_spec
) dependent_handling_clause? ';'
;
// Alter Type Specific Clauses
compile_type_clause
: COMPILE DEBUG? (SPECIFICATION | BODY)? compiler_parameters_clause* (REUSE SETTINGS)?
;
replace_type_clause
: REPLACE invoker_rights_clause? AS OBJECT '(' object_member_spec (',' object_member_spec)* ')'
;
alter_method_spec
: alter_method_element (',' alter_method_element)*
;
alter_method_element
: (ADD | DROP) (map_order_function_spec | subprogram_spec)
;
alter_attribute_definition
: (ADD | MODIFY | DROP) ATTRIBUTE (attribute_definition | '(' attribute_definition (',' attribute_definition)* ')')
;
attribute_definition
: attribute_name type_spec?
;
alter_collection_clauses
: MODIFY (LIMIT expression | ELEMENT TYPE type_spec)
;
dependent_handling_clause
: INVALIDATE
| CASCADE (CONVERT TO SUBSTITUTABLE | NOT? INCLUDING TABLE DATA)? dependent_exceptions_part?
;
dependent_exceptions_part
: FORCE? EXCEPTIONS INTO tableview_name
;
create_type
: CREATE (OR REPLACE)? TYPE (type_definition | type_body) ';'
;
// Create Type Specific Clauses
type_definition
: type_name (OID CHAR_STRING)? FORCE? object_type_def?
;
object_type_def
: invoker_rights_clause? (object_as_part | object_under_part) sqlj_object_type?
('(' object_member_spec (',' object_member_spec)* ')')? modifier_clause*
;
object_as_part
: (IS | AS) (OBJECT | varray_type_def | nested_table_type_def)
;
object_under_part
: UNDER type_spec
;
nested_table_type_def
: TABLE OF type_spec (NOT NULL_)?
;
sqlj_object_type
: EXTERNAL NAME expression LANGUAGE JAVA USING (SQLDATA | CUSTOMDATUM | ORADATA)
;
type_body
: BODY type_name (IS | AS) (type_body_elements)+ END
;
type_body_elements
: map_order_func_declaration
| subprog_decl_in_type
| overriding_subprogram_spec
;
map_order_func_declaration
: (MAP | ORDER) MEMBER func_decl_in_type
;
subprog_decl_in_type
: (MEMBER | STATIC) (proc_decl_in_type | func_decl_in_type | constructor_declaration)
;
proc_decl_in_type
: PROCEDURE procedure_name '(' type_elements_parameter (',' type_elements_parameter)* ')'
(IS | AS) (call_spec | DECLARE? seq_of_declare_specs? body ';')
;
func_decl_in_type
: FUNCTION function_name ('(' type_elements_parameter (',' type_elements_parameter)* ')')?
RETURN type_spec (IS | AS) (call_spec | DECLARE? seq_of_declare_specs? body ';')
;
constructor_declaration
: FINAL? INSTANTIABLE? CONSTRUCTOR FUNCTION type_spec
('(' (SELF IN OUT type_spec ',') type_elements_parameter (',' type_elements_parameter)* ')')?
RETURN SELF AS RESULT (IS | AS) (call_spec | DECLARE? seq_of_declare_specs? body ';')
;
// Common Type Clauses
modifier_clause
: NOT? (INSTANTIABLE | FINAL | OVERRIDING)
;
object_member_spec
: identifier type_spec sqlj_object_type_attr?
| element_spec
;
sqlj_object_type_attr
: EXTERNAL NAME expression
;
element_spec
: modifier_clause? element_spec_options+ (',' pragma_clause)?
;
element_spec_options
: subprogram_spec
| constructor_spec
| map_order_function_spec
;
subprogram_spec
: (MEMBER | STATIC) (type_procedure_spec | type_function_spec)
;