Skip to main content

sqruff_lib_dialects/
oracle.rs

1use sqruff_lib_core::dialects::Dialect;
2use sqruff_lib_core::dialects::init::DialectKind;
3use sqruff_lib_core::dialects::syntax::SyntaxKind;
4use sqruff_lib_core::helpers::{Config, ToMatchable};
5use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed};
6use sqruff_lib_core::parser::grammar::delimited::Delimited;
7use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence};
8use sqruff_lib_core::parser::grammar::{Nothing, Ref};
9use sqruff_lib_core::parser::lexer::Matcher;
10use sqruff_lib_core::parser::matchable::MatchableTrait;
11use sqruff_lib_core::parser::node_matcher::NodeMatcher;
12use sqruff_lib_core::parser::parsers::{RegexParser, StringParser};
13use sqruff_lib_core::parser::segments::generator::SegmentGenerator;
14use sqruff_lib_core::parser::segments::meta::MetaSegment;
15use sqruff_lib_core::parser::types::ParseMode;
16
17use super::ansi;
18use sqruff_lib_core::dialects::init::DialectConfig;
19use sqruff_lib_core::value::Value;
20
21sqruff_lib_core::dialect_config!(OracleDialectConfig {});
22
23pub fn dialect(config: Option<&Value>) -> Dialect {
24    let _dialect_config: OracleDialectConfig = config
25        .map(OracleDialectConfig::from_value)
26        .unwrap_or_default();
27
28    raw_dialect().config(|dialect| dialect.expand())
29}
30
31pub fn raw_dialect() -> Dialect {
32    let mut oracle = ansi::raw_dialect();
33    oracle.name = DialectKind::Oracle;
34
35    // ---- Keywords ----
36    oracle.sets_mut("reserved_keywords").extend([
37        "ACCESS",
38        "ADD",
39        "AUDIT",
40        "CLUSTER",
41        "COLUMN_VALUE",
42        "COMMENT",
43        "COMPRESS",
44        "CONNECT",
45        "CONNECT_BY_ROOT",
46        "DEFINITION",
47        "DELETING",
48        "DISABLE",
49        "ENABLE",
50        "EXCLUSIVE",
51        "EXECUTE",
52        "FILE",
53        "FORCE",
54        "IDENTIFIED",
55        "IMMEDIATE",
56        "INCREMENT",
57        "INDEXTYPE",
58        "INITIAL",
59        "INSERTING",
60        "INVISIBLE",
61        "LEVEL",
62        "LOCK",
63        "LOGGING",
64        "LONG",
65        "LOOP",
66        "MAXEXTENTS",
67        "MINUS",
68        "MLSLABEL",
69        "MODE",
70        "MODIFY",
71        "MONITORING",
72        "NESTED_TABLE_ID",
73        "NOAUDIT",
74        "NOCOMPRESS",
75        "NOLOGGING",
76        "NOMONITORING",
77        "NOREVERSE",
78        "NOWAIT",
79        "NUMBER",
80        "OFFLINE",
81        "ONLINE",
82        "OPTION",
83        "OVERFLOW",
84        "PARAMETERS",
85        "PCTFREE",
86        "PIVOT",
87        "PRIOR",
88        "PRIVATE",
89        "PROMPT",
90        "PUBLIC",
91        "RAW",
92        "REBUILD",
93        "RENAME",
94        "RESOURCE",
95        "REVERSE",
96        "ROWID",
97        "ROWNUM",
98        "SESSION",
99        "SHARE",
100        "SIBLINGS",
101        "SIZE",
102        "SMALLINT",
103        "START",
104        "SUCCESSFUL",
105        "SYNONYM",
106        "SYSDATE",
107        "UID",
108        "UNPIVOT",
109        "UNUSABLE",
110        "UPDATING",
111        "VALIDATE",
112        "VARCHAR2",
113        "VISIBLE",
114        "WHENEVER",
115    ]);
116
117    oracle.sets_mut("unreserved_keywords").extend([
118        "ABSENT",
119        "ACCESSIBLE",
120        "ACTIVE",
121        "ADMINISTER",
122        "ADVISE",
123        "ADVISOR",
124        "ANALYTIC",
125        "ARCHIVE",
126        "ARCHIVAL",
127        "AUTHENTICATED",
128        "AUTHID",
129        "BECOME",
130        "BODY",
131        "BULK",
132        "COMMITTED",
133        "CONSTRAINTS",
134        "BULK_EXCEPTIONS",
135        "BULK_ROWCOUNT",
136        "BYTE",
137        "COLLECT",
138        "COMPILE",
139        "COMPOUND",
140        "CONSTANT",
141        "CONTAINER",
142        "CONTEXT",
143        "CROSSEDITION",
144        "CURSOR",
145        "DBA_RECYCLEBIN",
146        "DBTIMEZONE",
147        "DDL",
148        "DEBUG",
149        "DEFERRED",
150        "DELEGATE",
151        "DIGEST",
152        "DIMENSION",
153        "DIRECTIVE",
154        "DIRECTORIES",
155        "DIRECTORY",
156        "DML",
157        "EDITION",
158        "EDITIONABLE",
159        "EDITIONING",
160        "EDITIONS",
161        "ELSIF",
162        "EMPTY",
163        "ERROR",
164        "ERRORS",
165        "EXEMPT",
166        "EXPIRE",
167        "EXTERNALLY",
168        "FINE",
169        "FLASHBACK",
170        "FOLLOWS",
171        "FORALL",
172        "GLOBALLY",
173        "GUARD",
174        "HIERARCHY",
175        "HTTP",
176        "INDICES",
177        "INHERITANY",
178        "ISOLATION_LEVEL",
179        "ISOPEN",
180        "JAVA",
181        "JOB",
182        "KEEP",
183        "LIBRARY",
184        "LINK",
185        "LOCKDOWN",
186        "LOG",
187        "LOGMINING",
188        "MEASURE",
189        "MINING",
190        "MUTABLE",
191        "NESTED",
192        "NEXTVAL",
193        "NOCOPY",
194        "NOMAXVALUE",
195        "NOMINVALUE",
196        "NONEDITIONABLE",
197        "NOTHING",
198        "NOTFOUND",
199        "OID",
200        "OUTLINE",
201        "PACKAGE",
202        "PAIRS",
203        "PARALLEL",
204        "PARALLEL_ENABLE",
205        "PARENT",
206        "PERSISTABLE",
207        "PIPELINED",
208        "PLUGGABLE",
209        "POLYMORPHIC",
210        "PRAGMA",
211        "PRECEDES",
212        "PRIVILEGE",
213        "PROFILE",
214        "PROGRAM",
215        "PROPERTY",
216        "QUERY",
217        "QUOTA",
218        "RAISE",
219        "RECORD",
220        "REDACTION",
221        "REDEFINE",
222        "REFRESH",
223        "REJECT",
224        "RELIES_ON",
225        "REMOTE",
226        "RESTRICTED",
227        "RESULT_CACHE",
228        "RESUMABLE",
229        "RETURNING",
230        "REUSE",
231        "REWRITE",
232        "ROWTYPE",
233        "SCHEDULER",
234        "SERIALIZABLE",
235        "SERVICE",
236        "SHARD",
237        "SHARD_ENABLE",
238        "SYNC",
239        "SHARED",
240        "SHARING",
241        "SIGN",
242        "SPECIFICATION",
243        "SQL_MACRO",
244        "SYSGUID",
245        "TIME_ZONE",
246        "TIMEOUT",
247        "UNLIMITED",
248        "VARRAY",
249        "VISIBILITY",
250    ]);
251
252    oracle.sets_mut("bare_functions").clear();
253    oracle.sets_mut("bare_functions").extend([
254        "COLUMN_VALUE",
255        "CURRENT_DATE",
256        "CURRENT_TIMESTAMP",
257        "DBTIMEZONE",
258        "LOCALTIMESTAMP",
259        "SESSIONTIMESTAMP",
260        "SYSDATE",
261        "SYSTIMESTAMP",
262    ]);
263
264    // ---- Lexer ----
265    // SQLFluff: RegexLexer("word", r"[\p{L}][\p{L}\p{N}_$#]*", WordSegment)
266    // sqruff doesn't support Unicode categories, so we use ASCII approximation
267    // SQLFluff: numeric_literal regex prevents 1. from consuming dot when followed by another dot
268    // This is critical for FOR i IN 1..5 LOOP syntax
269    oracle.patch_lexer_matchers(vec![
270        Matcher::regex("word", r"[a-zA-Z_][a-zA-Z0-9_$#]*", SyntaxKind::Word),
271        Matcher::legacy(
272            "numeric_literal",
273            |s| s.starts_with(|ch: char| ch.is_ascii_digit() || ch == '.'),
274            r"(?>\d+\.\d+|\d+\.(?![\.\w])|\d+)(\.?[eE][+-]?\d+)?((?<!\.)|(?=\b))",
275            SyntaxKind::NumericLiteral,
276        ),
277        Matcher::regex(
278            "single_quote",
279            r"'([^'\\]|\\|\\.|'')*'",
280            SyntaxKind::SingleQuote,
281        ),
282        Matcher::regex("double_quote", r#""([^"]|"")*""#, SyntaxKind::DoubleQuote),
283    ]);
284
285    oracle.insert_lexer_matchers(
286        vec![
287            Matcher::regex(
288                "prompt_command",
289                r"PROMPT[^\r\n]*",
290                SyntaxKind::InlineComment,
291            ),
292            Matcher::string("at_sign", "@", SyntaxKind::AtSign),
293        ],
294        "word",
295    );
296
297    oracle.insert_lexer_matchers(
298        vec![
299            Matcher::string("right_arrow", "=>", SyntaxKind::RightArrow),
300            Matcher::string(
301                "assignment_operator",
302                ":=",
303                SyntaxKind::OracleAssignmentOperator,
304            ),
305        ],
306        "equals",
307    );
308
309    oracle.insert_lexer_matchers(
310        vec![Matcher::string(
311            "power_operator",
312            "**",
313            SyntaxKind::OraclePowerOperator,
314        )],
315        "star",
316    );
317
318    // ---- NakedIdentifierSegment override ----
319    // SQLFluff: r"[\p{L}\p{N}_]*[\p{L}][\p{L}\p{N}_#$]*" with reserved keywords anti_template
320    // Allows # and $ in identifiers for Oracle
321    use itertools::Itertools;
322    oracle.add([(
323        "NakedIdentifierSegment".into(),
324        SegmentGenerator::new(|dialect| {
325            let reserved_keywords = dialect.sets("reserved_keywords");
326            let pattern = reserved_keywords.iter().join("|");
327            let anti_template = format!("^({pattern})$");
328
329            RegexParser::new(r"[A-Z0-9_]*[A-Z][A-Z0-9_#$]*", SyntaxKind::NakedIdentifier)
330                .anti_template(&anti_template)
331                .to_matchable()
332        })
333        .into(),
334    )]);
335
336    // ---- Grammar additions ----
337    oracle.add([
338        // AtSignSegment
339        (
340            "AtSignSegment".into(),
341            StringParser::new("@", SyntaxKind::AtSign)
342                .to_matchable()
343                .into(),
344        ),
345        // RightArrowSegment
346        (
347            "RightArrowSegment".into(),
348            StringParser::new("=>", SyntaxKind::RightArrow)
349                .to_matchable()
350                .into(),
351        ),
352        // AssignmentOperatorSegment
353        (
354            "AssignmentOperatorSegment".into(),
355            StringParser::new(":=", SyntaxKind::OracleAssignmentOperator)
356                .to_matchable()
357                .into(),
358        ),
359        // PowerOperatorSegment
360        (
361            "PowerOperatorSegment".into(),
362            StringParser::new("**", SyntaxKind::BinaryOperator)
363                .to_matchable()
364                .into(),
365        ),
366        // ModOperatorSegment
367        (
368            "ModOperatorSegment".into(),
369            StringParser::new("MOD", SyntaxKind::BinaryOperator)
370                .to_matchable()
371                .into(),
372        ),
373        // SequenceNextValGrammar
374        (
375            "SequenceNextValGrammar".into(),
376            Sequence::new(vec![
377                Ref::new("NakedIdentifierSegment").to_matchable(),
378                Ref::new("DotSegment").to_matchable(),
379                Ref::keyword("NEXTVAL").to_matchable(),
380            ])
381            .config(|config| {
382                config.allow_gaps = false;
383            })
384            .to_matchable()
385            .into(),
386        ),
387        // OnCommitGrammar
388        (
389            "OnCommitGrammar".into(),
390            Sequence::new(vec![
391                Ref::keyword("ON").to_matchable(),
392                Ref::keyword("COMMIT").to_matchable(),
393                one_of(vec![
394                    Sequence::new(vec![
395                        one_of(vec![
396                            Ref::keyword("DROP").to_matchable(),
397                            Ref::keyword("PRESERVE").to_matchable(),
398                        ])
399                        .to_matchable(),
400                        Ref::keyword("DEFINITION").to_matchable(),
401                    ])
402                    .to_matchable(),
403                    Sequence::new(vec![
404                        one_of(vec![
405                            Ref::keyword("DELETE").to_matchable(),
406                            Ref::keyword("PRESERVE").to_matchable(),
407                        ])
408                        .to_matchable(),
409                        Ref::keyword("ROWS").to_matchable(),
410                    ])
411                    .to_matchable(),
412                ])
413                .to_matchable(),
414            ])
415            .to_matchable()
416            .into(),
417        ),
418        // ConnectByRootGrammar
419        (
420            "ConnectByRootGrammar".into(),
421            Sequence::new(vec![
422                Ref::keyword("CONNECT_BY_ROOT").to_matchable(),
423                Ref::new("NakedIdentifierSegment").to_matchable(),
424            ])
425            .to_matchable()
426            .into(),
427        ),
428        // IntervalUnitsGrammar
429        (
430            "IntervalUnitsGrammar".into(),
431            one_of(vec![
432                Ref::keyword("YEAR").to_matchable(),
433                Ref::keyword("MONTH").to_matchable(),
434                Ref::keyword("DAY").to_matchable(),
435                Ref::keyword("HOUR").to_matchable(),
436                Ref::keyword("MINUTE").to_matchable(),
437                Ref::keyword("SECOND").to_matchable(),
438            ])
439            .to_matchable()
440            .into(),
441        ),
442        // PivotForInGrammar
443        (
444            "PivotForInGrammar".into(),
445            Sequence::new(vec![
446                Ref::keyword("FOR").to_matchable(),
447                optionally_bracketed(vec![
448                    Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
449                        .to_matchable(),
450                ])
451                .to_matchable(),
452                Ref::keyword("IN").to_matchable(),
453                Bracketed::new(vec![
454                    Delimited::new(vec![
455                        Sequence::new(vec![
456                            Ref::new("Expression_D_Grammar").to_matchable(),
457                            Ref::new("AliasExpressionSegment").optional().to_matchable(),
458                        ])
459                        .to_matchable(),
460                    ])
461                    .to_matchable(),
462                ])
463                .to_matchable(),
464            ])
465            .to_matchable()
466            .into(),
467        ),
468        // UnpivotNullsGrammar
469        (
470            "UnpivotNullsGrammar".into(),
471            Sequence::new(vec![
472                one_of(vec![
473                    Ref::keyword("INCLUDE").to_matchable(),
474                    Ref::keyword("EXCLUDE").to_matchable(),
475                ])
476                .to_matchable(),
477                Ref::keyword("NULLS").to_matchable(),
478            ])
479            .to_matchable()
480            .into(),
481        ),
482        // StatementAndDelimiterGrammar
483        (
484            "StatementAndDelimiterGrammar".into(),
485            Sequence::new(vec![
486                Ref::new("StatementSegment").to_matchable(),
487                Ref::new("DelimiterGrammar").optional().to_matchable(),
488            ])
489            .to_matchable()
490            .into(),
491        ),
492        // OneOrMoreStatementsGrammar
493        (
494            "OneOrMoreStatementsGrammar".into(),
495            AnyNumberOf::new(vec![
496                Ref::new("StatementAndDelimiterGrammar").to_matchable(),
497            ])
498            .config(|config| {
499                config.min_times = 1;
500            })
501            .to_matchable()
502            .into(),
503        ),
504        // TimingPointGrammar
505        (
506            "TimingPointGrammar".into(),
507            Sequence::new(vec![
508                one_of(vec![
509                    Ref::keyword("BEFORE").to_matchable(),
510                    Ref::keyword("AFTER").to_matchable(),
511                    Sequence::new(vec![
512                        Ref::keyword("INSTEAD").to_matchable(),
513                        Ref::keyword("OF").to_matchable(),
514                    ])
515                    .to_matchable(),
516                ])
517                .to_matchable(),
518                one_of(vec![
519                    Ref::keyword("STATEMENT").to_matchable(),
520                    Sequence::new(vec![
521                        Ref::keyword("EACH").to_matchable(),
522                        Ref::keyword("ROW").to_matchable(),
523                    ])
524                    .to_matchable(),
525                ])
526                .to_matchable(),
527            ])
528            .to_matchable()
529            .into(),
530        ),
531        // SharingClauseGrammar
532        (
533            "SharingClauseGrammar".into(),
534            Sequence::new(vec![
535                Ref::keyword("SHARING").to_matchable(),
536                one_of(vec![
537                    Ref::keyword("METADATA").to_matchable(),
538                    Ref::keyword("NONE").to_matchable(),
539                ])
540                .to_matchable(),
541            ])
542            .config(|config| {
543                config.optional();
544            })
545            .to_matchable()
546            .into(),
547        ),
548        // DefaultCollationClauseGrammar
549        (
550            "DefaultCollationClauseGrammar".into(),
551            Sequence::new(vec![
552                Ref::keyword("DEFAULT").to_matchable(),
553                Ref::keyword("COLLATION").to_matchable(),
554                Ref::new("NakedIdentifierSegment").to_matchable(),
555            ])
556            .config(|config| {
557                config.optional();
558            })
559            .to_matchable()
560            .into(),
561        ),
562        // InvokerRightsClauseGrammar
563        (
564            "InvokerRightsClauseGrammar".into(),
565            Sequence::new(vec![
566                Ref::keyword("AUTHID").to_matchable(),
567                one_of(vec![
568                    Ref::keyword("CURRENT_USER").to_matchable(),
569                    Ref::keyword("DEFINER").to_matchable(),
570                ])
571                .to_matchable(),
572            ])
573            .to_matchable()
574            .into(),
575        ),
576        // AccessibleByClauseGrammar
577        (
578            "AccessibleByClauseGrammar".into(),
579            Sequence::new(vec![
580                Ref::keyword("ACCESSIBLE").to_matchable(),
581                Ref::keyword("BY").to_matchable(),
582                Delimited::new(vec![
583                    Bracketed::new(vec![
584                        Sequence::new(vec![
585                            one_of(vec![
586                                Ref::keyword("FUNCTION").to_matchable(),
587                                Ref::keyword("PROCEDURE").to_matchable(),
588                                Ref::keyword("PACKAGE").to_matchable(),
589                                Ref::keyword("TRIGGER").to_matchable(),
590                                Ref::keyword("TYPE").to_matchable(),
591                            ])
592                            .config(|config| {
593                                config.optional();
594                            })
595                            .to_matchable(),
596                            Ref::new("FunctionNameSegment").to_matchable(),
597                        ])
598                        .to_matchable(),
599                    ])
600                    .to_matchable(),
601                ])
602                .to_matchable(),
603            ])
604            .to_matchable()
605            .into(),
606        ),
607        // DmlGrammar
608        (
609            "DmlGrammar".into(),
610            one_of(vec![
611                Ref::keyword("DELETE").to_matchable(),
612                Ref::keyword("INSERT").to_matchable(),
613                Sequence::new(vec![
614                    Ref::keyword("UPDATE").to_matchable(),
615                    Sequence::new(vec![
616                        Ref::keyword("OF").to_matchable(),
617                        Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
618                            .to_matchable(),
619                    ])
620                    .config(|config| {
621                        config.optional();
622                    })
623                    .to_matchable(),
624                ])
625                .to_matchable(),
626            ])
627            .to_matchable()
628            .into(),
629        ),
630        // IterationBoundsGrammar
631        (
632            "IterationBoundsGrammar".into(),
633            one_of(vec![
634                Ref::new("NumericLiteralSegment").to_matchable(),
635                Ref::new("SingleIdentifierGrammar").to_matchable(),
636                Sequence::new(vec![
637                    Ref::new("SingleIdentifierGrammar").to_matchable(),
638                    Ref::new("DotSegment").to_matchable(),
639                    Ref::new("SingleIdentifierGrammar").to_matchable(),
640                ])
641                .to_matchable(),
642            ])
643            .to_matchable()
644            .into(),
645        ),
646        // IterationSteppedControlGrammar
647        (
648            "IterationSteppedControlGrammar".into(),
649            Sequence::new(vec![
650                Ref::new("IterationBoundsGrammar").to_matchable(),
651                Ref::new("DotSegment").to_matchable(),
652                Ref::new("DotSegment").to_matchable(),
653                Ref::new("IterationBoundsGrammar").to_matchable(),
654                Sequence::new(vec![
655                    Ref::keyword("BY").to_matchable(),
656                    Ref::keyword("STEP").to_matchable(),
657                ])
658                .config(|config| {
659                    config.optional();
660                })
661                .to_matchable(),
662            ])
663            .to_matchable()
664            .into(),
665        ),
666        // ParallelEnableClauseGrammar
667        (
668            "ParallelEnableClauseGrammar".into(),
669            Sequence::new(vec![
670                Ref::keyword("PARALLEL_ENABLE").to_matchable(),
671                Bracketed::new(vec![
672                    Ref::keyword("PARTITION").to_matchable(),
673                    Ref::new("SingleIdentifierGrammar").to_matchable(),
674                    Ref::keyword("BY").to_matchable(),
675                    one_of(vec![
676                        Ref::keyword("ANY").to_matchable(),
677                        Sequence::new(vec![
678                            one_of(vec![
679                                Ref::keyword("HASH").to_matchable(),
680                                Ref::keyword("RANGE").to_matchable(),
681                            ])
682                            .to_matchable(),
683                            Bracketed::new(vec![
684                                Delimited::new(vec![
685                                    Ref::new("ColumnReferenceSegment").to_matchable(),
686                                ])
687                                .to_matchable(),
688                            ])
689                            .to_matchable(),
690                        ])
691                        .to_matchable(),
692                        Sequence::new(vec![
693                            Ref::keyword("VALUE").to_matchable(),
694                            Bracketed::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
695                                .to_matchable(),
696                        ])
697                        .to_matchable(),
698                    ])
699                    .to_matchable(),
700                ])
701                .config(|config| {
702                    config.optional();
703                })
704                .to_matchable(),
705            ])
706            .to_matchable()
707            .into(),
708        ),
709        // ResultCacheClauseGrammar
710        (
711            "ResultCacheClauseGrammar".into(),
712            Sequence::new(vec![
713                Ref::keyword("RESULT_CACHE").to_matchable(),
714                Sequence::new(vec![
715                    Ref::keyword("RELIES_ON").to_matchable(),
716                    Bracketed::new(vec![
717                        Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
718                            .to_matchable(),
719                    ])
720                    .to_matchable(),
721                ])
722                .config(|config| {
723                    config.optional();
724                })
725                .to_matchable(),
726            ])
727            .to_matchable()
728            .into(),
729        ),
730        // PipelinedClauseGrammar
731        (
732            "PipelinedClauseGrammar".into(),
733            Sequence::new(vec![
734                Ref::keyword("PIPELINED").to_matchable(),
735                one_of(vec![
736                    Sequence::new(vec![
737                        Ref::keyword("USING").to_matchable(),
738                        Ref::new("ObjectReferenceSegment").to_matchable(),
739                    ])
740                    .config(|config| {
741                        config.optional();
742                    })
743                    .to_matchable(),
744                    Sequence::new(vec![
745                        one_of(vec![
746                            Ref::keyword("ROW").to_matchable(),
747                            Ref::keyword("TABLE").to_matchable(),
748                        ])
749                        .to_matchable(),
750                        Ref::keyword("POLYMORPHIC").to_matchable(),
751                        Sequence::new(vec![
752                            Ref::keyword("USING").to_matchable(),
753                            Ref::new("ObjectReferenceSegment").to_matchable(),
754                        ])
755                        .config(|config| {
756                            config.optional();
757                        })
758                        .to_matchable(),
759                    ])
760                    .to_matchable(),
761                ])
762                .to_matchable(),
763            ])
764            .to_matchable()
765            .into(),
766        ),
767        // CompileClauseGrammar
768        (
769            "CompileClauseGrammar".into(),
770            Sequence::new(vec![
771                Ref::keyword("COMPILE").to_matchable(),
772                Ref::keyword("DEBUG").optional().to_matchable(),
773                one_of(vec![
774                    Ref::keyword("PACKAGE").to_matchable(),
775                    Ref::keyword("SPECIFICATION").to_matchable(),
776                    Ref::keyword("BODY").to_matchable(),
777                ])
778                .config(|config| {
779                    config.optional();
780                })
781                .to_matchable(),
782                Sequence::new(vec![
783                    Ref::keyword("REUSE").to_matchable(),
784                    Ref::keyword("SETTINGS").to_matchable(),
785                ])
786                .config(|config| {
787                    config.optional();
788                })
789                .to_matchable(),
790            ])
791            .to_matchable()
792            .into(),
793        ),
794        // IdentityClauseGrammar
795        (
796            "IdentityClauseGrammar".into(),
797            Sequence::new(vec![
798                Ref::keyword("GENERATED").to_matchable(),
799                one_of(vec![
800                    Ref::keyword("ALWAYS").to_matchable(),
801                    Sequence::new(vec![
802                        Ref::keyword("BY").to_matchable(),
803                        Ref::keyword("DEFAULT").to_matchable(),
804                        Sequence::new(vec![
805                            Ref::keyword("ON").to_matchable(),
806                            Ref::keyword("NULL").to_matchable(),
807                        ])
808                        .config(|config| {
809                            config.optional();
810                        })
811                        .to_matchable(),
812                    ])
813                    .to_matchable(),
814                ])
815                .config(|config| {
816                    config.optional();
817                })
818                .to_matchable(),
819                Ref::keyword("AS").to_matchable(),
820                Ref::keyword("IDENTITY").to_matchable(),
821                Bracketed::new(vec![Ref::new("IdentityOptionsGrammar").to_matchable()])
822                    .config(|config| {
823                        config.optional();
824                    })
825                    .to_matchable(),
826            ])
827            .to_matchable()
828            .into(),
829        ),
830        // IdentityOptionsGrammar
831        (
832            "IdentityOptionsGrammar".into(),
833            AnyNumberOf::new(vec![
834                Sequence::new(vec![
835                    one_of(vec![
836                        Sequence::new(vec![
837                            Ref::keyword("START").to_matchable(),
838                            Ref::keyword("WITH").to_matchable(),
839                        ])
840                        .to_matchable(),
841                        Sequence::new(vec![
842                            Ref::keyword("INCREMENT").to_matchable(),
843                            Ref::keyword("BY").to_matchable(),
844                        ])
845                        .to_matchable(),
846                        Ref::keyword("MAXVALUE").to_matchable(),
847                        Ref::keyword("MINVALUE").to_matchable(),
848                        Ref::keyword("CACHE").to_matchable(),
849                    ])
850                    .to_matchable(),
851                    Ref::new("NumericLiteralSegment").to_matchable(),
852                ])
853                .to_matchable(),
854                Ref::keyword("NOMAXVALUE").to_matchable(),
855                Ref::keyword("NOMINVALUE").to_matchable(),
856                Ref::keyword("CYCLE").to_matchable(),
857                Ref::keyword("NOCYCLE").to_matchable(),
858                Ref::keyword("NOCACHE").to_matchable(),
859                Ref::keyword("ORDER").to_matchable(),
860                Ref::keyword("NOORDER").to_matchable(),
861            ])
862            .to_matchable()
863            .into(),
864        ),
865        // TriggerPredicatesGrammar
866        (
867            "TriggerPredicatesGrammar".into(),
868            one_of(vec![
869                Ref::keyword("INSERTING").to_matchable(),
870                Sequence::new(vec![
871                    Ref::keyword("UPDATING").to_matchable(),
872                    Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()])
873                        .config(|config| {
874                            config.optional();
875                        })
876                        .to_matchable(),
877                ])
878                .to_matchable(),
879                Ref::keyword("DELETING").to_matchable(),
880            ])
881            .to_matchable()
882            .into(),
883        ),
884        // ForUpdateGrammar
885        (
886            "ForUpdateGrammar".into(),
887            Sequence::new(vec![
888                Ref::keyword("FOR").to_matchable(),
889                Ref::keyword("UPDATE").to_matchable(),
890                Sequence::new(vec![
891                    Ref::keyword("OF").to_matchable(),
892                    Ref::new("TableReferenceSegment").to_matchable(),
893                ])
894                .config(|config| {
895                    config.optional();
896                })
897                .to_matchable(),
898            ])
899            .to_matchable()
900            .into(),
901        ),
902        // ImplicitCursorAttributesGrammar
903        (
904            "ImplicitCursorAttributesGrammar".into(),
905            Sequence::new(vec![
906                Ref::new("SingleIdentifierGrammar").to_matchable(),
907                Ref::new("ModuloSegment").to_matchable(),
908                one_of(vec![
909                    Ref::keyword("ISOPEN").to_matchable(),
910                    Ref::keyword("FOUND").to_matchable(),
911                    Ref::keyword("NOTFOUND").to_matchable(),
912                    Ref::keyword("ROWCOUNT").to_matchable(),
913                    Ref::keyword("BULK_ROWCOUNT").to_matchable(),
914                    Ref::keyword("BULK_EXCEPTIONS").to_matchable(),
915                ])
916                .to_matchable(),
917            ])
918            .to_matchable()
919            .into(),
920        ),
921        // BatchDelimiterGrammar
922        (
923            "BatchDelimiterGrammar".into(),
924            Ref::new("SlashBufferExecutorSegment").to_matchable().into(),
925        ),
926        // ElementSpecificationGrammar
927        (
928            "ElementSpecificationGrammar".into(),
929            Sequence::new(vec![
930                AnyNumberOf::new(vec![
931                    Sequence::new(vec![
932                        Ref::keyword("NOT").to_matchable(),
933                        one_of(vec![
934                            Ref::keyword("OVERRIDING").to_matchable(),
935                            Ref::keyword("FINAL").to_matchable(),
936                            Ref::keyword("INSTANTIABLE").to_matchable(),
937                        ])
938                        .to_matchable(),
939                    ])
940                    .to_matchable(),
941                ])
942                .config(|config| {
943                    config.optional();
944                })
945                .to_matchable(),
946                AnyNumberOf::new(vec![
947                    Sequence::new(vec![
948                        one_of(vec![
949                            Ref::keyword("MEMBER").to_matchable(),
950                            Ref::keyword("STATIC").to_matchable(),
951                        ])
952                        .to_matchable(),
953                        one_of(vec![
954                            Ref::new("CreateFunctionStatementSegment").to_matchable(),
955                            Ref::new("CreateProcedureStatementSegment").to_matchable(),
956                        ])
957                        .to_matchable(),
958                    ])
959                    .to_matchable(),
960                ])
961                .to_matchable(),
962            ])
963            .to_matchable()
964            .into(),
965        ),
966        // ObjectTypeAndSubtypeDefGrammar
967        (
968            "ObjectTypeAndSubtypeDefGrammar".into(),
969            Sequence::new(vec![
970                one_of(vec![
971                    Ref::keyword("OBJECT").to_matchable(),
972                    Sequence::new(vec![
973                        Ref::keyword("UNDER").to_matchable(),
974                        Ref::new("ObjectReferenceSegment").to_matchable(),
975                    ])
976                    .to_matchable(),
977                ])
978                .to_matchable(),
979                Bracketed::new(vec![
980                    Delimited::new(vec![
981                        one_of(vec![
982                            Sequence::new(vec![
983                                Ref::new("SingleIdentifierGrammar").to_matchable(),
984                                Ref::new("DatatypeSegment").to_matchable(),
985                            ])
986                            .to_matchable(),
987                            Ref::new("ElementSpecificationGrammar").to_matchable(),
988                        ])
989                        .to_matchable(),
990                    ])
991                    .to_matchable(),
992                ])
993                .config(|config| {
994                    config.optional();
995                })
996                .to_matchable(),
997                AnyNumberOf::new(vec![
998                    Sequence::new(vec![
999                        Ref::keyword("NOT").optional().to_matchable(),
1000                        one_of(vec![
1001                            Ref::keyword("FINAL").to_matchable(),
1002                            Ref::keyword("INSTANTIABLE").to_matchable(),
1003                            Ref::keyword("PERSISTABLE").to_matchable(),
1004                        ])
1005                        .to_matchable(),
1006                    ])
1007                    .to_matchable(),
1008                ])
1009                .config(|config| {
1010                    config.optional();
1011                })
1012                .to_matchable(),
1013            ])
1014            .to_matchable()
1015            .into(),
1016        ),
1017        // VarrayAndNestedTypeSpecGrammar
1018        (
1019            "VarrayAndNestedTypeSpecGrammar".into(),
1020            Sequence::new(vec![
1021                one_of(vec![
1022                    Sequence::new(vec![
1023                        one_of(vec![
1024                            Ref::keyword("VARRAY").to_matchable(),
1025                            Sequence::new(vec![
1026                                Ref::keyword("VARYING").optional().to_matchable(),
1027                                Ref::keyword("ARRAY").to_matchable(),
1028                            ])
1029                            .to_matchable(),
1030                        ])
1031                        .to_matchable(),
1032                        Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
1033                            .to_matchable(),
1034                    ])
1035                    .to_matchable(),
1036                    Ref::keyword("TABLE").to_matchable(),
1037                ])
1038                .to_matchable(),
1039                Ref::keyword("OF").to_matchable(),
1040                Ref::new("DatatypeSegment").to_matchable(),
1041                Sequence::new(vec![
1042                    Ref::keyword("NOT").to_matchable(),
1043                    Ref::keyword("NULL").to_matchable(),
1044                ])
1045                .config(|config| {
1046                    config.optional();
1047                })
1048                .to_matchable(),
1049            ])
1050            .to_matchable()
1051            .into(),
1052        ),
1053        // DBLinkAuthenticationGrammar
1054        (
1055            "DBLinkAuthenticationGrammar".into(),
1056            one_of(vec![
1057                Sequence::new(vec![
1058                    Ref::keyword("AUTHENTICATED").to_matchable(),
1059                    Ref::keyword("BY").to_matchable(),
1060                    Ref::new("RoleReferenceSegment").to_matchable(),
1061                    Ref::keyword("IDENTIFIED").to_matchable(),
1062                    Ref::keyword("BY").to_matchable(),
1063                    Ref::new("SingleIdentifierGrammar").to_matchable(),
1064                ])
1065                .to_matchable(),
1066                Sequence::new(vec![
1067                    Ref::keyword("WITH").to_matchable(),
1068                    Ref::keyword("CREDENTIAL").to_matchable(),
1069                ])
1070                .to_matchable(),
1071            ])
1072            .to_matchable()
1073            .into(),
1074        ),
1075    ]);
1076
1077    // ---- New Segments ----
1078    oracle.add([
1079        // TriggerCorrelationNameSegment
1080        (
1081            "TriggerCorrelationNameSegment".into(),
1082            NodeMatcher::new(SyntaxKind::TriggerCorrelationName, |_| {
1083                one_of(vec![
1084                    Ref::keyword("OLD").to_matchable(),
1085                    Ref::keyword("NEW").to_matchable(),
1086                    Ref::keyword("PARENT").to_matchable(),
1087                ])
1088                .to_matchable()
1089            })
1090            .to_matchable()
1091            .into(),
1092        ),
1093        // TriggerCorrelationReferenceSegment
1094        (
1095            "TriggerCorrelationReferenceSegment".into(),
1096            NodeMatcher::new(SyntaxKind::OracleBindVariable, |_| {
1097                Sequence::new(vec![
1098                    Ref::new("ColonDelimiterSegment").to_matchable(),
1099                    Ref::new("TriggerCorrelationNameSegment").to_matchable(),
1100                    Sequence::new(vec![
1101                        Ref::new("DotSegment").to_matchable(),
1102                        Ref::new("SingleIdentifierGrammar").to_matchable(),
1103                    ])
1104                    .config(|config| {
1105                        config.optional();
1106                    })
1107                    .to_matchable(),
1108                ])
1109                .config(|config| {
1110                    config.allow_gaps = false;
1111                })
1112                .to_matchable()
1113            })
1114            .to_matchable()
1115            .into(),
1116        ),
1117        // SqlplusVariableGrammar
1118        (
1119            "SqlplusVariableGrammar".into(),
1120            NodeMatcher::new(SyntaxKind::OracleSqlplusVariable, |_| {
1121                optionally_bracketed(vec![
1122                    Ref::new("ColonSegment").to_matchable(),
1123                    Ref::new("ParameterNameSegment").to_matchable(),
1124                    Sequence::new(vec![
1125                        Ref::new("DotSegment").to_matchable(),
1126                        Ref::new("ParameterNameSegment").to_matchable(),
1127                    ])
1128                    .config(|config| {
1129                        config.optional();
1130                    })
1131                    .to_matchable(),
1132                ])
1133                .to_matchable()
1134            })
1135            .to_matchable()
1136            .into(),
1137        ),
1138        // SqlplusSubstitutionVariableSegment
1139        (
1140            "SqlplusSubstitutionVariableSegment".into(),
1141            NodeMatcher::new(SyntaxKind::OracleSqlplusVariable, |_| {
1142                Sequence::new(vec![
1143                    Ref::new("AmpersandSegment").to_matchable(),
1144                    Ref::new("AmpersandSegment").optional().to_matchable(),
1145                    Ref::new("SingleIdentifierGrammar").to_matchable(),
1146                ])
1147                .to_matchable()
1148            })
1149            .to_matchable()
1150            .into(),
1151        ),
1152        // SlashBufferExecutorSegment
1153        (
1154            "SlashBufferExecutorSegment".into(),
1155            NodeMatcher::new(SyntaxKind::SlashBufferExecutor, |_| {
1156                Ref::new("SlashSegment").to_matchable()
1157            })
1158            .to_matchable()
1159            .into(),
1160        ),
1161        // ConnectByClauseSegment
1162        (
1163            "ConnectByClauseSegment".into(),
1164            NodeMatcher::new(SyntaxKind::ConnectbyClause, |_| {
1165                Sequence::new(vec![
1166                    Ref::keyword("CONNECT").to_matchable(),
1167                    Ref::keyword("BY").to_matchable(),
1168                    Ref::keyword("NOCYCLE").optional().to_matchable(),
1169                    Ref::new("ExpressionSegment").to_matchable(),
1170                ])
1171                .to_matchable()
1172            })
1173            .to_matchable()
1174            .into(),
1175        ),
1176        // StartWithClauseSegment
1177        (
1178            "StartWithClauseSegment".into(),
1179            NodeMatcher::new(SyntaxKind::StartwithClause, |_| {
1180                Sequence::new(vec![
1181                    Ref::keyword("START").to_matchable(),
1182                    Ref::keyword("WITH").to_matchable(),
1183                    Ref::new("ExpressionSegment").to_matchable(),
1184                ])
1185                .to_matchable()
1186            })
1187            .to_matchable()
1188            .into(),
1189        ),
1190        // HierarchicalQueryClauseSegment
1191        (
1192            "HierarchicalQueryClauseSegment".into(),
1193            NodeMatcher::new(SyntaxKind::HierarchicalQueryClause, |_| {
1194                one_of(vec![
1195                    Sequence::new(vec![
1196                        Ref::new("ConnectByClauseSegment").to_matchable(),
1197                        Ref::new("StartWithClauseSegment").optional().to_matchable(),
1198                    ])
1199                    .to_matchable(),
1200                    Sequence::new(vec![
1201                        Ref::new("StartWithClauseSegment").to_matchable(),
1202                        Ref::new("ConnectByClauseSegment").to_matchable(),
1203                    ])
1204                    .to_matchable(),
1205                ])
1206                .to_matchable()
1207            })
1208            .to_matchable()
1209            .into(),
1210        ),
1211        // PivotSegment
1212        (
1213            "PivotSegment".into(),
1214            NodeMatcher::new(SyntaxKind::PivotSegment, |_| {
1215                Sequence::new(vec![
1216                    Ref::keyword("PIVOT").to_matchable(),
1217                    Ref::keyword("XML").optional().to_matchable(),
1218                    Bracketed::new(vec![
1219                        Delimited::new(vec![
1220                            Sequence::new(vec![
1221                                Ref::new("FunctionSegment").to_matchable(),
1222                                Ref::new("AliasExpressionSegment").optional().to_matchable(),
1223                            ])
1224                            .to_matchable(),
1225                        ])
1226                        .to_matchable(),
1227                        Ref::new("PivotForInGrammar").to_matchable(),
1228                    ])
1229                    .to_matchable(),
1230                ])
1231                .to_matchable()
1232            })
1233            .to_matchable()
1234            .into(),
1235        ),
1236        // UnpivotSegment
1237        (
1238            "UnpivotSegment".into(),
1239            NodeMatcher::new(SyntaxKind::UnpivotSegment, |_| {
1240                Sequence::new(vec![
1241                    Ref::keyword("UNPIVOT").to_matchable(),
1242                    Ref::new("UnpivotNullsGrammar").optional().to_matchable(),
1243                    Bracketed::new(vec![
1244                        optionally_bracketed(vec![
1245                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
1246                                .to_matchable(),
1247                        ])
1248                        .to_matchable(),
1249                        Ref::new("PivotForInGrammar").to_matchable(),
1250                    ])
1251                    .to_matchable(),
1252                ])
1253                .to_matchable()
1254            })
1255            .to_matchable()
1256            .into(),
1257        ),
1258        // WithinGroupClauseSegment
1259        (
1260            "WithinGroupClauseSegment".into(),
1261            NodeMatcher::new(SyntaxKind::OracleWithinGroupClause, |_| {
1262                Sequence::new(vec![
1263                    Ref::keyword("WITHIN").to_matchable(),
1264                    Ref::keyword("GROUP").to_matchable(),
1265                    Bracketed::new(vec![Ref::new("OrderByClauseSegment").to_matchable()])
1266                        .to_matchable(),
1267                ])
1268                .to_matchable()
1269            })
1270            .to_matchable()
1271            .into(),
1272        ),
1273        // ListaggOverflowClauseSegment
1274        (
1275            "ListaggOverflowClauseSegment".into(),
1276            NodeMatcher::new(SyntaxKind::OracleListaggOverflowClause, |_| {
1277                Sequence::new(vec![
1278                    Ref::keyword("ON").to_matchable(),
1279                    Ref::keyword("OVERFLOW").to_matchable(),
1280                    one_of(vec![
1281                        Ref::keyword("ERROR").to_matchable(),
1282                        Sequence::new(vec![
1283                            Ref::keyword("TRUNCATE").to_matchable(),
1284                            Ref::new("SingleQuotedIdentifierSegment")
1285                                .optional()
1286                                .to_matchable(),
1287                            one_of(vec![
1288                                Ref::keyword("WITH").to_matchable(),
1289                                Ref::keyword("WITHOUT").to_matchable(),
1290                            ])
1291                            .config(|config| {
1292                                config.optional();
1293                            })
1294                            .to_matchable(),
1295                            Ref::keyword("COUNT").optional().to_matchable(),
1296                        ])
1297                        .to_matchable(),
1298                    ])
1299                    .to_matchable(),
1300                ])
1301                .to_matchable()
1302            })
1303            .to_matchable()
1304            .into(),
1305        ),
1306        // NamedArgumentSegment
1307        (
1308            "NamedArgumentSegment".into(),
1309            NodeMatcher::new(SyntaxKind::OracleNamedArgument, |_| {
1310                Sequence::new(vec![
1311                    Ref::new("NakedIdentifierSegment").to_matchable(),
1312                    Ref::new("RightArrowSegment").to_matchable(),
1313                    Ref::new("ExpressionSegment").to_matchable(),
1314                ])
1315                .to_matchable()
1316            })
1317            .to_matchable()
1318            .into(),
1319        ),
1320        // CommentStatementSegment
1321        (
1322            "CommentStatementSegment".into(),
1323            NodeMatcher::new(SyntaxKind::OracleCommentStatement, |_| {
1324                Sequence::new(vec![
1325                    Ref::keyword("COMMENT").to_matchable(),
1326                    Ref::keyword("ON").to_matchable(),
1327                    Sequence::new(vec![
1328                        one_of(vec![
1329                            Sequence::new(vec![
1330                                Ref::keyword("TABLE").to_matchable(),
1331                                Ref::new("TableReferenceSegment").to_matchable(),
1332                            ])
1333                            .to_matchable(),
1334                            Sequence::new(vec![
1335                                Ref::keyword("COLUMN").to_matchable(),
1336                                Ref::new("ColumnReferenceSegment").to_matchable(),
1337                            ])
1338                            .to_matchable(),
1339                            Sequence::new(vec![
1340                                Ref::keyword("OPERATOR").to_matchable(),
1341                                Ref::new("ObjectReferenceSegment").to_matchable(),
1342                            ])
1343                            .to_matchable(),
1344                            Sequence::new(vec![
1345                                Ref::keyword("INDEXTYPE").to_matchable(),
1346                                Ref::new("ObjectReferenceSegment").to_matchable(),
1347                            ])
1348                            .to_matchable(),
1349                            Sequence::new(vec![
1350                                Ref::keyword("MATERIALIZED").to_matchable(),
1351                                Ref::keyword("VIEW").to_matchable(),
1352                                Ref::new("TableReferenceSegment").to_matchable(),
1353                            ])
1354                            .to_matchable(),
1355                        ])
1356                        .to_matchable(),
1357                        Sequence::new(vec![
1358                            Ref::keyword("IS").to_matchable(),
1359                            one_of(vec![
1360                                Ref::new("QuotedLiteralSegment").to_matchable(),
1361                                Ref::keyword("NULL").to_matchable(),
1362                            ])
1363                            .to_matchable(),
1364                        ])
1365                        .to_matchable(),
1366                    ])
1367                    .to_matchable(),
1368                ])
1369                .to_matchable()
1370            })
1371            .to_matchable()
1372            .into(),
1373        ),
1374        // TableReferenceSegment
1375        (
1376            "TableReferenceSegment".into(),
1377            NodeMatcher::new(SyntaxKind::OracleTableReference, |_| {
1378                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
1379                    .config(|config| {
1380                        config.delimiter(one_of(vec![
1381                            Ref::new("DotSegment").to_matchable(),
1382                            Sequence::new(vec![
1383                                Ref::new("DotSegment").to_matchable(),
1384                                Ref::new("DotSegment").to_matchable(),
1385                            ])
1386                            .to_matchable(),
1387                            Ref::new("AtSignSegment").to_matchable(),
1388                        ]));
1389                        config.terminators = vec![
1390                            Ref::keyword("ON").to_matchable(),
1391                            Ref::keyword("AS").to_matchable(),
1392                            Ref::keyword("USING").to_matchable(),
1393                            Ref::new("CommaSegment").to_matchable(),
1394                            Ref::new("CastOperatorSegment").to_matchable(),
1395                            Ref::new("StartSquareBracketSegment").to_matchable(),
1396                            Ref::new("StartBracketSegment").to_matchable(),
1397                            Ref::new("BinaryOperatorGrammar").to_matchable(),
1398                            Ref::new("ColonSegment").to_matchable(),
1399                            Ref::new("DelimiterGrammar").to_matchable(),
1400                            Ref::new("JoinLikeClauseGrammar").to_matchable(),
1401                        ];
1402                        config.allow_gaps = false;
1403                    })
1404                    .to_matchable()
1405            })
1406            .to_matchable()
1407            .into(),
1408        ),
1409        // FunctionNameSegment
1410        (
1411            "FunctionNameSegment".into(),
1412            NodeMatcher::new(SyntaxKind::OracleFunctionName, |_| {
1413                Sequence::new(vec![
1414                    AnyNumberOf::new(vec![
1415                        Sequence::new(vec![
1416                            Ref::new("SingleIdentifierGrammar").to_matchable(),
1417                            Ref::new("DotSegment").to_matchable(),
1418                        ])
1419                        .to_matchable(),
1420                    ])
1421                    .to_matchable(),
1422                    Delimited::new(vec![
1423                        one_of(vec![
1424                            Ref::new("FunctionNameIdentifierSegment").to_matchable(),
1425                            Ref::new("QuotedIdentifierSegment").to_matchable(),
1426                        ])
1427                        .to_matchable(),
1428                    ])
1429                    .config(|config| {
1430                        config.delimiter(Ref::new("AtSignSegment"));
1431                    })
1432                    .to_matchable(),
1433                ])
1434                .config(|config| {
1435                    config.allow_gaps = false;
1436                })
1437                .to_matchable()
1438            })
1439            .to_matchable()
1440            .into(),
1441        ),
1442        // AlterIndexStatementSegment
1443        (
1444            "AlterIndexStatementSegment".into(),
1445            NodeMatcher::new(SyntaxKind::OracleAlterIndexStatement, |_| {
1446                Sequence::new(vec![
1447                    Ref::keyword("ALTER").to_matchable(),
1448                    Ref::keyword("INDEX").to_matchable(),
1449                    Ref::new("IndexReferenceSegment").to_matchable(),
1450                    one_of(vec![
1451                        Sequence::new(vec![
1452                            Ref::keyword("REBUILD").to_matchable(),
1453                            one_of(vec![
1454                                Ref::keyword("REVERSE").to_matchable(),
1455                                Ref::keyword("NOREVERSE").to_matchable(),
1456                            ])
1457                            .config(|config| {
1458                                config.optional();
1459                            })
1460                            .to_matchable(),
1461                        ])
1462                        .to_matchable(),
1463                        Sequence::new(vec![
1464                            Ref::keyword("MONITORING").to_matchable(),
1465                            Ref::keyword("USAGE").to_matchable(),
1466                        ])
1467                        .to_matchable(),
1468                        Sequence::new(vec![
1469                            Ref::keyword("NOMONITORING").to_matchable(),
1470                            Ref::keyword("USAGE").to_matchable(),
1471                        ])
1472                        .to_matchable(),
1473                        Sequence::new(vec![
1474                            Ref::keyword("RENAME").to_matchable(),
1475                            Ref::keyword("TO").to_matchable(),
1476                            Ref::new("IndexReferenceSegment").to_matchable(),
1477                        ])
1478                        .to_matchable(),
1479                        Ref::keyword("COMPILE").to_matchable(),
1480                        Ref::keyword("LOGGING").to_matchable(),
1481                        Ref::keyword("NOLOGGING").to_matchable(),
1482                        Ref::keyword("ENABLE").to_matchable(),
1483                        Ref::keyword("DISABLE").to_matchable(),
1484                        Ref::keyword("UNUSABLE").to_matchable(),
1485                        Ref::keyword("INVISIBLE").to_matchable(),
1486                        Ref::keyword("VISIBLE").to_matchable(),
1487                    ])
1488                    .to_matchable(),
1489                ])
1490                .to_matchable()
1491            })
1492            .to_matchable()
1493            .into(),
1494        ),
1495        // AlterTableStatementSegment
1496        (
1497            "AlterTableStatementSegment".into(),
1498            NodeMatcher::new(SyntaxKind::OracleAlterTableStatement, |_| {
1499                Sequence::new(vec![
1500                    Ref::keyword("ALTER").to_matchable(),
1501                    Ref::keyword("TABLE").to_matchable(),
1502                    Ref::new("TableReferenceSegment").to_matchable(),
1503                    one_of(vec![
1504                        Ref::new("AlterTablePropertiesSegment").to_matchable(),
1505                        Ref::new("AlterTableColumnClausesSegment").to_matchable(),
1506                        Ref::new("AlterTableConstraintClauses").to_matchable(),
1507                    ])
1508                    .to_matchable(),
1509                ])
1510                .to_matchable()
1511            })
1512            .to_matchable()
1513            .into(),
1514        ),
1515        // AlterTablePropertiesSegment
1516        (
1517            "AlterTablePropertiesSegment".into(),
1518            NodeMatcher::new(SyntaxKind::AlterTableProperties, |_| {
1519                one_of(vec![
1520                    Sequence::new(vec![
1521                        Ref::keyword("RENAME").to_matchable(),
1522                        Ref::keyword("TO").to_matchable(),
1523                        Ref::new("TableReferenceSegment").to_matchable(),
1524                    ])
1525                    .to_matchable(),
1526                ])
1527                .to_matchable()
1528            })
1529            .to_matchable()
1530            .into(),
1531        ),
1532        // AlterTableColumnClausesSegment
1533        (
1534            "AlterTableColumnClausesSegment".into(),
1535            NodeMatcher::new(SyntaxKind::AlterTableColumnClauses, |_| {
1536                one_of(vec![
1537                    Sequence::new(vec![
1538                        one_of(vec![
1539                            Ref::keyword("ADD").to_matchable(),
1540                            Ref::keyword("MODIFY").to_matchable(),
1541                        ])
1542                        .to_matchable(),
1543                        one_of(vec![
1544                            Ref::new("ColumnDefinitionSegment").to_matchable(),
1545                            Bracketed::new(vec![
1546                                Delimited::new(vec![
1547                                    Ref::new("ColumnDefinitionSegment").to_matchable(),
1548                                ])
1549                                .to_matchable(),
1550                            ])
1551                            .to_matchable(),
1552                        ])
1553                        .to_matchable(),
1554                    ])
1555                    .to_matchable(),
1556                    Sequence::new(vec![
1557                        Ref::keyword("DROP").to_matchable(),
1558                        one_of(vec![
1559                            Sequence::new(vec![
1560                                Ref::keyword("COLUMN").to_matchable(),
1561                                Ref::new("ColumnReferenceSegment").to_matchable(),
1562                            ])
1563                            .to_matchable(),
1564                            Bracketed::new(vec![
1565                                Delimited::new(vec![
1566                                    Ref::new("ColumnReferenceSegment").to_matchable(),
1567                                ])
1568                                .to_matchable(),
1569                            ])
1570                            .to_matchable(),
1571                        ])
1572                        .to_matchable(),
1573                    ])
1574                    .to_matchable(),
1575                    Sequence::new(vec![
1576                        Ref::keyword("RENAME").to_matchable(),
1577                        Ref::keyword("COLUMN").to_matchable(),
1578                        Ref::new("ColumnReferenceSegment").to_matchable(),
1579                        Ref::keyword("TO").to_matchable(),
1580                        Ref::new("ColumnReferenceSegment").to_matchable(),
1581                    ])
1582                    .to_matchable(),
1583                ])
1584                .to_matchable()
1585            })
1586            .to_matchable()
1587            .into(),
1588        ),
1589        // AlterTableConstraintClauses
1590        (
1591            "AlterTableConstraintClauses".into(),
1592            NodeMatcher::new(SyntaxKind::AlterTableConstraintClauses, |_| {
1593                one_of(vec![
1594                    Sequence::new(vec![
1595                        Ref::keyword("ADD").to_matchable(),
1596                        Ref::new("TableConstraintSegment").to_matchable(),
1597                    ])
1598                    .to_matchable(),
1599                    Sequence::new(vec![
1600                        Ref::keyword("DROP").to_matchable(),
1601                        one_of(vec![
1602                            Sequence::new(vec![
1603                                Ref::keyword("PRIMARY").to_matchable(),
1604                                Ref::keyword("KEY").to_matchable(),
1605                            ])
1606                            .to_matchable(),
1607                            Sequence::new(vec![
1608                                Ref::keyword("UNIQUE").to_matchable(),
1609                                Bracketed::new(vec![
1610                                    Ref::new("ColumnReferenceSegment").to_matchable(),
1611                                ])
1612                                .to_matchable(),
1613                            ])
1614                            .to_matchable(),
1615                            Sequence::new(vec![
1616                                Ref::keyword("CONSTRAINT").to_matchable(),
1617                                Ref::new("ObjectReferenceSegment").to_matchable(),
1618                            ])
1619                            .to_matchable(),
1620                        ])
1621                        .to_matchable(),
1622                        Ref::keyword("CASCADE").optional().to_matchable(),
1623                    ])
1624                    .to_matchable(),
1625                    Sequence::new(vec![
1626                        Ref::keyword("RENAME").to_matchable(),
1627                        Ref::keyword("CONSTRAINT").to_matchable(),
1628                        Ref::new("ObjectReferenceSegment").to_matchable(),
1629                        Ref::keyword("TO").to_matchable(),
1630                        Ref::new("ObjectReferenceSegment").to_matchable(),
1631                    ])
1632                    .to_matchable(),
1633                ])
1634                .to_matchable()
1635            })
1636            .to_matchable()
1637            .into(),
1638        ),
1639        // AlterSessionStatementSegment
1640        (
1641            "AlterSessionStatementSegment".into(),
1642            NodeMatcher::new(SyntaxKind::OracleAlterSessionStatement, |_| {
1643                Sequence::new(vec![
1644                    Ref::keyword("ALTER").to_matchable(),
1645                    Ref::keyword("SESSION").to_matchable(),
1646                    one_of(vec![
1647                        Sequence::new(vec![
1648                            Ref::keyword("ADVISE").to_matchable(),
1649                            one_of(vec![
1650                                Ref::keyword("COMMIT").to_matchable(),
1651                                Ref::keyword("ROLLBACK").to_matchable(),
1652                                Ref::keyword("NOTHING").to_matchable(),
1653                            ])
1654                            .to_matchable(),
1655                        ])
1656                        .to_matchable(),
1657                        Sequence::new(vec![
1658                            Ref::keyword("SET").to_matchable(),
1659                            AnyNumberOf::new(vec![
1660                                Sequence::new(vec![
1661                                    Ref::new("ParameterNameSegment").to_matchable(),
1662                                    Ref::new("EqualsSegment").to_matchable(),
1663                                    one_of(vec![
1664                                        Ref::keyword("DEFAULT").to_matchable(),
1665                                        Ref::new("ExpressionSegment").to_matchable(),
1666                                    ])
1667                                    .to_matchable(),
1668                                ])
1669                                .to_matchable(),
1670                            ])
1671                            .config(|config| {
1672                                config.min_times = 1;
1673                            })
1674                            .to_matchable(),
1675                        ])
1676                        .to_matchable(),
1677                        Sequence::new(vec![
1678                            one_of(vec![
1679                                Ref::keyword("ENABLE").to_matchable(),
1680                                Ref::keyword("DISABLE").to_matchable(),
1681                            ])
1682                            .to_matchable(),
1683                            one_of(vec![
1684                                Ref::keyword("GUARD").to_matchable(),
1685                                Ref::keyword("RESUMABLE").to_matchable(),
1686                                Sequence::new(vec![
1687                                    Ref::keyword("PARALLEL").to_matchable(),
1688                                    one_of(vec![
1689                                        Ref::keyword("DML").to_matchable(),
1690                                        Ref::keyword("DDL").to_matchable(),
1691                                        Ref::keyword("QUERY").to_matchable(),
1692                                    ])
1693                                    .to_matchable(),
1694                                ])
1695                                .to_matchable(),
1696                            ])
1697                            .to_matchable(),
1698                        ])
1699                        .to_matchable(),
1700                    ])
1701                    .to_matchable(),
1702                ])
1703                .to_matchable()
1704            })
1705            .to_matchable()
1706            .into(),
1707        ),
1708        // CreateTableStatementSegment
1709        (
1710            "CreateTableStatementSegment".into(),
1711            NodeMatcher::new(SyntaxKind::OracleCreateTableStatement, |_| {
1712                Sequence::new(vec![
1713                    Ref::keyword("CREATE").to_matchable(),
1714                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
1715                    Ref::new("TemporaryGrammar").optional().to_matchable(),
1716                    Ref::keyword("TABLE").to_matchable(),
1717                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
1718                    Ref::new("TableReferenceSegment").to_matchable(),
1719                    one_of(vec![
1720                        Sequence::new(vec![
1721                            Bracketed::new(vec![
1722                                Delimited::new(vec![
1723                                    one_of(vec![
1724                                        Ref::new("TableConstraintSegment").to_matchable(),
1725                                        Ref::new("ColumnDefinitionSegment").to_matchable(),
1726                                    ])
1727                                    .to_matchable(),
1728                                ])
1729                                .to_matchable(),
1730                            ])
1731                            .to_matchable(),
1732                            Ref::new("CommentClauseSegment").optional().to_matchable(),
1733                            Ref::new("OnCommitGrammar").optional().to_matchable(),
1734                        ])
1735                        .to_matchable(),
1736                        Sequence::new(vec![
1737                            Ref::new("OnCommitGrammar").optional().to_matchable(),
1738                            Ref::keyword("AS").to_matchable(),
1739                            optionally_bracketed(vec![
1740                                Ref::new("SelectableGrammar").to_matchable(),
1741                            ])
1742                            .to_matchable(),
1743                        ])
1744                        .to_matchable(),
1745                        Sequence::new(vec![
1746                            Ref::keyword("LIKE").to_matchable(),
1747                            Ref::new("TableReferenceSegment").to_matchable(),
1748                        ])
1749                        .to_matchable(),
1750                    ])
1751                    .to_matchable(),
1752                    Ref::new("TableEndClauseSegment").optional().to_matchable(),
1753                ])
1754                .to_matchable()
1755            })
1756            .to_matchable()
1757            .into(),
1758        ),
1759        // ColumnDefinitionSegment
1760        (
1761            "ColumnDefinitionSegment".into(),
1762            NodeMatcher::new(SyntaxKind::OracleColumnDefinition, |_| {
1763                Sequence::new(vec![
1764                    Ref::new("SingleIdentifierGrammar").to_matchable(),
1765                    Ref::new("DatatypeSegment").optional().to_matchable(),
1766                    AnyNumberOf::new(vec![
1767                        Sequence::new(vec![
1768                            Ref::new("ColumnConstraintSegment").to_matchable(),
1769                            one_of(vec![
1770                                Ref::keyword("ENABLE").to_matchable(),
1771                                Ref::keyword("DISABLE").to_matchable(),
1772                            ])
1773                            .config(|config| {
1774                                config.optional();
1775                            })
1776                            .to_matchable(),
1777                        ])
1778                        .to_matchable(),
1779                    ])
1780                    .to_matchable(),
1781                    Ref::new("IdentityClauseGrammar").optional().to_matchable(),
1782                ])
1783                .to_matchable()
1784            })
1785            .to_matchable()
1786            .into(),
1787        ),
1788        // CreateViewStatementSegment
1789        (
1790            "CreateViewStatementSegment".into(),
1791            NodeMatcher::new(SyntaxKind::OracleCreateViewStatement, |_| {
1792                Sequence::new(vec![
1793                    Ref::keyword("CREATE").to_matchable(),
1794                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
1795                    Sequence::new(vec![
1796                        Ref::keyword("NO").optional().to_matchable(),
1797                        Ref::keyword("FORCE").to_matchable(),
1798                    ])
1799                    .config(|config| {
1800                        config.optional();
1801                    })
1802                    .to_matchable(),
1803                    one_of(vec![
1804                        Ref::keyword("EDITIONING").to_matchable(),
1805                        Sequence::new(vec![
1806                            Ref::keyword("EDITIONABLE").to_matchable(),
1807                            Ref::keyword("EDITIONING").optional().to_matchable(),
1808                        ])
1809                        .to_matchable(),
1810                        Ref::keyword("NONEDITIONABLE").to_matchable(),
1811                    ])
1812                    .config(|config| {
1813                        config.optional();
1814                    })
1815                    .to_matchable(),
1816                    Ref::keyword("MATERIALIZED").optional().to_matchable(),
1817                    Ref::keyword("VIEW").to_matchable(),
1818                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
1819                    Ref::new("TableReferenceSegment").to_matchable(),
1820                    Ref::new("BracketedColumnReferenceListGrammar")
1821                        .optional()
1822                        .to_matchable(),
1823                    Ref::keyword("AS").to_matchable(),
1824                    optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
1825                        .to_matchable(),
1826                    Ref::new("WithNoSchemaBindingClauseSegment")
1827                        .optional()
1828                        .to_matchable(),
1829                ])
1830                .to_matchable()
1831            })
1832            .to_matchable()
1833            .into(),
1834        ),
1835        // TransactionStatementSegment
1836        (
1837            "TransactionStatementSegment".into(),
1838            NodeMatcher::new(SyntaxKind::OracleTransactionStatement, |_| {
1839                Sequence::new(vec![
1840                    one_of(vec![
1841                        Ref::keyword("START").to_matchable(),
1842                        Ref::keyword("COMMIT").to_matchable(),
1843                        Ref::keyword("ROLLBACK").to_matchable(),
1844                    ])
1845                    .to_matchable(),
1846                    one_of(vec![
1847                        Ref::keyword("TRANSACTION").to_matchable(),
1848                        Ref::keyword("WORK").to_matchable(),
1849                    ])
1850                    .config(|config| {
1851                        config.optional();
1852                    })
1853                    .to_matchable(),
1854                ])
1855                .to_matchable()
1856            })
1857            .to_matchable()
1858            .into(),
1859        ),
1860        // CreateProcedureStatementSegment
1861        (
1862            "CreateProcedureStatementSegment".into(),
1863            NodeMatcher::new(SyntaxKind::OracleCreateProcedureStatement, |_| {
1864                Sequence::new(vec![
1865                    Ref::keyword("CREATE").optional().to_matchable(),
1866                    Sequence::new(vec![
1867                        Ref::keyword("OR").to_matchable(),
1868                        Ref::keyword("REPLACE").to_matchable(),
1869                    ])
1870                    .config(|config| {
1871                        config.optional();
1872                    })
1873                    .to_matchable(),
1874                    one_of(vec![
1875                        Ref::keyword("EDITIONABLE").to_matchable(),
1876                        Ref::keyword("NONEDITIONABLE").to_matchable(),
1877                    ])
1878                    .config(|config| {
1879                        config.optional();
1880                    })
1881                    .to_matchable(),
1882                    Ref::keyword("PROCEDURE").to_matchable(),
1883                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
1884                    Ref::new("FunctionNameSegment").to_matchable(),
1885                    Ref::new("FunctionParameterListGrammar")
1886                        .optional()
1887                        .to_matchable(),
1888                    Ref::new("SharingClauseGrammar").optional().to_matchable(),
1889                    // SQLFluff: AnyNumberOf(DefaultCollation, InvokerRights, AccessibleBy)
1890                    AnyNumberOf::new(vec![
1891                        Ref::new("DefaultCollationClauseGrammar").to_matchable(),
1892                        Ref::new("InvokerRightsClauseGrammar").to_matchable(),
1893                        Ref::new("AccessibleByClauseGrammar").to_matchable(),
1894                    ])
1895                    .config(|config| {
1896                        config.optional();
1897                    })
1898                    .to_matchable(),
1899                    one_of(vec![
1900                        Ref::keyword("IS").to_matchable(),
1901                        Ref::keyword("AS").to_matchable(),
1902                    ])
1903                    .config(|config| {
1904                        config.optional();
1905                    })
1906                    .to_matchable(),
1907                    AnyNumberOf::new(vec![Ref::new("DeclareSegment").to_matchable()])
1908                        .config(|config| {
1909                            config.optional();
1910                        })
1911                        .to_matchable(),
1912                    Ref::new("BeginEndSegment").optional().to_matchable(),
1913                    Ref::new("DelimiterGrammar").optional().to_matchable(),
1914                ])
1915                .to_matchable()
1916            })
1917            .to_matchable()
1918            .into(),
1919        ),
1920        // DropProcedureStatementSegment
1921        (
1922            "DropProcedureStatementSegment".into(),
1923            NodeMatcher::new(SyntaxKind::OracleDropProcedureStatement, |_| {
1924                Sequence::new(vec![
1925                    Ref::keyword("DROP").to_matchable(),
1926                    Ref::keyword("PROCEDURE").to_matchable(),
1927                    Ref::new("FunctionNameSegment").to_matchable(),
1928                ])
1929                .to_matchable()
1930            })
1931            .to_matchable()
1932            .into(),
1933        ),
1934        // DeclareSegment
1935        (
1936            "DeclareSegment".into(),
1937            NodeMatcher::new(SyntaxKind::OracleDeclareSegment, |_| {
1938                Sequence::new(vec![
1939                    Ref::keyword("DECLARE").optional().to_matchable(),
1940                    MetaSegment::indent().to_matchable(),
1941                    AnyNumberOf::new(vec![
1942                        Delimited::new(vec![
1943                            one_of(vec![
1944                                Sequence::new(vec![
1945                                    one_of(vec![
1946                                        Sequence::new(vec![
1947                                            Ref::new("SingleIdentifierGrammar").to_matchable(),
1948                                            Ref::keyword("CONSTANT").optional().to_matchable(),
1949                                            one_of(vec![
1950                                                Ref::new("DatatypeSegment").to_matchable(),
1951                                                Ref::new("ColumnTypeReferenceSegment")
1952                                                    .to_matchable(),
1953                                                Ref::new("RowTypeReferenceSegment").to_matchable(),
1954                                            ])
1955                                            .to_matchable(),
1956                                        ])
1957                                        .to_matchable(),
1958                                        Sequence::new(vec![
1959                                            Ref::keyword("PRAGMA").to_matchable(),
1960                                            Ref::new("FunctionSegment").to_matchable(),
1961                                        ])
1962                                        .to_matchable(),
1963                                        Ref::new("CollectionTypeDefinitionSegment").to_matchable(),
1964                                        Ref::new("RecordTypeDefinitionSegment").to_matchable(),
1965                                        Ref::new("RefCursorTypeDefinitionSegment").to_matchable(),
1966                                    ])
1967                                    .to_matchable(),
1968                                    Sequence::new(vec![
1969                                        Ref::keyword("NOT").to_matchable(),
1970                                        Ref::keyword("NULL").to_matchable(),
1971                                    ])
1972                                    .config(|config| {
1973                                        config.optional();
1974                                    })
1975                                    .to_matchable(),
1976                                    Sequence::new(vec![
1977                                        one_of(vec![
1978                                            Ref::new("AssignmentOperatorSegment").to_matchable(),
1979                                            Ref::keyword("DEFAULT").to_matchable(),
1980                                        ])
1981                                        .to_matchable(),
1982                                        Ref::new("ExpressionSegment").to_matchable(),
1983                                    ])
1984                                    .config(|config| {
1985                                        config.optional();
1986                                    })
1987                                    .to_matchable(),
1988                                    Ref::new("DelimiterGrammar").to_matchable(),
1989                                ])
1990                                .to_matchable(),
1991                                Ref::new("CreateProcedureStatementSegment").to_matchable(),
1992                                Ref::new("CreateFunctionStatementSegment").to_matchable(),
1993                                Ref::new("DeclareCursorVariableSegment").to_matchable(),
1994                            ])
1995                            .to_matchable(),
1996                        ])
1997                        .config(|config| {
1998                            config.delimiter(Ref::new("DelimiterGrammar"));
1999                            config.terminators = vec![
2000                                Ref::keyword("BEGIN").to_matchable(),
2001                                Ref::keyword("END").to_matchable(),
2002                            ];
2003                        })
2004                        .to_matchable(),
2005                    ])
2006                    .config(|config| {
2007                        config.min_times = 1;
2008                    })
2009                    .to_matchable(),
2010                    MetaSegment::dedent().to_matchable(),
2011                ])
2012                .to_matchable()
2013            })
2014            .to_matchable()
2015            .into(),
2016        ),
2017        // ColumnTypeReferenceSegment
2018        (
2019            "ColumnTypeReferenceSegment".into(),
2020            NodeMatcher::new(SyntaxKind::OracleColumnTypeReference, |_| {
2021                Sequence::new(vec![
2022                    Ref::new("ColumnReferenceSegment").to_matchable(),
2023                    Ref::new("ModuloSegment").to_matchable(),
2024                    Ref::keyword("TYPE").to_matchable(),
2025                ])
2026                .to_matchable()
2027            })
2028            .to_matchable()
2029            .into(),
2030        ),
2031        // RowTypeReferenceSegment
2032        (
2033            "RowTypeReferenceSegment".into(),
2034            NodeMatcher::new(SyntaxKind::OracleRowTypeReference, |_| {
2035                Sequence::new(vec![
2036                    Ref::new("TableReferenceSegment").to_matchable(),
2037                    Ref::new("ModuloSegment").to_matchable(),
2038                    Ref::keyword("ROWTYPE").to_matchable(),
2039                ])
2040                .to_matchable()
2041            })
2042            .to_matchable()
2043            .into(),
2044        ),
2045        // CollectionTypeDefinitionSegment
2046        // SQLFluff: TYPE name IS [TABLE OF | VARRAY(n) OF] type [NOT NULL] [INDEX BY type]
2047        (
2048            "CollectionTypeDefinitionSegment".into(),
2049            NodeMatcher::new(SyntaxKind::CollectionType, |_| {
2050                Sequence::new(vec![
2051                    Ref::keyword("TYPE").to_matchable(),
2052                    Ref::new("SingleIdentifierGrammar").to_matchable(),
2053                    Ref::keyword("IS").to_matchable(),
2054                    one_of(vec![
2055                        // TABLE OF type
2056                        Sequence::new(vec![
2057                            Ref::keyword("TABLE").to_matchable(),
2058                            Ref::keyword("OF").to_matchable(),
2059                            one_of(vec![
2060                                Ref::new("DatatypeSegment").to_matchable(),
2061                                Ref::new("ColumnTypeReferenceSegment").to_matchable(),
2062                                Ref::new("RowTypeReferenceSegment").to_matchable(),
2063                            ])
2064                            .to_matchable(),
2065                        ])
2066                        .to_matchable(),
2067                        // VARRAY(n) OF type
2068                        Sequence::new(vec![
2069                            one_of(vec![
2070                                Ref::keyword("VARRAY").to_matchable(),
2071                                Sequence::new(vec![
2072                                    Ref::keyword("VARYING").optional().to_matchable(),
2073                                    Ref::keyword("ARRAY").to_matchable(),
2074                                ])
2075                                .to_matchable(),
2076                            ])
2077                            .to_matchable(),
2078                            Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
2079                                .to_matchable(),
2080                            Ref::keyword("OF").to_matchable(),
2081                            one_of(vec![
2082                                Ref::new("DatatypeSegment").to_matchable(),
2083                                Ref::new("ColumnTypeReferenceSegment").to_matchable(),
2084                                Ref::new("RowTypeReferenceSegment").to_matchable(),
2085                            ])
2086                            .to_matchable(),
2087                        ])
2088                        .to_matchable(),
2089                        // Plain type (subtype definition)
2090                        one_of(vec![
2091                            Ref::new("DatatypeSegment").to_matchable(),
2092                            Ref::new("ColumnTypeReferenceSegment").to_matchable(),
2093                            Ref::new("RowTypeReferenceSegment").to_matchable(),
2094                        ])
2095                        .to_matchable(),
2096                    ])
2097                    .to_matchable(),
2098                    Sequence::new(vec![
2099                        Ref::keyword("NOT").to_matchable(),
2100                        Ref::keyword("NULL").to_matchable(),
2101                    ])
2102                    .config(|config| {
2103                        config.optional();
2104                    })
2105                    .to_matchable(),
2106                    Sequence::new(vec![
2107                        Ref::keyword("INDEX").to_matchable(),
2108                        Ref::keyword("BY").to_matchable(),
2109                        Ref::new("DatatypeSegment").to_matchable(),
2110                    ])
2111                    .config(|config| {
2112                        config.optional();
2113                    })
2114                    .to_matchable(),
2115                ])
2116                .to_matchable()
2117            })
2118            .to_matchable()
2119            .into(),
2120        ),
2121        // RecordTypeDefinitionSegment
2122        // SQLFluff: TYPE name IS RECORD (field type [NOT NULL] [:= | DEFAULT expr], ...)
2123        (
2124            "RecordTypeDefinitionSegment".into(),
2125            NodeMatcher::new(SyntaxKind::RecordType, |_| {
2126                Sequence::new(vec![
2127                    Ref::keyword("TYPE").to_matchable(),
2128                    Ref::new("SingleIdentifierGrammar").to_matchable(),
2129                    Ref::keyword("IS").to_matchable(),
2130                    Ref::keyword("RECORD").to_matchable(),
2131                    Bracketed::new(vec![
2132                        Delimited::new(vec![
2133                            Sequence::new(vec![
2134                                Ref::new("SingleIdentifierGrammar").to_matchable(),
2135                                one_of(vec![
2136                                    Ref::new("DatatypeSegment").to_matchable(),
2137                                    Ref::new("ColumnTypeReferenceSegment").to_matchable(),
2138                                ])
2139                                .to_matchable(),
2140                                Sequence::new(vec![
2141                                    Sequence::new(vec![
2142                                        Ref::keyword("NOT").to_matchable(),
2143                                        Ref::keyword("NULL").to_matchable(),
2144                                    ])
2145                                    .config(|config| {
2146                                        config.optional();
2147                                    })
2148                                    .to_matchable(),
2149                                    one_of(vec![
2150                                        Ref::new("AssignmentOperatorSegment").to_matchable(),
2151                                        Ref::keyword("DEFAULT").to_matchable(),
2152                                    ])
2153                                    .to_matchable(),
2154                                    Ref::new("ExpressionSegment").to_matchable(),
2155                                ])
2156                                .config(|config| {
2157                                    config.optional();
2158                                })
2159                                .to_matchable(),
2160                            ])
2161                            .to_matchable(),
2162                        ])
2163                        .to_matchable(),
2164                    ])
2165                    .to_matchable(),
2166                ])
2167                .to_matchable()
2168            })
2169            .to_matchable()
2170            .into(),
2171        ),
2172        // RefCursorTypeDefinitionSegment
2173        (
2174            "RefCursorTypeDefinitionSegment".into(),
2175            NodeMatcher::new(SyntaxKind::RefCursorType, |_| {
2176                Sequence::new(vec![
2177                    Ref::keyword("TYPE").to_matchable(),
2178                    Ref::new("SingleIdentifierGrammar").to_matchable(),
2179                    Ref::keyword("IS").to_matchable(),
2180                    Ref::keyword("REF").to_matchable(),
2181                    Ref::keyword("CURSOR").to_matchable(),
2182                    Sequence::new(vec![
2183                        Ref::keyword("RETURN").to_matchable(),
2184                        one_of(vec![
2185                            Ref::new("RowTypeReferenceSegment").to_matchable(),
2186                            Ref::new("ColumnTypeReferenceSegment").to_matchable(),
2187                            Ref::new("ObjectReferenceSegment").to_matchable(),
2188                        ])
2189                        .to_matchable(),
2190                    ])
2191                    .config(|config| {
2192                        config.optional();
2193                    })
2194                    .to_matchable(),
2195                ])
2196                .to_matchable()
2197            })
2198            .to_matchable()
2199            .into(),
2200        ),
2201        // DeclareCursorVariableSegment
2202        (
2203            "DeclareCursorVariableSegment".into(),
2204            NodeMatcher::new(SyntaxKind::DeclareCursorVariable, |_| {
2205                Sequence::new(vec![
2206                    Ref::keyword("CURSOR").to_matchable(),
2207                    Ref::new("SingleIdentifierGrammar").to_matchable(),
2208                    Ref::new("FunctionParameterListGrammar")
2209                        .optional()
2210                        .to_matchable(),
2211                    Sequence::new(vec![
2212                        Ref::keyword("RETURN").to_matchable(),
2213                        one_of(vec![
2214                            Ref::new("ColumnTypeReferenceSegment").to_matchable(),
2215                            Ref::new("RowTypeReferenceSegment").to_matchable(),
2216                            Ref::new("DatatypeSegment").to_matchable(),
2217                        ])
2218                        .to_matchable(),
2219                    ])
2220                    .config(|config| {
2221                        config.optional();
2222                    })
2223                    .to_matchable(),
2224                    Sequence::new(vec![
2225                        Ref::keyword("IS").to_matchable(),
2226                        MetaSegment::indent().to_matchable(),
2227                        Ref::new("SelectStatementSegment").to_matchable(),
2228                        MetaSegment::dedent().to_matchable(),
2229                    ])
2230                    .config(|config| {
2231                        config.optional();
2232                    })
2233                    .to_matchable(),
2234                    Ref::new("DelimiterGrammar").optional().to_matchable(),
2235                ])
2236                .to_matchable()
2237            })
2238            .to_matchable()
2239            .into(),
2240        ),
2241        // ExecuteImmediateSegment
2242        (
2243            "ExecuteImmediateSegment".into(),
2244            NodeMatcher::new(SyntaxKind::OracleExecuteImmediateStatement, |_| {
2245                Sequence::new(vec![
2246                    Ref::keyword("EXECUTE").to_matchable(),
2247                    Ref::keyword("IMMEDIATE").to_matchable(),
2248                    Ref::new("ExpressionSegment").to_matchable(),
2249                    one_of(vec![
2250                        Ref::new("IntoClauseSegment").to_matchable(),
2251                        Ref::new("BulkCollectIntoClauseSegment").to_matchable(),
2252                    ])
2253                    .config(|config| {
2254                        config.optional();
2255                    })
2256                    .to_matchable(),
2257                    Sequence::new(vec![
2258                        Ref::keyword("USING").to_matchable(),
2259                        Delimited::new(vec![
2260                            Sequence::new(vec![
2261                                one_of(vec![
2262                                    Ref::keyword("IN").to_matchable(),
2263                                    Ref::keyword("OUT").to_matchable(),
2264                                    Sequence::new(vec![
2265                                        Ref::keyword("IN").to_matchable(),
2266                                        Ref::keyword("OUT").to_matchable(),
2267                                    ])
2268                                    .to_matchable(),
2269                                ])
2270                                .config(|config| {
2271                                    config.optional();
2272                                })
2273                                .to_matchable(),
2274                                Ref::new("ExpressionSegment").to_matchable(),
2275                            ])
2276                            .to_matchable(),
2277                        ])
2278                        .to_matchable(),
2279                    ])
2280                    .config(|config| {
2281                        config.optional();
2282                    })
2283                    .to_matchable(),
2284                ])
2285                .to_matchable()
2286            })
2287            .to_matchable()
2288            .into(),
2289        ),
2290        // BeginEndSegment
2291        (
2292            "BeginEndSegment".into(),
2293            NodeMatcher::new(SyntaxKind::OracleBeginEndBlock, |_| {
2294                Sequence::new(vec![
2295                    Ref::new("DeclareSegment").optional().to_matchable(),
2296                    Ref::keyword("BEGIN").to_matchable(),
2297                    MetaSegment::indent().to_matchable(),
2298                    Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
2299                    Sequence::new(vec![
2300                        Ref::keyword("EXCEPTION").to_matchable(),
2301                        MetaSegment::indent().to_matchable(),
2302                        AnyNumberOf::new(vec![
2303                            Sequence::new(vec![
2304                                Ref::keyword("WHEN").to_matchable(),
2305                                one_of(vec![
2306                                    Ref::keyword("OTHERS").to_matchable(),
2307                                    Sequence::new(vec![
2308                                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2309                                        AnyNumberOf::new(vec![
2310                                            Sequence::new(vec![
2311                                                Ref::keyword("OR").to_matchable(),
2312                                                Ref::new("SingleIdentifierGrammar").to_matchable(),
2313                                            ])
2314                                            .to_matchable(),
2315                                        ])
2316                                        .to_matchable(),
2317                                    ])
2318                                    .to_matchable(),
2319                                ])
2320                                .to_matchable(),
2321                                Ref::keyword("THEN").to_matchable(),
2322                                MetaSegment::indent().to_matchable(),
2323                                Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
2324                                MetaSegment::dedent().to_matchable(),
2325                            ])
2326                            .to_matchable(),
2327                        ])
2328                        .config(|config| {
2329                            config.min_times = 1;
2330                        })
2331                        .to_matchable(),
2332                        MetaSegment::dedent().to_matchable(),
2333                    ])
2334                    .config(|config| {
2335                        config.optional();
2336                    })
2337                    .to_matchable(),
2338                    MetaSegment::dedent().to_matchable(),
2339                    Ref::keyword("END").to_matchable(),
2340                    Ref::new("ObjectReferenceSegment").optional().to_matchable(),
2341                ])
2342                .to_matchable()
2343            })
2344            .to_matchable()
2345            .into(),
2346        ),
2347        // CreateFunctionStatementSegment
2348        (
2349            "CreateFunctionStatementSegment".into(),
2350            NodeMatcher::new(SyntaxKind::OracleCreateFunctionStatement, |_| {
2351                Sequence::new(vec![
2352                    Ref::keyword("CREATE").optional().to_matchable(),
2353                    Sequence::new(vec![
2354                        Ref::keyword("OR").to_matchable(),
2355                        Ref::keyword("REPLACE").to_matchable(),
2356                    ])
2357                    .config(|config| {
2358                        config.optional();
2359                    })
2360                    .to_matchable(),
2361                    one_of(vec![
2362                        Ref::keyword("EDITIONABLE").to_matchable(),
2363                        Ref::keyword("NONEDITIONABLE").to_matchable(),
2364                    ])
2365                    .config(|config| {
2366                        config.optional();
2367                    })
2368                    .to_matchable(),
2369                    Ref::keyword("FUNCTION").to_matchable(),
2370                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2371                    Ref::new("FunctionNameSegment").to_matchable(),
2372                    Ref::new("FunctionParameterListGrammar")
2373                        .optional()
2374                        .to_matchable(),
2375                    Ref::keyword("RETURN").to_matchable(),
2376                    Ref::new("DatatypeSegment").to_matchable(),
2377                    Ref::new("SharingClauseGrammar").optional().to_matchable(),
2378                    AnyNumberOf::new(vec![
2379                        Ref::new("DefaultCollationClauseGrammar").to_matchable(),
2380                        Ref::new("InvokerRightsClauseGrammar").to_matchable(),
2381                        Ref::new("AccessibleByClauseGrammar").to_matchable(),
2382                        Ref::keyword("DETERMINISTIC").to_matchable(),
2383                        Ref::keyword("SHARD_ENABLE").to_matchable(),
2384                        Ref::new("ParallelEnableClauseGrammar").to_matchable(),
2385                        Ref::new("ResultCacheClauseGrammar").to_matchable(),
2386                        Ref::new("PipelinedClauseGrammar").to_matchable(),
2387                    ])
2388                    .config(|config| {
2389                        config.optional();
2390                    })
2391                    .to_matchable(),
2392                    one_of(vec![
2393                        Ref::keyword("IS").to_matchable(),
2394                        Ref::keyword("AS").to_matchable(),
2395                    ])
2396                    .config(|config| {
2397                        config.optional();
2398                    })
2399                    .to_matchable(),
2400                    AnyNumberOf::new(vec![Ref::new("DeclareSegment").to_matchable()])
2401                        .config(|config| {
2402                            config.optional();
2403                        })
2404                        .to_matchable(),
2405                    Ref::new("BeginEndSegment").optional().to_matchable(),
2406                    Ref::new("DelimiterGrammar").optional().to_matchable(),
2407                ])
2408                .to_matchable()
2409            })
2410            .to_matchable()
2411            .into(),
2412        ),
2413        // AlterFunctionStatementSegment
2414        (
2415            "AlterFunctionStatementSegment".into(),
2416            NodeMatcher::new(SyntaxKind::OracleAlterFunctionStatement, |_| {
2417                Sequence::new(vec![
2418                    Ref::keyword("ALTER").to_matchable(),
2419                    one_of(vec![
2420                        Ref::keyword("FUNCTION").to_matchable(),
2421                        Ref::keyword("PROCEDURE").to_matchable(),
2422                    ])
2423                    .to_matchable(),
2424                    Ref::new("FunctionNameSegment").to_matchable(),
2425                    one_of(vec![
2426                        Ref::new("CompileClauseGrammar").to_matchable(),
2427                        Ref::keyword("EDITIONABLE").to_matchable(),
2428                        Ref::keyword("NONEDITIONABLE").to_matchable(),
2429                    ])
2430                    .to_matchable(),
2431                ])
2432                .to_matchable()
2433            })
2434            .to_matchable()
2435            .into(),
2436        ),
2437        // CreateTypeStatementSegment
2438        (
2439            "CreateTypeStatementSegment".into(),
2440            NodeMatcher::new(SyntaxKind::OracleCreateTypeStatement, |_| {
2441                Sequence::new(vec![
2442                    Ref::keyword("CREATE").optional().to_matchable(),
2443                    Sequence::new(vec![
2444                        Ref::keyword("OR").to_matchable(),
2445                        Ref::keyword("REPLACE").to_matchable(),
2446                    ])
2447                    .config(|config| {
2448                        config.optional();
2449                    })
2450                    .to_matchable(),
2451                    Ref::keyword("TYPE").to_matchable(),
2452                    Ref::new("ObjectReferenceSegment").to_matchable(),
2453                    one_of(vec![
2454                        Ref::keyword("IS").to_matchable(),
2455                        Ref::keyword("AS").to_matchable(),
2456                    ])
2457                    .config(|config| {
2458                        config.optional();
2459                    })
2460                    .to_matchable(),
2461                    one_of(vec![
2462                        Ref::new("ObjectTypeAndSubtypeDefGrammar").to_matchable(),
2463                        Ref::new("VarrayAndNestedTypeSpecGrammar").to_matchable(),
2464                    ])
2465                    .to_matchable(),
2466                ])
2467                .to_matchable()
2468            })
2469            .to_matchable()
2470            .into(),
2471        ),
2472        // CreateTypeBodyStatementSegment
2473        (
2474            "CreateTypeBodyStatementSegment".into(),
2475            NodeMatcher::new(SyntaxKind::OracleCreateTypeBodyStatement, |_| {
2476                Sequence::new(vec![
2477                    Ref::keyword("CREATE").optional().to_matchable(),
2478                    Sequence::new(vec![
2479                        Ref::keyword("OR").to_matchable(),
2480                        Ref::keyword("REPLACE").to_matchable(),
2481                    ])
2482                    .config(|config| {
2483                        config.optional();
2484                    })
2485                    .to_matchable(),
2486                    Ref::keyword("TYPE").to_matchable(),
2487                    Ref::keyword("BODY").to_matchable(),
2488                    Ref::new("ObjectReferenceSegment").to_matchable(),
2489                    one_of(vec![
2490                        Ref::keyword("IS").to_matchable(),
2491                        Ref::keyword("AS").to_matchable(),
2492                    ])
2493                    .to_matchable(),
2494                    MetaSegment::indent().to_matchable(),
2495                    Ref::new("ElementSpecificationGrammar").to_matchable(),
2496                    MetaSegment::dedent().to_matchable(),
2497                    Ref::keyword("END").to_matchable(),
2498                ])
2499                .to_matchable()
2500            })
2501            .to_matchable()
2502            .into(),
2503        ),
2504        // CreatePackageStatementSegment
2505        (
2506            "CreatePackageStatementSegment".into(),
2507            NodeMatcher::new(SyntaxKind::OracleCreatePackageStatement, |_| {
2508                Sequence::new(vec![
2509                    Ref::keyword("CREATE").to_matchable(),
2510                    Sequence::new(vec![
2511                        Ref::keyword("OR").to_matchable(),
2512                        Ref::keyword("REPLACE").to_matchable(),
2513                    ])
2514                    .config(|config| {
2515                        config.optional();
2516                    })
2517                    .to_matchable(),
2518                    Ref::keyword("PACKAGE").to_matchable(),
2519                    Ref::keyword("BODY").optional().to_matchable(),
2520                    Ref::new("ObjectReferenceSegment").to_matchable(),
2521                    one_of(vec![
2522                        Ref::keyword("IS").to_matchable(),
2523                        Ref::keyword("AS").to_matchable(),
2524                    ])
2525                    .to_matchable(),
2526                    Ref::new("DeclareSegment").to_matchable(),
2527                    Ref::keyword("END").to_matchable(),
2528                    Ref::new("ObjectReferenceSegment").optional().to_matchable(),
2529                ])
2530                .to_matchable()
2531            })
2532            .to_matchable()
2533            .into(),
2534        ),
2535        // AlterPackageStatementSegment
2536        (
2537            "AlterPackageStatementSegment".into(),
2538            NodeMatcher::new(SyntaxKind::OracleAlterPackageStatement, |_| {
2539                Sequence::new(vec![
2540                    Ref::keyword("ALTER").to_matchable(),
2541                    Ref::keyword("PACKAGE").to_matchable(),
2542                    Ref::new("ObjectReferenceSegment").to_matchable(),
2543                    one_of(vec![
2544                        Ref::new("CompileClauseGrammar").to_matchable(),
2545                        Ref::keyword("EDITIONABLE").to_matchable(),
2546                        Ref::keyword("NONEDITIONABLE").to_matchable(),
2547                    ])
2548                    .to_matchable(),
2549                ])
2550                .to_matchable()
2551            })
2552            .to_matchable()
2553            .into(),
2554        ),
2555        // DropPackageStatementSegment
2556        (
2557            "DropPackageStatementSegment".into(),
2558            NodeMatcher::new(SyntaxKind::OracleDropPackageStatement, |_| {
2559                Sequence::new(vec![
2560                    Ref::keyword("DROP").to_matchable(),
2561                    Ref::keyword("PACKAGE").to_matchable(),
2562                    Ref::keyword("BODY").optional().to_matchable(),
2563                    Ref::new("ObjectReferenceSegment").to_matchable(),
2564                ])
2565                .to_matchable()
2566            })
2567            .to_matchable()
2568            .into(),
2569        ),
2570        // CreateTriggerStatementSegment
2571        (
2572            "CreateTriggerStatementSegment".into(),
2573            NodeMatcher::new(SyntaxKind::OracleCreateTriggerStatement, |_| {
2574                Sequence::new(vec![
2575                    Ref::keyword("CREATE").to_matchable(),
2576                    Sequence::new(vec![
2577                        Ref::keyword("OR").to_matchable(),
2578                        Ref::keyword("REPLACE").to_matchable(),
2579                    ])
2580                    .config(|config| {
2581                        config.optional();
2582                    })
2583                    .to_matchable(),
2584                    Ref::keyword("TRIGGER").to_matchable(),
2585                    Ref::new("TriggerReferenceSegment").to_matchable(),
2586                    Sequence::new(vec![
2587                        one_of(vec![
2588                            one_of(vec![
2589                                Ref::keyword("BEFORE").to_matchable(),
2590                                Ref::keyword("AFTER").to_matchable(),
2591                            ])
2592                            .to_matchable(),
2593                            Sequence::new(vec![
2594                                Ref::keyword("INSTEAD").to_matchable(),
2595                                Ref::keyword("OF").to_matchable(),
2596                            ])
2597                            .to_matchable(),
2598                            Ref::keyword("FOR").to_matchable(),
2599                        ])
2600                        .to_matchable(),
2601                        Ref::new("DmlEventClauseSegment").to_matchable(),
2602                    ])
2603                    .to_matchable(),
2604                    Sequence::new(vec![
2605                        Ref::keyword("FOR").to_matchable(),
2606                        Ref::keyword("EACH").to_matchable(),
2607                        Ref::keyword("ROW").to_matchable(),
2608                    ])
2609                    .config(|config| {
2610                        config.optional();
2611                    })
2612                    .to_matchable(),
2613                    one_of(vec![
2614                        Ref::keyword("ENABLE").to_matchable(),
2615                        Ref::keyword("DISABLE").to_matchable(),
2616                    ])
2617                    .config(|config| {
2618                        config.optional();
2619                    })
2620                    .to_matchable(),
2621                    Sequence::new(vec![
2622                        Ref::keyword("WHEN").to_matchable(),
2623                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
2624                            .to_matchable(),
2625                    ])
2626                    .config(|config| {
2627                        config.optional();
2628                    })
2629                    .to_matchable(),
2630                    Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
2631                    Ref::keyword("END").optional().to_matchable(),
2632                    Ref::new("TriggerReferenceSegment")
2633                        .optional()
2634                        .to_matchable(),
2635                ])
2636                .to_matchable()
2637            })
2638            .to_matchable()
2639            .into(),
2640        ),
2641        // DmlEventClauseSegment
2642        (
2643            "DmlEventClauseSegment".into(),
2644            NodeMatcher::new(SyntaxKind::DmlEventClause, |_| {
2645                Sequence::new(vec![
2646                    Ref::new("DmlGrammar").to_matchable(),
2647                    AnyNumberOf::new(vec![
2648                        Sequence::new(vec![
2649                            Ref::keyword("OR").to_matchable(),
2650                            Ref::new("DmlGrammar").to_matchable(),
2651                        ])
2652                        .to_matchable(),
2653                    ])
2654                    .to_matchable(),
2655                    Ref::keyword("ON").to_matchable(),
2656                    Ref::new("TableReferenceSegment").to_matchable(),
2657                ])
2658                .to_matchable()
2659            })
2660            .to_matchable()
2661            .into(),
2662        ),
2663        // AlterTriggerStatementSegment
2664        (
2665            "AlterTriggerStatementSegment".into(),
2666            NodeMatcher::new(SyntaxKind::OracleAlterTriggerStatement, |_| {
2667                Sequence::new(vec![
2668                    Ref::keyword("ALTER").to_matchable(),
2669                    Ref::keyword("TRIGGER").to_matchable(),
2670                    Ref::new("FunctionNameSegment").to_matchable(),
2671                    one_of(vec![
2672                        Ref::new("CompileClauseGrammar").to_matchable(),
2673                        Ref::keyword("ENABLE").to_matchable(),
2674                        Ref::keyword("DISABLE").to_matchable(),
2675                        Sequence::new(vec![
2676                            Ref::keyword("RENAME").to_matchable(),
2677                            Ref::keyword("TO").to_matchable(),
2678                            Ref::new("FunctionNameSegment").to_matchable(),
2679                        ])
2680                        .to_matchable(),
2681                    ])
2682                    .to_matchable(),
2683                ])
2684                .to_matchable()
2685            })
2686            .to_matchable()
2687            .into(),
2688        ),
2689        // AssignmentStatementSegment
2690        // SQLFluff: AnyNumberOf(ObjectRef, Bracketed(subscript)?, DotSegment?,
2691        //           OneOf(TriggerCorrelation, SqlplusVariable)?, optional)
2692        //           := / DEFAULT  ExpressionSegment
2693        (
2694            "AssignmentStatementSegment".into(),
2695            NodeMatcher::new(SyntaxKind::AssignmentSegmentStatement, |_| {
2696                Sequence::new(vec![
2697                    AnyNumberOf::new(vec![
2698                        Ref::new("ObjectReferenceSegment").to_matchable(),
2699                        Bracketed::new(vec![
2700                            one_of(vec![
2701                                Ref::new("ObjectReferenceSegment").to_matchable(),
2702                                Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
2703                                Ref::new("NumericLiteralSegment").to_matchable(),
2704                            ])
2705                            .to_matchable(),
2706                        ])
2707                        .config(|config| {
2708                            config.optional();
2709                        })
2710                        .to_matchable(),
2711                        Ref::new("DotSegment").optional().to_matchable(),
2712                        one_of(vec![
2713                            Ref::new("TriggerCorrelationReferenceSegment").to_matchable(),
2714                            Ref::new("SqlplusVariableGrammar").to_matchable(),
2715                        ])
2716                        .config(|config| {
2717                            config.optional();
2718                        })
2719                        .to_matchable(),
2720                    ])
2721                    .config(|config| {
2722                        config.optional();
2723                    })
2724                    .to_matchable(),
2725                    one_of(vec![
2726                        Ref::new("AssignmentOperatorSegment").to_matchable(),
2727                        Ref::keyword("DEFAULT").to_matchable(),
2728                    ])
2729                    .to_matchable(),
2730                    Ref::new("ExpressionSegment").to_matchable(),
2731                ])
2732                .to_matchable()
2733            })
2734            .to_matchable()
2735            .into(),
2736        ),
2737        // IfExpressionStatement
2738        (
2739            "IfExpressionStatement".into(),
2740            NodeMatcher::new(SyntaxKind::OracleIfThenStatement, |_| {
2741                Sequence::new(vec![
2742                    Ref::new("IfClauseSegment").to_matchable(),
2743                    MetaSegment::indent().to_matchable(),
2744                    Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
2745                    MetaSegment::dedent().to_matchable(),
2746                    AnyNumberOf::new(vec![
2747                        Sequence::new(vec![
2748                            Ref::keyword("ELSIF").to_matchable(),
2749                            Ref::new("ExpressionSegment").to_matchable(),
2750                            Ref::keyword("THEN").to_matchable(),
2751                            MetaSegment::indent().to_matchable(),
2752                            Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
2753                            MetaSegment::dedent().to_matchable(),
2754                        ])
2755                        .to_matchable(),
2756                    ])
2757                    .to_matchable(),
2758                    Sequence::new(vec![
2759                        Ref::keyword("ELSE").to_matchable(),
2760                        MetaSegment::indent().to_matchable(),
2761                        Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
2762                        MetaSegment::dedent().to_matchable(),
2763                    ])
2764                    .config(|config| {
2765                        config.optional();
2766                    })
2767                    .to_matchable(),
2768                    Ref::keyword("END").to_matchable(),
2769                    Ref::keyword("IF").to_matchable(),
2770                ])
2771                .to_matchable()
2772            })
2773            .to_matchable()
2774            .into(),
2775        ),
2776        // IfClauseSegment
2777        (
2778            "IfClauseSegment".into(),
2779            NodeMatcher::new(SyntaxKind::OracleIfClause, |_| {
2780                Sequence::new(vec![
2781                    Ref::keyword("IF").to_matchable(),
2782                    Ref::new("ExpressionSegment").to_matchable(),
2783                    Ref::keyword("THEN").to_matchable(),
2784                ])
2785                .to_matchable()
2786            })
2787            .to_matchable()
2788            .into(),
2789        ),
2790        // NullStatementSegment
2791        (
2792            "NullStatementSegment".into(),
2793            NodeMatcher::new(SyntaxKind::OracleNullStatement, |_| {
2794                Ref::keyword("NULL").to_matchable()
2795            })
2796            .to_matchable()
2797            .into(),
2798        ),
2799        // ForLoopStatementSegment
2800        // SQLFluff: Sequence("FOR", Delimited(Sequence(id, OneOf(MUTABLE,IMMUTABLE)?)),
2801        //   "IN", Delimited(Sequence(REVERSE?, OneOf(range,expr,select), WHILE?, WHEN?)),
2802        //   LoopStatementSegment)
2803        (
2804            "ForLoopStatementSegment".into(),
2805            NodeMatcher::new(SyntaxKind::ForLoopStatement, |_| {
2806                Sequence::new(vec![
2807                    Ref::keyword("FOR").to_matchable(),
2808                    Delimited::new(vec![
2809                        Sequence::new(vec![
2810                            Ref::new("SingleIdentifierGrammar").to_matchable(),
2811                            one_of(vec![
2812                                Ref::keyword("MUTABLE").to_matchable(),
2813                                Ref::keyword("IMMUTABLE").to_matchable(),
2814                            ])
2815                            .config(|config| {
2816                                config.optional();
2817                            })
2818                            .to_matchable(),
2819                        ])
2820                        .to_matchable(),
2821                    ])
2822                    .to_matchable(),
2823                    Ref::keyword("IN").to_matchable(),
2824                    Delimited::new(vec![
2825                        Sequence::new(vec![
2826                            Ref::keyword("REVERSE").optional().to_matchable(),
2827                            one_of(vec![
2828                                Ref::new("IterationSteppedControlGrammar").to_matchable(),
2829                                Sequence::new(vec![
2830                                    Ref::keyword("REPEAT").optional().to_matchable(),
2831                                    Ref::new("ExpressionSegment").to_matchable(),
2832                                ])
2833                                .to_matchable(),
2834                                Sequence::new(vec![
2835                                    one_of(vec![
2836                                        Ref::keyword("VALUES").to_matchable(),
2837                                        Ref::keyword("INDICES").to_matchable(),
2838                                        Ref::keyword("PAIRS").to_matchable(),
2839                                    ])
2840                                    .to_matchable(),
2841                                    Ref::keyword("OF").to_matchable(),
2842                                    Ref::new("SingleIdentifierGrammar").to_matchable(),
2843                                ])
2844                                .to_matchable(),
2845                                Bracketed::new(vec![
2846                                    Ref::new("SelectStatementSegment").to_matchable(),
2847                                ])
2848                                .to_matchable(),
2849                            ])
2850                            .to_matchable(),
2851                            Sequence::new(vec![
2852                                Ref::keyword("WHILE").to_matchable(),
2853                                Ref::new("ExpressionSegment").to_matchable(),
2854                            ])
2855                            .config(|config| {
2856                                config.optional();
2857                            })
2858                            .to_matchable(),
2859                            Sequence::new(vec![
2860                                Ref::keyword("WHEN").to_matchable(),
2861                                Ref::new("ExpressionSegment").to_matchable(),
2862                            ])
2863                            .config(|config| {
2864                                config.optional();
2865                            })
2866                            .to_matchable(),
2867                        ])
2868                        .to_matchable(),
2869                    ])
2870                    .to_matchable(),
2871                    Ref::new("LoopStatementSegment").to_matchable(),
2872                ])
2873                .to_matchable()
2874            })
2875            .to_matchable()
2876            .into(),
2877        ),
2878        // WhileLoopStatementSegment
2879        (
2880            "WhileLoopStatementSegment".into(),
2881            NodeMatcher::new(SyntaxKind::WhileLoopStatement, |_| {
2882                Sequence::new(vec![
2883                    Ref::keyword("WHILE").to_matchable(),
2884                    Ref::new("ExpressionSegment").to_matchable(),
2885                    Ref::new("LoopStatementSegment").to_matchable(),
2886                ])
2887                .to_matchable()
2888            })
2889            .to_matchable()
2890            .into(),
2891        ),
2892        // LoopStatementSegment
2893        (
2894            "LoopStatementSegment".into(),
2895            NodeMatcher::new(SyntaxKind::OracleLoopStatement, |_| {
2896                Sequence::new(vec![
2897                    Ref::keyword("LOOP").to_matchable(),
2898                    MetaSegment::indent().to_matchable(),
2899                    Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
2900                    MetaSegment::dedent().to_matchable(),
2901                    Ref::keyword("END").to_matchable(),
2902                    Ref::keyword("LOOP").to_matchable(),
2903                    Ref::new("SingleIdentifierGrammar")
2904                        .optional()
2905                        .to_matchable(),
2906                ])
2907                .to_matchable()
2908            })
2909            .to_matchable()
2910            .into(),
2911        ),
2912        // ForAllStatementSegment
2913        (
2914            "ForAllStatementSegment".into(),
2915            NodeMatcher::new(SyntaxKind::ForallStatement, |_| {
2916                Sequence::new(vec![
2917                    Ref::keyword("FORALL").to_matchable(),
2918                    Ref::new("NakedIdentifierSegment").to_matchable(),
2919                    Ref::keyword("IN").to_matchable(),
2920                    one_of(vec![
2921                        Ref::new("IterationSteppedControlGrammar").to_matchable(),
2922                        Sequence::new(vec![
2923                            Ref::keyword("VALUES").to_matchable(),
2924                            Ref::keyword("OF").to_matchable(),
2925                            Ref::new("SingleIdentifierGrammar").to_matchable(),
2926                        ])
2927                        .to_matchable(),
2928                    ])
2929                    .to_matchable(),
2930                    Sequence::new(vec![
2931                        Ref::keyword("SAVE").to_matchable(),
2932                        Ref::keyword("EXCEPTIONS").to_matchable(),
2933                    ])
2934                    .config(|config| {
2935                        config.optional();
2936                    })
2937                    .to_matchable(),
2938                    one_of(vec![
2939                        Ref::new("DeleteStatementSegment").to_matchable(),
2940                        Ref::new("InsertStatementSegment").to_matchable(),
2941                        Ref::new("UpdateStatementSegment").to_matchable(),
2942                    ])
2943                    .to_matchable(),
2944                ])
2945                .to_matchable()
2946            })
2947            .to_matchable()
2948            .into(),
2949        ),
2950        // OpenStatementSegment
2951        (
2952            "OpenStatementSegment".into(),
2953            NodeMatcher::new(SyntaxKind::OracleOpenStatement, |_| {
2954                Sequence::new(vec![
2955                    Ref::keyword("OPEN").to_matchable(),
2956                    Ref::new("SingleIdentifierGrammar").to_matchable(),
2957                    Ref::new("FunctionContentsSegment")
2958                        .optional()
2959                        .to_matchable(),
2960                ])
2961                .to_matchable()
2962            })
2963            .to_matchable()
2964            .into(),
2965        ),
2966        // CloseStatementSegment
2967        (
2968            "CloseStatementSegment".into(),
2969            NodeMatcher::new(SyntaxKind::CloseStatement, |_| {
2970                Sequence::new(vec![
2971                    Ref::keyword("CLOSE").to_matchable(),
2972                    Ref::new("SingleIdentifierGrammar").to_matchable(),
2973                ])
2974                .to_matchable()
2975            })
2976            .to_matchable()
2977            .into(),
2978        ),
2979        // OpenForStatementSegment
2980        // SQLFluff: OPEN cursor FOR select/string/ident [USING [IN|OUT|IN OUT] expr, ...]
2981        (
2982            "OpenForStatementSegment".into(),
2983            NodeMatcher::new(SyntaxKind::OracleOpenForStatement, |_| {
2984                Sequence::new(vec![
2985                    Ref::keyword("OPEN").to_matchable(),
2986                    one_of(vec![
2987                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2988                        Ref::new("SqlplusVariableGrammar").to_matchable(),
2989                    ])
2990                    .to_matchable(),
2991                    Ref::keyword("FOR").to_matchable(),
2992                    one_of(vec![
2993                        Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
2994                        Ref::new("SelectStatementSegment").to_matchable(),
2995                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2996                    ])
2997                    .to_matchable(),
2998                    Sequence::new(vec![
2999                        Ref::keyword("USING").to_matchable(),
3000                        Delimited::new(vec![
3001                            Sequence::new(vec![
3002                                one_of(vec![
3003                                    Ref::keyword("IN").to_matchable(),
3004                                    Ref::keyword("OUT").to_matchable(),
3005                                    Sequence::new(vec![
3006                                        Ref::keyword("IN").to_matchable(),
3007                                        Ref::keyword("OUT").to_matchable(),
3008                                    ])
3009                                    .to_matchable(),
3010                                ])
3011                                .config(|config| {
3012                                    config.optional();
3013                                })
3014                                .to_matchable(),
3015                                one_of(vec![
3016                                    Ref::new("SingleIdentifierGrammar").to_matchable(),
3017                                    Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
3018                                ])
3019                                .to_matchable(),
3020                            ])
3021                            .to_matchable(),
3022                        ])
3023                        .config(|config| {
3024                            config.optional();
3025                        })
3026                        .to_matchable(),
3027                    ])
3028                    .config(|config| {
3029                        config.optional();
3030                    })
3031                    .to_matchable(),
3032                ])
3033                .to_matchable()
3034            })
3035            .to_matchable()
3036            .into(),
3037        ),
3038        // FetchStatementSegment
3039        (
3040            "FetchStatementSegment".into(),
3041            NodeMatcher::new(SyntaxKind::OracleFetchStatement, |_| {
3042                Sequence::new(vec![
3043                    Ref::keyword("FETCH").to_matchable(),
3044                    Ref::new("SingleIdentifierGrammar").to_matchable(),
3045                    one_of(vec![
3046                        Ref::new("IntoClauseSegment").to_matchable(),
3047                        Sequence::new(vec![
3048                            Ref::new("BulkCollectIntoClauseSegment").to_matchable(),
3049                            Sequence::new(vec![
3050                                Ref::keyword("LIMIT").to_matchable(),
3051                                one_of(vec![
3052                                    Ref::new("NumericLiteralSegment").to_matchable(),
3053                                    Ref::new("SingleIdentifierGrammar").to_matchable(),
3054                                ])
3055                                .to_matchable(),
3056                            ])
3057                            .config(|config| {
3058                                config.optional();
3059                            })
3060                            .to_matchable(),
3061                        ])
3062                        .to_matchable(),
3063                    ])
3064                    .to_matchable(),
3065                ])
3066                .to_matchable()
3067            })
3068            .to_matchable()
3069            .into(),
3070        ),
3071        // IntoClauseSegment
3072        (
3073            "IntoClauseSegment".into(),
3074            NodeMatcher::new(SyntaxKind::OracleIntoClause, |_| {
3075                Sequence::new(vec![
3076                    Ref::keyword("INTO").to_matchable(),
3077                    Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
3078                        .to_matchable(),
3079                ])
3080                .to_matchable()
3081            })
3082            .to_matchable()
3083            .into(),
3084        ),
3085        // BulkCollectIntoClauseSegment
3086        (
3087            "BulkCollectIntoClauseSegment".into(),
3088            NodeMatcher::new(SyntaxKind::BulkCollectIntoClause, |_| {
3089                Sequence::new(vec![
3090                    Ref::keyword("BULK").to_matchable(),
3091                    Ref::keyword("COLLECT").to_matchable(),
3092                    Ref::keyword("INTO").to_matchable(),
3093                    Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
3094                        .to_matchable(),
3095                ])
3096                .to_matchable()
3097            })
3098            .to_matchable()
3099            .into(),
3100        ),
3101        // ExitStatementSegment
3102        // SQLFluff: EXIT [label] [WHEN expression]
3103        // Exclude WHEN from the optional label to prevent it being consumed as an identifier
3104        (
3105            "ExitStatementSegment".into(),
3106            NodeMatcher::new(SyntaxKind::OracleExitStatement, |_| {
3107                Sequence::new(vec![
3108                    Ref::keyword("EXIT").to_matchable(),
3109                    Ref::new("SingleIdentifierGrammar")
3110                        .exclude(Ref::keyword("WHEN"))
3111                        .optional()
3112                        .to_matchable(),
3113                    Sequence::new(vec![
3114                        Ref::keyword("WHEN").to_matchable(),
3115                        Ref::new("ExpressionSegment").to_matchable(),
3116                    ])
3117                    .config(|config| {
3118                        config.optional();
3119                    })
3120                    .to_matchable(),
3121                ])
3122                .to_matchable()
3123            })
3124            .to_matchable()
3125            .into(),
3126        ),
3127        // ContinueStatementSegment
3128        // SQLFluff: CONTINUE [label] [WHEN expression]
3129        (
3130            "ContinueStatementSegment".into(),
3131            NodeMatcher::new(SyntaxKind::ContinueStatement, |_| {
3132                Sequence::new(vec![
3133                    Ref::keyword("CONTINUE").to_matchable(),
3134                    Ref::new("SingleIdentifierGrammar")
3135                        .exclude(Ref::keyword("WHEN"))
3136                        .optional()
3137                        .to_matchable(),
3138                    Sequence::new(vec![
3139                        Ref::keyword("WHEN").to_matchable(),
3140                        Ref::new("ExpressionSegment").to_matchable(),
3141                    ])
3142                    .config(|config| {
3143                        config.optional();
3144                    })
3145                    .to_matchable(),
3146                ])
3147                .to_matchable()
3148            })
3149            .to_matchable()
3150            .into(),
3151        ),
3152        // RaiseStatementSegment
3153        (
3154            "RaiseStatementSegment".into(),
3155            NodeMatcher::new(SyntaxKind::RaiseStatement, |_| {
3156                Sequence::new(vec![
3157                    Ref::keyword("RAISE").to_matchable(),
3158                    Ref::new("SingleIdentifierGrammar")
3159                        .optional()
3160                        .to_matchable(),
3161                ])
3162                .to_matchable()
3163            })
3164            .to_matchable()
3165            .into(),
3166        ),
3167        // ReturnStatementSegment
3168        (
3169            "ReturnStatementSegment".into(),
3170            NodeMatcher::new(SyntaxKind::OracleReturnStatement, |_| {
3171                Sequence::new(vec![
3172                    Ref::keyword("RETURN").to_matchable(),
3173                    Ref::new("ExpressionSegment").optional().to_matchable(),
3174                ])
3175                .to_matchable()
3176            })
3177            .to_matchable()
3178            .into(),
3179        ),
3180        // ReturningClauseSegment
3181        (
3182            "ReturningClauseSegment".into(),
3183            NodeMatcher::new(SyntaxKind::OracleReturningClause, |_| {
3184                Sequence::new(vec![
3185                    one_of(vec![
3186                        Ref::keyword("RETURNING").to_matchable(),
3187                        Ref::keyword("RETURN").to_matchable(),
3188                    ])
3189                    .to_matchable(),
3190                    Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
3191                        .to_matchable(),
3192                    one_of(vec![
3193                        Ref::new("IntoClauseSegment").to_matchable(),
3194                        Ref::new("BulkCollectIntoClauseSegment").to_matchable(),
3195                    ])
3196                    .to_matchable(),
3197                ])
3198                .to_matchable()
3199            })
3200            .to_matchable()
3201            .into(),
3202        ),
3203        // ValuesClauseSegment
3204        (
3205            "ValuesClauseSegment".into(),
3206            NodeMatcher::new(SyntaxKind::OracleValuesClause, |_| {
3207                Sequence::new(vec![
3208                    one_of(vec![
3209                        Ref::keyword("VALUE").to_matchable(),
3210                        Ref::keyword("VALUES").to_matchable(),
3211                    ])
3212                    .to_matchable(),
3213                    optionally_bracketed(vec![
3214                        Delimited::new(vec![
3215                            Ref::keyword("DEFAULT").to_matchable(),
3216                            Ref::new("LiteralGrammar").to_matchable(),
3217                            Ref::new("ExpressionSegment").to_matchable(),
3218                        ])
3219                        .to_matchable(),
3220                    ])
3221                    .to_matchable(),
3222                ])
3223                .to_matchable()
3224            })
3225            .to_matchable()
3226            .into(),
3227        ),
3228        // DatabaseLinkReferenceSegment
3229        (
3230            "DatabaseLinkReferenceSegment".into(),
3231            NodeMatcher::new(SyntaxKind::DatabaseLinkReference, |_| {
3232                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
3233                    .config(|config| {
3234                        config.delimiter(Ref::new("DotSegment"));
3235                    })
3236                    .to_matchable()
3237            })
3238            .to_matchable()
3239            .into(),
3240        ),
3241        // CreateDatabaseLinkStatementSegment
3242        (
3243            "CreateDatabaseLinkStatementSegment".into(),
3244            NodeMatcher::new(SyntaxKind::OracleCreateDatabaseLinkStatement, |_| {
3245                Sequence::new(vec![
3246                    Ref::keyword("CREATE").to_matchable(),
3247                    Ref::keyword("SHARED").optional().to_matchable(),
3248                    Ref::keyword("PUBLIC").optional().to_matchable(),
3249                    Ref::keyword("DATABASE").to_matchable(),
3250                    Ref::keyword("LINK").to_matchable(),
3251                    Ref::new("DatabaseLinkReferenceSegment").to_matchable(),
3252                    Sequence::new(vec![
3253                        Ref::keyword("CONNECT").to_matchable(),
3254                        Ref::keyword("TO").to_matchable(),
3255                        one_of(vec![
3256                            Ref::keyword("CURRENT_USER").to_matchable(),
3257                            Sequence::new(vec![
3258                                Ref::new("RoleReferenceSegment").to_matchable(),
3259                                Ref::keyword("IDENTIFIED").to_matchable(),
3260                                Ref::keyword("BY").to_matchable(),
3261                                Ref::new("SingleIdentifierGrammar").to_matchable(),
3262                            ])
3263                            .to_matchable(),
3264                        ])
3265                        .to_matchable(),
3266                    ])
3267                    .config(|config| {
3268                        config.optional();
3269                    })
3270                    .to_matchable(),
3271                    Sequence::new(vec![
3272                        Ref::keyword("USING").to_matchable(),
3273                        Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
3274                    ])
3275                    .config(|config| {
3276                        config.optional();
3277                    })
3278                    .to_matchable(),
3279                ])
3280                .to_matchable()
3281            })
3282            .to_matchable()
3283            .into(),
3284        ),
3285        // DropDatabaseLinkStatementSegment
3286        (
3287            "DropDatabaseLinkStatementSegment".into(),
3288            NodeMatcher::new(SyntaxKind::OracleDropDatabaseLinkStatement, |_| {
3289                Sequence::new(vec![
3290                    Ref::keyword("DROP").to_matchable(),
3291                    Ref::keyword("PUBLIC").optional().to_matchable(),
3292                    Ref::keyword("DATABASE").to_matchable(),
3293                    Ref::keyword("LINK").to_matchable(),
3294                    Ref::new("DatabaseLinkReferenceSegment").to_matchable(),
3295                ])
3296                .to_matchable()
3297            })
3298            .to_matchable()
3299            .into(),
3300        ),
3301        // AlterDatabaseLinkStatementSegment
3302        (
3303            "AlterDatabaseLinkStatementSegment".into(),
3304            NodeMatcher::new(SyntaxKind::OracleAlterDatabaseLinkStatement, |_| {
3305                Sequence::new(vec![
3306                    Ref::keyword("ALTER").to_matchable(),
3307                    Ref::keyword("SHARED").optional().to_matchable(),
3308                    Ref::keyword("PUBLIC").optional().to_matchable(),
3309                    Ref::keyword("DATABASE").to_matchable(),
3310                    Ref::keyword("LINK").to_matchable(),
3311                    Ref::new("DatabaseLinkReferenceSegment").to_matchable(),
3312                    Sequence::new(vec![
3313                        Ref::keyword("CONNECT").to_matchable(),
3314                        Ref::keyword("TO").to_matchable(),
3315                        Ref::new("RoleReferenceSegment").to_matchable(),
3316                        Ref::keyword("IDENTIFIED").to_matchable(),
3317                        Ref::keyword("BY").to_matchable(),
3318                        Ref::new("SingleIdentifierGrammar").to_matchable(),
3319                    ])
3320                    .to_matchable(),
3321                ])
3322                .to_matchable()
3323            })
3324            .to_matchable()
3325            .into(),
3326        ),
3327        // CreateSynonymStatementSegment
3328        (
3329            "CreateSynonymStatementSegment".into(),
3330            NodeMatcher::new(SyntaxKind::OracleCreateSynonymStatement, |_| {
3331                Sequence::new(vec![
3332                    Ref::keyword("CREATE").to_matchable(),
3333                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
3334                    Ref::keyword("PUBLIC").optional().to_matchable(),
3335                    Ref::keyword("SYNONYM").to_matchable(),
3336                    Ref::new("ObjectReferenceSegment").to_matchable(),
3337                    Ref::keyword("FOR").to_matchable(),
3338                    Ref::new("ObjectReferenceSegment").to_matchable(),
3339                    Sequence::new(vec![
3340                        Ref::new("AtSignSegment").to_matchable(),
3341                        Ref::new("DatabaseLinkReferenceSegment").to_matchable(),
3342                    ])
3343                    .config(|config| {
3344                        config.optional();
3345                    })
3346                    .to_matchable(),
3347                ])
3348                .to_matchable()
3349            })
3350            .to_matchable()
3351            .into(),
3352        ),
3353        // DropSynonymStatementSegment
3354        (
3355            "DropSynonymStatementSegment".into(),
3356            NodeMatcher::new(SyntaxKind::OracleDropSynonymStatement, |_| {
3357                Sequence::new(vec![
3358                    Ref::keyword("DROP").to_matchable(),
3359                    Ref::keyword("PUBLIC").optional().to_matchable(),
3360                    Ref::keyword("SYNONYM").to_matchable(),
3361                    Ref::new("ObjectReferenceSegment").to_matchable(),
3362                    Ref::keyword("FORCE").optional().to_matchable(),
3363                ])
3364                .to_matchable()
3365            })
3366            .to_matchable()
3367            .into(),
3368        ),
3369        // AlterSynonymStatementSegment
3370        (
3371            "AlterSynonymStatementSegment".into(),
3372            NodeMatcher::new(SyntaxKind::OracleAlterSynonymStatement, |_| {
3373                Sequence::new(vec![
3374                    Ref::keyword("ALTER").to_matchable(),
3375                    Ref::keyword("PUBLIC").optional().to_matchable(),
3376                    Ref::keyword("SYNONYM").to_matchable(),
3377                    Ref::new("ObjectReferenceSegment").to_matchable(),
3378                    one_of(vec![
3379                        Ref::keyword("EDITIONABLE").to_matchable(),
3380                        Ref::keyword("NONEDITIONABLE").to_matchable(),
3381                        Ref::keyword("COMPILE").to_matchable(),
3382                    ])
3383                    .to_matchable(),
3384                ])
3385                .to_matchable()
3386            })
3387            .to_matchable()
3388            .into(),
3389        ),
3390    ]);
3391
3392    // ---- Grammar replacements ----
3393    oracle.replace_grammar(
3394        "TemporaryGrammar",
3395        Sequence::new(vec![
3396            one_of(vec![
3397                Ref::keyword("GLOBAL").to_matchable(),
3398                Ref::keyword("PRIVATE").to_matchable(),
3399            ])
3400            .to_matchable(),
3401            Ref::keyword("TEMPORARY").to_matchable(),
3402        ])
3403        .config(|config| {
3404            config.optional();
3405        })
3406        .to_matchable(),
3407    );
3408
3409    oracle.replace_grammar(
3410        "DropBehaviorGrammar",
3411        Sequence::new(vec![
3412            Sequence::new(vec![
3413                Ref::keyword("CASCADE").to_matchable(),
3414                Ref::keyword("CONSTRAINTS").to_matchable(),
3415            ])
3416            .config(|config| {
3417                config.optional();
3418            })
3419            .to_matchable(),
3420            Ref::keyword("PURGE").optional().to_matchable(),
3421        ])
3422        .config(|config| {
3423            config.optional();
3424        })
3425        .to_matchable(),
3426    );
3427
3428    oracle.replace_grammar(
3429        "PostFunctionGrammar",
3430        AnyNumberOf::new(vec![
3431            Ref::new("WithinGroupClauseSegment").to_matchable(),
3432            Ref::new("FilterClauseGrammar").to_matchable(),
3433            Ref::new("OverClauseSegment").optional().to_matchable(),
3434        ])
3435        .to_matchable(),
3436    );
3437
3438    oracle.replace_grammar(
3439        "FunctionContentsExpressionGrammar",
3440        one_of(vec![
3441            Ref::new("ExpressionSegment").to_matchable(),
3442            Ref::new("NamedArgumentSegment").to_matchable(),
3443        ])
3444        .to_matchable(),
3445    );
3446
3447    oracle.replace_grammar(
3448        "DateTimeLiteralGrammar",
3449        Sequence::new(vec![
3450            one_of(vec![
3451                Ref::keyword("DATE").to_matchable(),
3452                Ref::keyword("TIME").to_matchable(),
3453                Ref::keyword("TIMESTAMP").to_matchable(),
3454                Ref::keyword("INTERVAL").to_matchable(),
3455            ])
3456            .to_matchable(),
3457            Ref::new("QuotedLiteralSegment").to_matchable(),
3458            Sequence::new(vec![
3459                Ref::new("IntervalUnitsGrammar").to_matchable(),
3460                Sequence::new(vec![
3461                    Ref::keyword("TO").to_matchable(),
3462                    Ref::new("IntervalUnitsGrammar").to_matchable(),
3463                ])
3464                .config(|config| {
3465                    config.optional();
3466                })
3467                .to_matchable(),
3468            ])
3469            .config(|config| {
3470                config.optional();
3471            })
3472            .to_matchable(),
3473        ])
3474        .to_matchable(),
3475    );
3476
3477    oracle.replace_grammar(
3478        "PreTableFunctionKeywordsGrammar",
3479        one_of(vec![Ref::keyword("LATERAL").to_matchable()]).to_matchable(),
3480    );
3481
3482    oracle.replace_grammar(
3483        "ConditionalCrossJoinKeywordsGrammar",
3484        Nothing::new().to_matchable(),
3485    );
3486
3487    oracle.replace_grammar(
3488        "UnconditionalCrossJoinKeywordsGrammar",
3489        Ref::keyword("CROSS").to_matchable(),
3490    );
3491
3492    oracle.replace_grammar(
3493        "FunctionParameterGrammar",
3494        Sequence::new(vec![
3495            Ref::new("ParameterNameSegment").to_matchable(),
3496            one_of(vec![
3497                Sequence::new(vec![
3498                    Ref::keyword("IN").optional().to_matchable(),
3499                    one_of(vec![
3500                        Ref::new("DatatypeSegment").to_matchable(),
3501                        Ref::new("ColumnTypeReferenceSegment").to_matchable(),
3502                        Ref::new("RowTypeReferenceSegment").to_matchable(),
3503                    ])
3504                    .to_matchable(),
3505                    Sequence::new(vec![
3506                        one_of(vec![
3507                            Ref::new("AssignmentOperatorSegment").to_matchable(),
3508                            Ref::keyword("DEFAULT").to_matchable(),
3509                        ])
3510                        .to_matchable(),
3511                        Ref::new("ExpressionSegment").to_matchable(),
3512                    ])
3513                    .config(|config| {
3514                        config.optional();
3515                    })
3516                    .to_matchable(),
3517                ])
3518                .to_matchable(),
3519                Sequence::new(vec![
3520                    Ref::keyword("IN").optional().to_matchable(),
3521                    Ref::keyword("OUT").to_matchable(),
3522                    Ref::keyword("NOCOPY").optional().to_matchable(),
3523                    one_of(vec![
3524                        Ref::new("DatatypeSegment").to_matchable(),
3525                        Ref::new("ColumnTypeReferenceSegment").to_matchable(),
3526                        Ref::new("RowTypeReferenceSegment").to_matchable(),
3527                    ])
3528                    .to_matchable(),
3529                ])
3530                .to_matchable(),
3531            ])
3532            .to_matchable(),
3533        ])
3534        .to_matchable(),
3535    );
3536
3537    oracle.replace_grammar(
3538        "SequenceMinValueGrammar",
3539        one_of(vec![
3540            Sequence::new(vec![
3541                Ref::keyword("MINVALUE").to_matchable(),
3542                Ref::new("NumericLiteralSegment").to_matchable(),
3543            ])
3544            .to_matchable(),
3545            Ref::keyword("NOMINVALUE").to_matchable(),
3546        ])
3547        .to_matchable(),
3548    );
3549
3550    oracle.replace_grammar(
3551        "SequenceMaxValueGrammar",
3552        one_of(vec![
3553            Sequence::new(vec![
3554                Ref::keyword("MAXVALUE").to_matchable(),
3555                Ref::new("NumericLiteralSegment").to_matchable(),
3556            ])
3557            .to_matchable(),
3558            Ref::keyword("NOMAXVALUE").to_matchable(),
3559        ])
3560        .to_matchable(),
3561    );
3562
3563    // ---- Override FileSegment for Oracle batch (/) and @file support ----
3564    // SQLFluff: FileSegment.match_grammar = Sequence(AnyNumberOf(Ref("BatchSegment"), Ref("ExecuteFileSegment")))
3565    oracle.replace_grammar(
3566        "FileSegment",
3567        AnyNumberOf::new(vec![
3568            one_of(vec![
3569                Ref::new("BatchSegment").to_matchable(),
3570                Ref::new("ExecuteFileSegment").to_matchable(),
3571            ])
3572            .to_matchable(),
3573        ])
3574        .to_matchable(),
3575    );
3576
3577    // ---- BatchSegment ----
3578    oracle.add([(
3579        "BatchSegment".into(),
3580        NodeMatcher::new(SyntaxKind::OracleBatch, |_| {
3581            one_of(vec![
3582                Sequence::new(vec![
3583                    Delimited::new(vec![Ref::new("StatementSegment").to_matchable()])
3584                        .config(|this| {
3585                            this.allow_trailing();
3586                            this.delimiter(
3587                                AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()])
3588                                    .config(|config| config.min_times(1)),
3589                            );
3590                        })
3591                        .to_matchable(),
3592                    Ref::new("BatchDelimiterGrammar").optional().to_matchable(),
3593                ])
3594                .to_matchable(),
3595                Ref::new("BatchDelimiterGrammar").to_matchable(),
3596            ])
3597            .to_matchable()
3598        })
3599        .to_matchable()
3600        .into(),
3601    )]);
3602
3603    // ---- ExecuteFileSegment ----
3604    oracle.add([(
3605        "ExecuteFileSegment".into(),
3606        NodeMatcher::new(SyntaxKind::ExecuteFileStatement, |_| {
3607            Sequence::new(vec![
3608                one_of(vec![
3609                    Sequence::new(vec![
3610                        Ref::new("AtSignSegment").to_matchable(),
3611                        Ref::new("AtSignSegment").optional().to_matchable(),
3612                    ])
3613                    .to_matchable(),
3614                    Ref::keyword("START").to_matchable(),
3615                ])
3616                .to_matchable(),
3617                AnyNumberOf::new(vec![
3618                    Ref::new("SingleIdentifierGrammar").to_matchable(),
3619                    Ref::new("DotSegment").to_matchable(),
3620                    Ref::new("SlashSegment").to_matchable(),
3621                ])
3622                .to_matchable(),
3623            ])
3624            .to_matchable()
3625        })
3626        .to_matchable()
3627        .into(),
3628    )]);
3629
3630    // ---- Override StatementSegment to include Oracle-specific statements ----
3631    // SQLFluff: ansi.StatementSegment.match_grammar.copy(insert=[...])
3632    // Uses copy() to append Oracle statements to the ANSI one_of list.
3633    oracle.replace_grammar(
3634        "StatementSegment",
3635        ansi::statement_segment().copy(
3636            Some(vec![
3637                Ref::new("CommentStatementSegment").to_matchable(),
3638                Ref::new("CreateProcedureStatementSegment").to_matchable(),
3639                Ref::new("DropProcedureStatementSegment").to_matchable(),
3640                Ref::new("AlterFunctionStatementSegment").to_matchable(),
3641                Ref::new("CreateTypeStatementSegment").to_matchable(),
3642                Ref::new("CreateTypeBodyStatementSegment").to_matchable(),
3643                Ref::new("CreatePackageStatementSegment").to_matchable(),
3644                Ref::new("AlterSessionStatementSegment").to_matchable(),
3645                Ref::new("DropPackageStatementSegment").to_matchable(),
3646                Ref::new("AlterPackageStatementSegment").to_matchable(),
3647                Ref::new("AlterTriggerStatementSegment").to_matchable(),
3648                Ref::new("BeginEndSegment").to_matchable(),
3649                Ref::new("AssignmentStatementSegment").to_matchable(),
3650                Ref::new("RecordTypeDefinitionSegment").to_matchable(),
3651                Ref::new("DeclareCursorVariableSegment").to_matchable(),
3652                Ref::new("ExecuteImmediateSegment").to_matchable(),
3653                Ref::new("FunctionSegment").to_matchable(),
3654                Ref::new("IfExpressionStatement").to_matchable(),
3655                Ref::new("CaseExpressionSegment").to_matchable(),
3656                Ref::new("NullStatementSegment").to_matchable(),
3657                Ref::new("ForLoopStatementSegment").to_matchable(),
3658                Ref::new("WhileLoopStatementSegment").to_matchable(),
3659                Ref::new("LoopStatementSegment").to_matchable(),
3660                Ref::new("ForAllStatementSegment").to_matchable(),
3661                Ref::new("OpenStatementSegment").to_matchable(),
3662                Ref::new("CloseStatementSegment").to_matchable(),
3663                Ref::new("OpenForStatementSegment").to_matchable(),
3664                Ref::new("FetchStatementSegment").to_matchable(),
3665                Ref::new("ExitStatementSegment").to_matchable(),
3666                Ref::new("ContinueStatementSegment").to_matchable(),
3667                Ref::new("RaiseStatementSegment").to_matchable(),
3668                Ref::new("ReturnStatementSegment").to_matchable(),
3669                Ref::new("AlterIndexStatementSegment").to_matchable(),
3670                Ref::new("CreateDatabaseLinkStatementSegment").to_matchable(),
3671                Ref::new("DropDatabaseLinkStatementSegment").to_matchable(),
3672                Ref::new("AlterDatabaseLinkStatementSegment").to_matchable(),
3673                Ref::new("CreateSynonymStatementSegment").to_matchable(),
3674                Ref::new("DropSynonymStatementSegment").to_matchable(),
3675                Ref::new("AlterSynonymStatementSegment").to_matchable(),
3676            ]),
3677            None,
3678            None,
3679            None,
3680            vec![],
3681            false,
3682        ),
3683    );
3684
3685    // ---- Override UnorderedSelectStatementSegment ----
3686    // SQLFluff inserts HierarchicalQueryClause, Pivot, Unpivot before GroupBy,
3687    // and IntoClause/BulkCollectIntoClause before From.
3688    oracle.replace_grammar(
3689        "UnorderedSelectStatementSegment",
3690        Sequence::new(vec![
3691            Ref::new("SelectClauseSegment").to_matchable(),
3692            MetaSegment::dedent().to_matchable(),
3693            one_of(vec![
3694                Ref::new("IntoClauseSegment").to_matchable(),
3695                Ref::new("BulkCollectIntoClauseSegment").to_matchable(),
3696            ])
3697            .config(|config| {
3698                config.optional();
3699            })
3700            .to_matchable(),
3701            Ref::new("FromClauseSegment").optional().to_matchable(),
3702            Ref::new("WhereClauseSegment").optional().to_matchable(),
3703            Ref::new("HierarchicalQueryClauseSegment")
3704                .optional()
3705                .to_matchable(),
3706            Ref::new("PivotSegment").optional().to_matchable(),
3707            Ref::new("UnpivotSegment").optional().to_matchable(),
3708            Ref::new("GroupByClauseSegment").optional().to_matchable(),
3709            Ref::new("HavingClauseSegment").optional().to_matchable(),
3710            Ref::new("OverlapsClauseSegment").optional().to_matchable(),
3711            Ref::new("NamedWindowSegment").optional().to_matchable(),
3712        ])
3713        .terminators(vec![
3714            Ref::new("SetOperatorSegment").to_matchable(),
3715            Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
3716            Ref::new("WithDataClauseSegment").to_matchable(),
3717            Ref::new("OrderByClauseSegment").to_matchable(),
3718            Ref::new("LimitClauseSegment").to_matchable(),
3719            Ref::new("HierarchicalQueryClauseSegment").to_matchable(),
3720            Ref::new("PivotSegment").to_matchable(),
3721            Ref::new("UnpivotSegment").to_matchable(),
3722            Ref::keyword("LOG").to_matchable(),
3723        ])
3724        .config(|this| {
3725            this.parse_mode(ParseMode::GreedyOnceStarted);
3726        })
3727        .to_matchable(),
3728    );
3729
3730    // ---- Override SelectStatementSegment ----
3731    // SQLFluff adds FOR UPDATE, ORDER BY, FETCH, LIMIT on top of the unordered grammar.
3732    oracle.replace_grammar(
3733        "SelectStatementSegment",
3734        Sequence::new(vec![
3735            Ref::new("SelectClauseSegment").to_matchable(),
3736            MetaSegment::dedent().to_matchable(),
3737            one_of(vec![
3738                Ref::new("IntoClauseSegment").to_matchable(),
3739                Ref::new("BulkCollectIntoClauseSegment").to_matchable(),
3740            ])
3741            .config(|config| {
3742                config.optional();
3743            })
3744            .to_matchable(),
3745            Ref::new("FromClauseSegment").optional().to_matchable(),
3746            Ref::new("WhereClauseSegment").optional().to_matchable(),
3747            Ref::new("HierarchicalQueryClauseSegment")
3748                .optional()
3749                .to_matchable(),
3750            Ref::new("PivotSegment").optional().to_matchable(),
3751            Ref::new("UnpivotSegment").optional().to_matchable(),
3752            Ref::new("GroupByClauseSegment").optional().to_matchable(),
3753            Ref::new("HavingClauseSegment").optional().to_matchable(),
3754            Ref::new("OverlapsClauseSegment").optional().to_matchable(),
3755            Ref::new("ForUpdateGrammar").optional().to_matchable(),
3756            Ref::new("OrderByClauseSegment").optional().to_matchable(),
3757            Ref::new("FetchClauseSegment").optional().to_matchable(),
3758            Ref::new("LimitClauseSegment").optional().to_matchable(),
3759            Ref::new("NamedWindowSegment").optional().to_matchable(),
3760            Ref::new("ForUpdateGrammar").optional().to_matchable(),
3761        ])
3762        .terminators(vec![
3763            Ref::new("SetOperatorSegment").to_matchable(),
3764            Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
3765            Ref::new("WithDataClauseSegment").to_matchable(),
3766            Ref::keyword("LOG").to_matchable(),
3767        ])
3768        .config(|this| {
3769            this.parse_mode(ParseMode::GreedyOnceStarted);
3770        })
3771        .to_matchable(),
3772    );
3773
3774    // ---- Override ArithmeticBinaryOperatorGrammar to add MOD and ** ----
3775    oracle.replace_grammar(
3776        "ArithmeticBinaryOperatorGrammar",
3777        one_of(vec![
3778            Ref::new("PlusSegment").to_matchable(),
3779            Ref::new("MinusSegment").to_matchable(),
3780            Ref::new("DivideSegment").to_matchable(),
3781            Ref::new("MultiplySegment").to_matchable(),
3782            Ref::new("ModuloSegment").to_matchable(),
3783            Ref::new("BitwiseAndSegment").to_matchable(),
3784            Ref::new("BitwiseOrSegment").to_matchable(),
3785            Ref::new("BitwiseXorSegment").to_matchable(),
3786            Ref::new("BitwiseLShiftSegment").to_matchable(),
3787            Ref::new("BitwiseRShiftSegment").to_matchable(),
3788            Ref::new("ModOperatorSegment").to_matchable(),
3789            Ref::new("PowerOperatorSegment").to_matchable(),
3790        ])
3791        .to_matchable(),
3792    );
3793
3794    // ---- Expression_D_Grammar ----
3795    // SQLFluff: Completely rewritten for Oracle with PlusJoinGrammar, subscript access,
3796    // trigger correlation references, implicit cursor attributes, etc.
3797    oracle.replace_grammar(
3798        "Expression_D_Grammar",
3799        Sequence::new(vec![
3800            one_of(vec![
3801                Ref::new("BareFunctionSegment").to_matchable(),
3802                Ref::new("FunctionSegment").to_matchable(),
3803                Ref::new("TriggerCorrelationReferenceSegment").to_matchable(),
3804                Bracketed::new(vec![
3805                    one_of(vec![
3806                        Ref::new("ExpressionSegment").to_matchable(),
3807                        Ref::new("SelectableGrammar").to_matchable(),
3808                        Delimited::new(vec![
3809                            Ref::new("ColumnReferenceSegment").to_matchable(),
3810                            Ref::new("FunctionSegment").to_matchable(),
3811                            Ref::new("LiteralGrammar").to_matchable(),
3812                        ])
3813                        .to_matchable(),
3814                    ])
3815                    .to_matchable(),
3816                ])
3817                .config(|config| {
3818                    config.parse_mode(ParseMode::Greedy);
3819                })
3820                .to_matchable(),
3821                Ref::new("SelectStatementSegment").to_matchable(),
3822                Ref::new("LiteralGrammar").to_matchable(),
3823                Ref::new("IntervalExpressionSegment").to_matchable(),
3824                Ref::new("TypedStructLiteralSegment").to_matchable(),
3825                Ref::new("ArrayExpressionSegment").to_matchable(),
3826                Ref::new("ColumnReferenceSegment").to_matchable(),
3827                // NEW.* / OLD.* for triggers
3828                Sequence::new(vec![
3829                    Ref::new("SingleIdentifierGrammar").to_matchable(),
3830                    Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(),
3831                    Ref::new("StarSegment").to_matchable(),
3832                ])
3833                .to_matchable(),
3834                Sequence::new(vec![
3835                    Ref::new("DatatypeSegment").to_matchable(),
3836                    one_of(vec![
3837                        Ref::new("QuotedLiteralSegment").to_matchable(),
3838                        Ref::new("NumericLiteralSegment").to_matchable(),
3839                        Ref::new("BooleanLiteralGrammar").to_matchable(),
3840                        Ref::new("NullLiteralSegment").to_matchable(),
3841                        Ref::new("DateTimeLiteralGrammar").to_matchable(),
3842                    ])
3843                    .to_matchable(),
3844                ])
3845                .to_matchable(),
3846                Ref::new("SqlplusSubstitutionVariableSegment").to_matchable(),
3847                Ref::new("ImplicitCursorAttributesGrammar").to_matchable(),
3848                // ObjectReference with optional subscript and trailing dot (PL/SQL array access)
3849                Sequence::new(vec![
3850                    Ref::new("ObjectReferenceSegment").to_matchable(),
3851                    Bracketed::new(vec![
3852                        one_of(vec![
3853                            Ref::new("ObjectReferenceSegment").to_matchable(),
3854                            Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
3855                            Ref::new("NumericLiteralSegment").to_matchable(),
3856                        ])
3857                        .to_matchable(),
3858                    ])
3859                    .config(|config| {
3860                        config.optional();
3861                    })
3862                    .to_matchable(),
3863                    Ref::new("DotSegment").optional().to_matchable(),
3864                ])
3865                .to_matchable(),
3866            ])
3867            .config(|config| {
3868                config.terminators = vec![Ref::new("CommaSegment").to_matchable()];
3869            })
3870            .to_matchable(),
3871            Ref::new("AccessorGrammar").optional().to_matchable(),
3872        ])
3873        .to_matchable(),
3874    );
3875
3876    // ---- FromClauseTerminatorGrammar ----
3877    // Add FOR (for FOR UPDATE), CONNECT, START, PIVOT, UNPIVOT as FROM clause terminators
3878    oracle.replace_grammar(
3879        "FromClauseTerminatorGrammar",
3880        one_of(vec![
3881            Ref::keyword("WHERE").to_matchable(),
3882            Ref::keyword("LIMIT").to_matchable(),
3883            Sequence::new(vec![
3884                Ref::keyword("GROUP").to_matchable(),
3885                Ref::keyword("BY").to_matchable(),
3886            ])
3887            .to_matchable(),
3888            Sequence::new(vec![
3889                Ref::keyword("ORDER").to_matchable(),
3890                Ref::keyword("BY").to_matchable(),
3891            ])
3892            .to_matchable(),
3893            Ref::keyword("HAVING").to_matchable(),
3894            Ref::keyword("QUALIFY").to_matchable(),
3895            Ref::keyword("WINDOW").to_matchable(),
3896            Ref::new("SetOperatorSegment").to_matchable(),
3897            Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
3898            Ref::new("WithDataClauseSegment").to_matchable(),
3899            Ref::keyword("FETCH").to_matchable(),
3900            // Oracle-specific additions
3901            Sequence::new(vec![
3902                Ref::keyword("FOR").to_matchable(),
3903                Ref::keyword("UPDATE").to_matchable(),
3904            ])
3905            .to_matchable(),
3906            Sequence::new(vec![
3907                Ref::keyword("CONNECT").to_matchable(),
3908                Ref::keyword("BY").to_matchable(),
3909            ])
3910            .to_matchable(),
3911            Sequence::new(vec![
3912                Ref::keyword("START").to_matchable(),
3913                Ref::keyword("WITH").to_matchable(),
3914            ])
3915            .to_matchable(),
3916            Ref::keyword("PIVOT").to_matchable(),
3917            Ref::keyword("UNPIVOT").to_matchable(),
3918        ])
3919        .to_matchable(),
3920    );
3921
3922    // ---- WhereClauseTerminatorGrammar ----
3923    // Add FOR UPDATE, CONNECT BY, START WITH, PIVOT, UNPIVOT
3924    oracle.replace_grammar(
3925        "WhereClauseTerminatorGrammar",
3926        one_of(vec![
3927            Ref::keyword("LIMIT").to_matchable(),
3928            Sequence::new(vec![
3929                Ref::keyword("GROUP").to_matchable(),
3930                Ref::keyword("BY").to_matchable(),
3931            ])
3932            .to_matchable(),
3933            Sequence::new(vec![
3934                Ref::keyword("ORDER").to_matchable(),
3935                Ref::keyword("BY").to_matchable(),
3936            ])
3937            .to_matchable(),
3938            Ref::keyword("HAVING").to_matchable(),
3939            Ref::keyword("QUALIFY").to_matchable(),
3940            Ref::keyword("WINDOW").to_matchable(),
3941            Ref::keyword("OVERLAPS").to_matchable(),
3942            Ref::keyword("FETCH").to_matchable(),
3943            // Oracle-specific additions
3944            Sequence::new(vec![
3945                Ref::keyword("FOR").to_matchable(),
3946                Ref::keyword("UPDATE").to_matchable(),
3947            ])
3948            .to_matchable(),
3949            Sequence::new(vec![
3950                Ref::keyword("CONNECT").to_matchable(),
3951                Ref::keyword("BY").to_matchable(),
3952            ])
3953            .to_matchable(),
3954            Sequence::new(vec![
3955                Ref::keyword("START").to_matchable(),
3956                Ref::keyword("WITH").to_matchable(),
3957            ])
3958            .to_matchable(),
3959            Ref::keyword("PIVOT").to_matchable(),
3960            Ref::keyword("UNPIVOT").to_matchable(),
3961        ])
3962        .to_matchable(),
3963    );
3964
3965    // ---- LiteralGrammar ----
3966    // SQLFluff inserts TriggerCorrelationReferenceSegment, SqlplusVariableGrammar,
3967    // LEVEL, ROWNUM, ANY before ArrayLiteralSegment.
3968    oracle.replace_grammar(
3969        "LiteralGrammar",
3970        one_of(vec![
3971            Ref::new("QuotedLiteralSegment").to_matchable(),
3972            Ref::new("NumericLiteralSegment").to_matchable(),
3973            Ref::new("BooleanLiteralGrammar").to_matchable(),
3974            Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
3975            Ref::new("NullLiteralSegment").to_matchable(),
3976            Ref::new("DateTimeLiteralGrammar").to_matchable(),
3977            // Oracle-specific additions
3978            Ref::new("TriggerCorrelationReferenceSegment").to_matchable(),
3979            Ref::new("SqlplusVariableGrammar").to_matchable(),
3980            Ref::keyword("LEVEL").to_matchable(),
3981            Ref::keyword("ROWNUM").to_matchable(),
3982            Ref::keyword("ANY").to_matchable(),
3983            // ANSI items continued
3984            Ref::new("ArrayLiteralSegment").to_matchable(),
3985            Ref::new("TypedArrayLiteralSegment").to_matchable(),
3986            Ref::new("ObjectLiteralSegment").to_matchable(),
3987        ])
3988        .to_matchable(),
3989    );
3990
3991    // ---- ColumnConstraintDefaultGrammar ----
3992    // SQLFluff: OneOf(ansi_dialect.get_grammar("ColumnConstraintDefaultGrammar"), Ref("SequenceNextValGrammar"))
3993    oracle.replace_grammar(
3994        "ColumnConstraintDefaultGrammar",
3995        one_of(vec![
3996            Ref::new("ShorthandCastSegment").to_matchable(),
3997            Ref::new("LiteralGrammar").to_matchable(),
3998            Ref::new("FunctionSegment").to_matchable(),
3999            Ref::new("BareFunctionSegment").to_matchable(),
4000            Ref::new("ExpressionSegment").to_matchable(),
4001            Ref::new("SequenceNextValGrammar").to_matchable(),
4002        ])
4003        .to_matchable(),
4004    );
4005
4006    // ---- SelectClauseTerminatorGrammar ----
4007    // SQLFluff adds BULK, INTO, FETCH as terminators
4008    oracle.replace_grammar(
4009        "SelectClauseTerminatorGrammar",
4010        one_of(vec![
4011            Ref::keyword("BULK").to_matchable(),
4012            Ref::keyword("INTO").to_matchable(),
4013            Ref::new("FromClauseSegment").to_matchable(),
4014            Ref::keyword("WHERE").to_matchable(),
4015            Sequence::new(vec![
4016                Ref::keyword("ORDER").to_matchable(),
4017                Ref::keyword("BY").to_matchable(),
4018            ])
4019            .to_matchable(),
4020            Ref::keyword("LIMIT").to_matchable(),
4021            Ref::keyword("OVERLAPS").to_matchable(),
4022            Ref::new("SetOperatorSegment").to_matchable(),
4023            Ref::keyword("FETCH").to_matchable(),
4024        ])
4025        .to_matchable(),
4026    );
4027
4028    // ---- UpdateStatementSegment: add RETURNING clause ----
4029    // SQLFluff: ansi.UpdateStatementSegment.match_grammar.copy(insert=[Ref("ReturningClauseSegment", optional=True)])
4030    oracle.add([(
4031        "UpdateStatementSegment".into(),
4032        NodeMatcher::new(SyntaxKind::OracleUpdateStatement, |_| {
4033            Sequence::new(vec![
4034                Ref::keyword("UPDATE").to_matchable(),
4035                Ref::new("TableReferenceSegment").to_matchable(),
4036                Ref::new("AliasExpressionSegment")
4037                    .exclude(Ref::keyword("SET"))
4038                    .optional()
4039                    .to_matchable(),
4040                Ref::new("SetClauseListSegment").to_matchable(),
4041                Ref::new("FromClauseSegment").optional().to_matchable(),
4042                Ref::new("WhereClauseSegment").optional().to_matchable(),
4043                Ref::new("ReturningClauseSegment").optional().to_matchable(),
4044            ])
4045            .to_matchable()
4046        })
4047        .to_matchable()
4048        .into(),
4049    )]);
4050
4051    // ---- DeleteStatementSegment: add RETURNING clause ----
4052    // SQLFluff: ansi.DeleteStatementSegment.match_grammar.copy(insert=[Ref("ReturningClauseSegment", optional=True)])
4053    oracle.add([(
4054        "DeleteStatementSegment".into(),
4055        NodeMatcher::new(SyntaxKind::OracleDeleteStatement, |_| {
4056            Sequence::new(vec![
4057                Ref::keyword("DELETE").to_matchable(),
4058                Ref::new("FromClauseSegment").to_matchable(),
4059                Ref::new("WhereClauseSegment").optional().to_matchable(),
4060                Ref::new("ReturningClauseSegment").optional().to_matchable(),
4061            ])
4062            .to_matchable()
4063        })
4064        .to_matchable()
4065        .into(),
4066    )]);
4067
4068    // ---- InsertStatementSegment ----
4069    // SQLFluff: supports INSERT INTO (subquery), INSERT ALL, RETURNING INTO, LOG ERRORS
4070    oracle.add([(
4071        "InsertStatementSegment".into(),
4072        NodeMatcher::new(SyntaxKind::OracleInsertStatement, |_| {
4073            Sequence::new(vec![
4074                Ref::keyword("INSERT").to_matchable(),
4075                one_of(vec![
4076                    // Standard INSERT INTO
4077                    Sequence::new(vec![
4078                        Ref::keyword("INTO").to_matchable(),
4079                        one_of(vec![
4080                            Ref::new("TableReferenceSegment").to_matchable(),
4081                            Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()])
4082                                .to_matchable(),
4083                        ])
4084                        .to_matchable(),
4085                        Ref::new("AliasExpressionSegment")
4086                            .exclude(one_of(vec![
4087                                Ref::keyword("VALUES").to_matchable(),
4088                                Ref::keyword("VALUE").to_matchable(),
4089                                Ref::keyword("SET").to_matchable(),
4090                                Ref::keyword("SELECT").to_matchable(),
4091                                Ref::keyword("WITH").to_matchable(),
4092                            ]))
4093                            .optional()
4094                            .to_matchable(),
4095                        Bracketed::new(vec![
4096                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
4097                                .to_matchable(),
4098                        ])
4099                        .config(|config| {
4100                            config.optional();
4101                        })
4102                        .to_matchable(),
4103                        one_of(vec![
4104                            Ref::new("ValuesClauseSegment").to_matchable(),
4105                            Sequence::new(vec![
4106                                Ref::keyword("SET").to_matchable(),
4107                                Delimited::new(vec![Ref::new("SetClauseSegment").to_matchable()])
4108                                    .to_matchable(),
4109                            ])
4110                            .to_matchable(),
4111                            Ref::new("SelectableGrammar").to_matchable(),
4112                        ])
4113                        .config(|config| {
4114                            config.optional();
4115                        })
4116                        .to_matchable(),
4117                        Ref::new("ReturningClauseSegment").optional().to_matchable(),
4118                        // LOG ERRORS clause
4119                        Sequence::new(vec![
4120                            Ref::keyword("LOG").to_matchable(),
4121                            Ref::keyword("ERRORS").to_matchable(),
4122                            Sequence::new(vec![
4123                                Ref::keyword("INTO").to_matchable(),
4124                                Ref::new("TableReferenceSegment").to_matchable(),
4125                            ])
4126                            .config(|config| {
4127                                config.optional();
4128                            })
4129                            .to_matchable(),
4130                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
4131                                .config(|config| {
4132                                    config.optional();
4133                                })
4134                                .to_matchable(),
4135                            Sequence::new(vec![
4136                                Ref::keyword("REJECT").to_matchable(),
4137                                Ref::keyword("LIMIT").to_matchable(),
4138                                one_of(vec![
4139                                    Ref::new("NumericLiteralSegment").to_matchable(),
4140                                    Ref::keyword("UNLIMITED").to_matchable(),
4141                                ])
4142                                .to_matchable(),
4143                            ])
4144                            .config(|config| {
4145                                config.optional();
4146                            })
4147                            .to_matchable(),
4148                        ])
4149                        .config(|config| {
4150                            config.optional();
4151                        })
4152                        .to_matchable(),
4153                    ])
4154                    .to_matchable(),
4155                    // INSERT ALL
4156                    Sequence::new(vec![
4157                        Ref::keyword("ALL").to_matchable(),
4158                        AnyNumberOf::new(vec![
4159                            Sequence::new(vec![
4160                                Ref::keyword("INTO").to_matchable(),
4161                                Ref::new("TableReferenceSegment").to_matchable(),
4162                                Ref::new("AliasExpressionSegment").optional().to_matchable(),
4163                                Bracketed::new(vec![
4164                                    Delimited::new(vec![
4165                                        Ref::new("ColumnReferenceSegment").to_matchable(),
4166                                    ])
4167                                    .to_matchable(),
4168                                ])
4169                                .config(|config| {
4170                                    config.optional();
4171                                })
4172                                .to_matchable(),
4173                                Ref::new("ValuesClauseSegment").optional().to_matchable(),
4174                            ])
4175                            .to_matchable(),
4176                        ])
4177                        .config(|config| {
4178                            config.min_times = 1;
4179                        })
4180                        .to_matchable(),
4181                        Ref::new("SelectableGrammar").to_matchable(),
4182                    ])
4183                    .to_matchable(),
4184                ])
4185                .to_matchable(),
4186            ])
4187            .to_matchable()
4188        })
4189        .to_matchable()
4190        .into(),
4191    )]);
4192
4193    // ---- OrderByClauseSegment: add SIBLINGS support ----
4194    // SQLFluff: ORDER [SIBLINGS] BY ...
4195    oracle.add([(
4196        "OrderByClauseSegment".into(),
4197        NodeMatcher::new(SyntaxKind::OracleOrderByClause, |_| {
4198            Sequence::new(vec![
4199                Ref::keyword("ORDER").to_matchable(),
4200                Ref::keyword("SIBLINGS").optional().to_matchable(),
4201                Ref::keyword("BY").to_matchable(),
4202                MetaSegment::indent().to_matchable(),
4203                Delimited::new(vec![
4204                    Sequence::new(vec![
4205                        one_of(vec![
4206                            Ref::new("ColumnReferenceSegment").to_matchable(),
4207                            Ref::new("NumericLiteralSegment").to_matchable(),
4208                            Ref::new("ExpressionSegment").to_matchable(),
4209                        ])
4210                        .to_matchable(),
4211                        one_of(vec![
4212                            Ref::keyword("ASC").to_matchable(),
4213                            Ref::keyword("DESC").to_matchable(),
4214                        ])
4215                        .config(|this| this.optional())
4216                        .to_matchable(),
4217                        Sequence::new(vec![
4218                            Ref::keyword("NULLS").to_matchable(),
4219                            one_of(vec![
4220                                Ref::keyword("FIRST").to_matchable(),
4221                                Ref::keyword("LAST").to_matchable(),
4222                            ])
4223                            .to_matchable(),
4224                        ])
4225                        .config(|this| this.optional())
4226                        .to_matchable(),
4227                    ])
4228                    .to_matchable(),
4229                ])
4230                .config(|this| {
4231                    this.terminators = vec![
4232                        Ref::keyword("LIMIT").to_matchable(),
4233                        Ref::new("FrameClauseUnitGrammar").to_matchable(),
4234                    ]
4235                })
4236                .to_matchable(),
4237                MetaSegment::dedent().to_matchable(),
4238            ])
4239            .to_matchable()
4240        })
4241        .to_matchable()
4242        .into(),
4243    )]);
4244
4245    // ---- Comparison operator overrides to allow spaces ----
4246    // SQLFluff: GreaterThanOrEqualToSegment, LessThanOrEqualToSegment, NotEqualToSegment
4247    // Oracle allows spaces between composite comparison operators: `> =`, `< =`, `! =`
4248    oracle.add([
4249        (
4250            "GreaterThanOrEqualToSegment".into(),
4251            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
4252                one_of(vec![
4253                    Sequence::new(vec![
4254                        Ref::new("RawGreaterThanSegment").to_matchable(),
4255                        Ref::new("RawEqualsSegment").to_matchable(),
4256                    ])
4257                    .to_matchable(),
4258                    Sequence::new(vec![
4259                        Ref::new("RawNotSegment").to_matchable(),
4260                        Ref::new("RawLessThanSegment").to_matchable(),
4261                    ])
4262                    .to_matchable(),
4263                ])
4264                .to_matchable()
4265            })
4266            .to_matchable()
4267            .into(),
4268        ),
4269        (
4270            "LessThanOrEqualToSegment".into(),
4271            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
4272                one_of(vec![
4273                    Sequence::new(vec![
4274                        Ref::new("RawLessThanSegment").to_matchable(),
4275                        Ref::new("RawEqualsSegment").to_matchable(),
4276                    ])
4277                    .to_matchable(),
4278                    Sequence::new(vec![
4279                        Ref::new("RawNotSegment").to_matchable(),
4280                        Ref::new("RawGreaterThanSegment").to_matchable(),
4281                    ])
4282                    .to_matchable(),
4283                ])
4284                .to_matchable()
4285            })
4286            .to_matchable()
4287            .into(),
4288        ),
4289        (
4290            "NotEqualToSegment".into(),
4291            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
4292                one_of(vec![
4293                    Sequence::new(vec![
4294                        Ref::new("RawNotSegment").to_matchable(),
4295                        Ref::new("RawEqualsSegment").to_matchable(),
4296                    ])
4297                    .to_matchable(),
4298                    Sequence::new(vec![
4299                        Ref::new("RawLessThanSegment").to_matchable(),
4300                        Ref::new("RawGreaterThanSegment").to_matchable(),
4301                    ])
4302                    .to_matchable(),
4303                ])
4304                .to_matchable()
4305            })
4306            .to_matchable()
4307            .into(),
4308        ),
4309    ]);
4310
4311    // ---- CreateSequenceOptionsSegment override ----
4312    // SQLFluff Oracle uses NOMINVALUE/NOMAXVALUE (single keywords) instead of NO MINVALUE/NO MAXVALUE
4313    oracle.add([(
4314        "CreateSequenceOptionsSegment".into(),
4315        NodeMatcher::new(SyntaxKind::CreateSequenceOptionsSegment, |_| {
4316            one_of(vec![
4317                Sequence::new(vec![
4318                    Ref::keyword("INCREMENT").to_matchable(),
4319                    Ref::keyword("BY").to_matchable(),
4320                    Ref::new("NumericLiteralSegment").to_matchable(),
4321                ])
4322                .to_matchable(),
4323                Sequence::new(vec![
4324                    Ref::keyword("START").to_matchable(),
4325                    Ref::keyword("WITH").optional().to_matchable(),
4326                    Ref::new("NumericLiteralSegment").to_matchable(),
4327                ])
4328                .to_matchable(),
4329                Ref::new("SequenceMinValueGrammar").to_matchable(),
4330                Ref::new("SequenceMaxValueGrammar").to_matchable(),
4331                one_of(vec![
4332                    Sequence::new(vec![
4333                        Ref::keyword("CACHE").to_matchable(),
4334                        Ref::new("NumericLiteralSegment").to_matchable(),
4335                    ])
4336                    .to_matchable(),
4337                    Ref::keyword("NOCACHE").to_matchable(),
4338                ])
4339                .to_matchable(),
4340                one_of(vec![
4341                    Ref::keyword("CYCLE").to_matchable(),
4342                    Ref::keyword("NOCYCLE").to_matchable(),
4343                ])
4344                .to_matchable(),
4345                one_of(vec![
4346                    Ref::keyword("ORDER").to_matchable(),
4347                    Ref::keyword("NOORDER").to_matchable(),
4348                ])
4349                .to_matchable(),
4350            ])
4351            .to_matchable()
4352        })
4353        .to_matchable()
4354        .into(),
4355    )]);
4356
4357    // ---- DropTypeStatementSegment override ----
4358    // SQLFluff: adds BODY keyword and FORCE/VALIDATE options
4359    oracle.add([(
4360        "DropTypeStatementSegment".into(),
4361        NodeMatcher::new(SyntaxKind::DropTypeStatement, |_| {
4362            Sequence::new(vec![
4363                Ref::keyword("DROP").to_matchable(),
4364                Ref::keyword("TYPE").to_matchable(),
4365                Ref::keyword("BODY").optional().to_matchable(),
4366                Ref::new("IfExistsGrammar").optional().to_matchable(),
4367                Ref::new("ObjectReferenceSegment").to_matchable(),
4368                one_of(vec![
4369                    Ref::keyword("FORCE").to_matchable(),
4370                    Ref::keyword("VALIDATE").to_matchable(),
4371                ])
4372                .config(|config| {
4373                    config.optional();
4374                })
4375                .to_matchable(),
4376                Ref::new("DropBehaviorGrammar").optional().to_matchable(),
4377            ])
4378            .to_matchable()
4379        })
4380        .to_matchable()
4381        .into(),
4382    )]);
4383
4384    // ---- AlterFunctionStatementSegment: add IF EXISTS ----
4385    // SQLFluff: Ref("IfExistsGrammar", optional=True) before function name
4386    oracle.add([(
4387        "AlterFunctionStatementSegment".into(),
4388        NodeMatcher::new(SyntaxKind::OracleAlterFunctionStatement, |_| {
4389            Sequence::new(vec![
4390                Ref::keyword("ALTER").to_matchable(),
4391                one_of(vec![
4392                    Ref::keyword("FUNCTION").to_matchable(),
4393                    Ref::keyword("PROCEDURE").to_matchable(),
4394                ])
4395                .to_matchable(),
4396                Ref::new("IfExistsGrammar").optional().to_matchable(),
4397                Ref::new("FunctionNameSegment").to_matchable(),
4398                one_of(vec![
4399                    Ref::new("CompileClauseGrammar").to_matchable(),
4400                    Ref::keyword("EDITIONABLE").to_matchable(),
4401                    Ref::keyword("NONEDITIONABLE").to_matchable(),
4402                ])
4403                .to_matchable(),
4404            ])
4405            .to_matchable()
4406        })
4407        .to_matchable()
4408        .into(),
4409    )]);
4410
4411    // ---- AlterIndexStatementSegment: add PARAMETERS ----
4412    // SQLFluff includes PARAMETERS(quoted) option
4413    oracle.add([(
4414        "AlterIndexStatementSegment".into(),
4415        NodeMatcher::new(SyntaxKind::OracleAlterIndexStatement, |_| {
4416            Sequence::new(vec![
4417                Ref::keyword("ALTER").to_matchable(),
4418                Ref::keyword("INDEX").to_matchable(),
4419                Ref::new("IndexReferenceSegment").to_matchable(),
4420                one_of(vec![
4421                    Sequence::new(vec![
4422                        Ref::keyword("REBUILD").to_matchable(),
4423                        one_of(vec![
4424                            Ref::keyword("REVERSE").to_matchable(),
4425                            Ref::keyword("NOREVERSE").to_matchable(),
4426                        ])
4427                        .config(|config| {
4428                            config.optional();
4429                        })
4430                        .to_matchable(),
4431                    ])
4432                    .to_matchable(),
4433                    Sequence::new(vec![
4434                        Ref::keyword("MONITORING").to_matchable(),
4435                        Ref::keyword("USAGE").to_matchable(),
4436                    ])
4437                    .to_matchable(),
4438                    Sequence::new(vec![
4439                        Ref::keyword("NOMONITORING").to_matchable(),
4440                        Ref::keyword("USAGE").to_matchable(),
4441                    ])
4442                    .to_matchable(),
4443                    Sequence::new(vec![
4444                        Ref::keyword("PARAMETERS").to_matchable(),
4445                        Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()])
4446                            .to_matchable(),
4447                    ])
4448                    .to_matchable(),
4449                    Sequence::new(vec![
4450                        Ref::keyword("RENAME").to_matchable(),
4451                        Ref::keyword("TO").to_matchable(),
4452                        Ref::new("IndexReferenceSegment").to_matchable(),
4453                    ])
4454                    .to_matchable(),
4455                    Ref::keyword("COMPILE").to_matchable(),
4456                    Ref::keyword("LOGGING").to_matchable(),
4457                    Ref::keyword("NOLOGGING").to_matchable(),
4458                    Ref::keyword("ENABLE").to_matchable(),
4459                    Ref::keyword("DISABLE").to_matchable(),
4460                    Ref::keyword("UNUSABLE").to_matchable(),
4461                    Ref::keyword("INVISIBLE").to_matchable(),
4462                    Ref::keyword("VISIBLE").to_matchable(),
4463                ])
4464                .to_matchable(),
4465            ])
4466            .to_matchable()
4467        })
4468        .to_matchable()
4469        .into(),
4470    )]);
4471
4472    // ---- AlterDatabaseLinkStatementSegment: add AUTHENTICATED BY ----
4473    // SQLFluff includes DBLinkAuthenticationGrammar
4474    oracle.add([(
4475        "AlterDatabaseLinkStatementSegment".into(),
4476        NodeMatcher::new(SyntaxKind::OracleAlterDatabaseLinkStatement, |_| {
4477            Sequence::new(vec![
4478                Ref::keyword("ALTER").to_matchable(),
4479                Ref::keyword("SHARED").optional().to_matchable(),
4480                Ref::keyword("PUBLIC").optional().to_matchable(),
4481                Ref::keyword("DATABASE").to_matchable(),
4482                Ref::keyword("LINK").to_matchable(),
4483                Ref::new("IfExistsGrammar").optional().to_matchable(),
4484                Ref::new("DatabaseLinkReferenceSegment").to_matchable(),
4485                one_of(vec![
4486                    Sequence::new(vec![
4487                        Ref::keyword("CONNECT").to_matchable(),
4488                        one_of(vec![
4489                            Sequence::new(vec![
4490                                Ref::keyword("TO").to_matchable(),
4491                                Ref::new("RoleReferenceSegment").to_matchable(),
4492                                Ref::keyword("IDENTIFIED").to_matchable(),
4493                                Ref::keyword("BY").to_matchable(),
4494                                Ref::new("SingleIdentifierGrammar").to_matchable(),
4495                                Ref::new("DBLinkAuthenticationGrammar")
4496                                    .optional()
4497                                    .to_matchable(),
4498                            ])
4499                            .to_matchable(),
4500                            Sequence::new(vec![
4501                                Ref::keyword("WITH").to_matchable(),
4502                                Ref::new("SingleIdentifierGrammar").to_matchable(),
4503                            ])
4504                            .to_matchable(),
4505                        ])
4506                        .to_matchable(),
4507                    ])
4508                    .to_matchable(),
4509                    Ref::new("DBLinkAuthenticationGrammar").to_matchable(),
4510                ])
4511                .to_matchable(),
4512            ])
4513            .to_matchable()
4514        })
4515        .to_matchable()
4516        .into(),
4517    )]);
4518
4519    // ---- AlterSessionStatementSegment: fuller version ----
4520    // SQLFluff has many more SET options including ISOLATION_LEVEL with special handling
4521    oracle.add([(
4522        "AlterSessionStatementSegment".into(),
4523        NodeMatcher::new(SyntaxKind::OracleAlterSessionStatement, |_| {
4524            Sequence::new(vec![
4525                Ref::keyword("ALTER").to_matchable(),
4526                Ref::keyword("SESSION").to_matchable(),
4527                one_of(vec![
4528                    Sequence::new(vec![
4529                        Ref::keyword("ADVISE").to_matchable(),
4530                        one_of(vec![
4531                            Ref::keyword("COMMIT").to_matchable(),
4532                            Ref::keyword("ROLLBACK").to_matchable(),
4533                            Ref::keyword("NOTHING").to_matchable(),
4534                        ])
4535                        .to_matchable(),
4536                    ])
4537                    .to_matchable(),
4538                    Sequence::new(vec![
4539                        Ref::keyword("CLOSE").to_matchable(),
4540                        Ref::keyword("DATABASE").to_matchable(),
4541                        Ref::keyword("LINK").to_matchable(),
4542                        Ref::new("DatabaseLinkReferenceSegment").to_matchable(),
4543                    ])
4544                    .to_matchable(),
4545                    Sequence::new(vec![
4546                        one_of(vec![
4547                            Ref::keyword("ENABLE").to_matchable(),
4548                            Ref::keyword("DISABLE").to_matchable(),
4549                        ])
4550                        .to_matchable(),
4551                        one_of(vec![
4552                            Ref::keyword("GUARD").to_matchable(),
4553                            Ref::keyword("RESUMABLE").to_matchable(),
4554                            Sequence::new(vec![
4555                                Ref::keyword("COMMIT").to_matchable(),
4556                                Ref::keyword("IN").to_matchable(),
4557                                Ref::keyword("PROCEDURE").to_matchable(),
4558                            ])
4559                            .to_matchable(),
4560                            Sequence::new(vec![
4561                                Ref::keyword("PARALLEL").to_matchable(),
4562                                one_of(vec![
4563                                    Ref::keyword("DML").to_matchable(),
4564                                    Ref::keyword("DDL").to_matchable(),
4565                                    Ref::keyword("QUERY").to_matchable(),
4566                                ])
4567                                .to_matchable(),
4568                            ])
4569                            .to_matchable(),
4570                            Sequence::new(vec![
4571                                Ref::keyword("SHARD").to_matchable(),
4572                                Ref::keyword("DDL").to_matchable(),
4573                            ])
4574                            .to_matchable(),
4575                        ])
4576                        .to_matchable(),
4577                    ])
4578                    .to_matchable(),
4579                    Sequence::new(vec![
4580                        Ref::keyword("FORCE").to_matchable(),
4581                        Ref::keyword("PARALLEL").to_matchable(),
4582                        one_of(vec![
4583                            Ref::keyword("DML").to_matchable(),
4584                            Ref::keyword("DDL").to_matchable(),
4585                            Ref::keyword("QUERY").to_matchable(),
4586                        ])
4587                        .to_matchable(),
4588                        Sequence::new(vec![
4589                            Ref::keyword("PARALLEL").to_matchable(),
4590                            Ref::new("NumericLiteralSegment").to_matchable(),
4591                        ])
4592                        .config(|config| {
4593                            config.optional();
4594                        })
4595                        .to_matchable(),
4596                    ])
4597                    .to_matchable(),
4598                    Sequence::new(vec![
4599                        Ref::keyword("SYNC").to_matchable(),
4600                        Ref::keyword("WITH").to_matchable(),
4601                        Ref::keyword("PRIMARY").to_matchable(),
4602                    ])
4603                    .to_matchable(),
4604                    Sequence::new(vec![
4605                        Ref::keyword("SET").to_matchable(),
4606                        AnyNumberOf::new(vec![
4607                            Sequence::new(vec![
4608                                Ref::keyword("ISOLATION_LEVEL").to_matchable(),
4609                                Ref::new("EqualsSegment").to_matchable(),
4610                                one_of(vec![
4611                                    Ref::keyword("SERIALIZABLE").to_matchable(),
4612                                    Sequence::new(vec![
4613                                        Ref::keyword("READ").to_matchable(),
4614                                        Ref::keyword("COMMITTED").to_matchable(),
4615                                    ])
4616                                    .to_matchable(),
4617                                ])
4618                                .to_matchable(),
4619                            ])
4620                            .to_matchable(),
4621                            Sequence::new(vec![
4622                                one_of(vec![
4623                                    Ref::keyword("CONSTRAINT").to_matchable(),
4624                                    Ref::keyword("CONSTRAINTS").to_matchable(),
4625                                ])
4626                                .to_matchable(),
4627                                Ref::new("EqualsSegment").to_matchable(),
4628                                one_of(vec![
4629                                    Ref::keyword("IMMEDIATE").to_matchable(),
4630                                    Ref::keyword("DEFERRED").to_matchable(),
4631                                    Ref::keyword("DEFAULT").to_matchable(),
4632                                ])
4633                                .to_matchable(),
4634                            ])
4635                            .to_matchable(),
4636                            Sequence::new(vec![
4637                                Ref::keyword("TIME_ZONE").to_matchable(),
4638                                Ref::new("EqualsSegment").to_matchable(),
4639                                one_of(vec![
4640                                    Ref::keyword("LOCAL").to_matchable(),
4641                                    Ref::keyword("DBTIMEZONE").to_matchable(),
4642                                    Ref::new("QuotedLiteralSegment").to_matchable(),
4643                                ])
4644                                .to_matchable(),
4645                            ])
4646                            .to_matchable(),
4647                            Sequence::new(vec![
4648                                Ref::new("ParameterNameSegment").to_matchable(),
4649                                Ref::new("EqualsSegment").to_matchable(),
4650                                one_of(vec![
4651                                    Ref::keyword("DEFAULT").to_matchable(),
4652                                    Ref::new("ExpressionSegment").to_matchable(),
4653                                ])
4654                                .to_matchable(),
4655                            ])
4656                            .to_matchable(),
4657                        ])
4658                        .config(|config| {
4659                            config.min_times = 1;
4660                        })
4661                        .to_matchable(),
4662                    ])
4663                    .to_matchable(),
4664                ])
4665                .to_matchable(),
4666            ])
4667            .to_matchable()
4668        })
4669        .to_matchable()
4670        .into(),
4671    )]);
4672
4673    // ---- AlterTableStatementSegment: handle MODIFY ----
4674    // SQLFluff: supports MODIFY column
4675    oracle.add([(
4676        "AlterTableColumnClausesSegment".into(),
4677        NodeMatcher::new(SyntaxKind::AlterTableColumnClauses, |_| {
4678            one_of(vec![
4679                // ADD / MODIFY
4680                Sequence::new(vec![
4681                    one_of(vec![
4682                        Ref::keyword("ADD").to_matchable(),
4683                        Ref::keyword("MODIFY").to_matchable(),
4684                    ])
4685                    .to_matchable(),
4686                    one_of(vec![
4687                        Ref::new("ColumnDefinitionSegment").to_matchable(),
4688                        Bracketed::new(vec![
4689                            Delimited::new(vec![
4690                                Ref::new("ColumnDefinitionSegment").to_matchable(),
4691                            ])
4692                            .to_matchable(),
4693                        ])
4694                        .to_matchable(),
4695                    ])
4696                    .to_matchable(),
4697                ])
4698                .to_matchable(),
4699                // DROP COLUMN / DROP (cols)
4700                Sequence::new(vec![
4701                    Ref::keyword("DROP").to_matchable(),
4702                    one_of(vec![
4703                        Sequence::new(vec![
4704                            Ref::keyword("COLUMN").to_matchable(),
4705                            Ref::new("ColumnReferenceSegment").to_matchable(),
4706                        ])
4707                        .to_matchable(),
4708                        Bracketed::new(vec![
4709                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
4710                                .to_matchable(),
4711                        ])
4712                        .to_matchable(),
4713                    ])
4714                    .to_matchable(),
4715                ])
4716                .to_matchable(),
4717                // RENAME COLUMN
4718                Sequence::new(vec![
4719                    Ref::keyword("RENAME").to_matchable(),
4720                    Ref::keyword("COLUMN").to_matchable(),
4721                    Ref::new("ColumnReferenceSegment").to_matchable(),
4722                    Ref::keyword("TO").to_matchable(),
4723                    Ref::new("ColumnReferenceSegment").to_matchable(),
4724                ])
4725                .to_matchable(),
4726                // SET UNUSED
4727                Sequence::new(vec![
4728                    Ref::keyword("SET").to_matchable(),
4729                    Ref::keyword("UNUSED").to_matchable(),
4730                    one_of(vec![
4731                        Sequence::new(vec![
4732                            Ref::keyword("COLUMN").to_matchable(),
4733                            Ref::new("ColumnReferenceSegment").to_matchable(),
4734                        ])
4735                        .to_matchable(),
4736                        Bracketed::new(vec![
4737                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
4738                                .to_matchable(),
4739                        ])
4740                        .to_matchable(),
4741                    ])
4742                    .to_matchable(),
4743                ])
4744                .to_matchable(),
4745            ])
4746            .to_matchable()
4747        })
4748        .to_matchable()
4749        .into(),
4750    )]);
4751
4752    // ---- ColumnDefinitionSegment: handle BYTE/CHAR qualifier in type brackets ----
4753    // SQLFluff: Bracketed(Anything(), OneOf("BYTE", "CHAR", optional=True), optional=True)
4754    oracle.add([(
4755        "ColumnDefinitionSegment".into(),
4756        NodeMatcher::new(SyntaxKind::OracleColumnDefinition, |_| {
4757            Sequence::new(vec![
4758                Ref::new("SingleIdentifierGrammar").to_matchable(),
4759                one_of(vec![
4760                    // Column with data type
4761                    Sequence::new(vec![
4762                        Ref::new("DatatypeSegment").to_matchable(),
4763                        Bracketed::new(vec![
4764                            Ref::new("ExpressionSegment").to_matchable(),
4765                            one_of(vec![
4766                                Ref::keyword("BYTE").to_matchable(),
4767                                Ref::keyword("CHAR").to_matchable(),
4768                            ])
4769                            .config(|config| {
4770                                config.optional();
4771                            })
4772                            .to_matchable(),
4773                        ])
4774                        .config(|config| {
4775                            config.optional();
4776                        })
4777                        .to_matchable(),
4778                        AnyNumberOf::new(vec![
4779                            Sequence::new(vec![
4780                                Ref::new("ColumnConstraintSegment").to_matchable(),
4781                                one_of(vec![
4782                                    Ref::keyword("ENABLE").to_matchable(),
4783                                    Ref::keyword("DISABLE").to_matchable(),
4784                                ])
4785                                .config(|config| {
4786                                    config.optional();
4787                                })
4788                                .to_matchable(),
4789                            ])
4790                            .to_matchable(),
4791                        ])
4792                        .to_matchable(),
4793                        Ref::new("IdentityClauseGrammar").optional().to_matchable(),
4794                    ])
4795                    .to_matchable(),
4796                    // Column with only constraints (no data type)
4797                    AnyNumberOf::new(vec![
4798                        Sequence::new(vec![
4799                            Ref::new("ColumnConstraintSegment").to_matchable(),
4800                            one_of(vec![
4801                                Ref::keyword("ENABLE").to_matchable(),
4802                                Ref::keyword("DISABLE").to_matchable(),
4803                            ])
4804                            .config(|config| {
4805                                config.optional();
4806                            })
4807                            .to_matchable(),
4808                        ])
4809                        .to_matchable(),
4810                    ])
4811                    .to_matchable(),
4812                ])
4813                .to_matchable(),
4814            ])
4815            .to_matchable()
4816        })
4817        .to_matchable()
4818        .into(),
4819    )]);
4820
4821    // ---- FunctionContentsGrammar: add ListaggOverflow and JSONObjectContent ----
4822    // SQLFluff: ansi_dialect.get_grammar("FunctionContentsGrammar").copy(
4823    //     insert=[Ref("ListaggOverflowClauseSegment"), Ref("JSONObjectContentSegment")])
4824    {
4825        let existing = oracle.grammar("FunctionContentsGrammar");
4826        oracle.replace_grammar(
4827            "FunctionContentsGrammar",
4828            existing.copy(
4829                Some(vec![
4830                    Ref::new("ListaggOverflowClauseSegment").to_matchable(),
4831                    Ref::new("JSONObjectContentSegment").to_matchable(),
4832                ]),
4833                None,
4834                None,
4835                None,
4836                vec![],
4837                false,
4838            ),
4839        );
4840    }
4841
4842    // ---- AccessStatementSegment: delegate to Grant/Revoke ----
4843    oracle.add([(
4844        "AccessStatementSegment".into(),
4845        NodeMatcher::new(SyntaxKind::AccessStatement, |_| {
4846            one_of(vec![
4847                Ref::new("GrantStatementSegment").to_matchable(),
4848                Ref::new("RevokeStatementSegment").to_matchable(),
4849            ])
4850            .to_matchable()
4851        })
4852        .to_matchable()
4853        .into(),
4854    )]);
4855
4856    // ---- CreateUserStatementSegment ----
4857    // SQLFluff: CREATE USER with IDENTIFIED BY/EXTERNALLY/GLOBALLY
4858    oracle.add([(
4859        "CreateUserStatementSegment".into(),
4860        NodeMatcher::new(SyntaxKind::OracleCreateUserStatement, |_| {
4861            Sequence::new(vec![
4862                Ref::keyword("CREATE").to_matchable(),
4863                Ref::keyword("USER").to_matchable(),
4864                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
4865                Ref::new("RoleReferenceSegment").to_matchable(),
4866                one_of(vec![
4867                    Sequence::new(vec![
4868                        Ref::keyword("IDENTIFIED").to_matchable(),
4869                        one_of(vec![
4870                            Sequence::new(vec![
4871                                Ref::keyword("BY").to_matchable(),
4872                                Ref::new("SingleIdentifierGrammar").to_matchable(),
4873                            ])
4874                            .to_matchable(),
4875                            Sequence::new(vec![
4876                                one_of(vec![
4877                                    Ref::keyword("EXTERNALLY").to_matchable(),
4878                                    Ref::keyword("GLOBALLY").to_matchable(),
4879                                ])
4880                                .to_matchable(),
4881                                Sequence::new(vec![
4882                                    Ref::keyword("AS").to_matchable(),
4883                                    one_of(vec![
4884                                        Ref::new("QuotedIdentifierSegment").to_matchable(),
4885                                        Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
4886                                    ])
4887                                    .to_matchable(),
4888                                ])
4889                                .config(|config| {
4890                                    config.optional();
4891                                })
4892                                .to_matchable(),
4893                            ])
4894                            .to_matchable(),
4895                        ])
4896                        .to_matchable(),
4897                    ])
4898                    .to_matchable(),
4899                    Sequence::new(vec![
4900                        Ref::keyword("NO").to_matchable(),
4901                        Ref::keyword("AUTHENTICATION").to_matchable(),
4902                    ])
4903                    .to_matchable(),
4904                ])
4905                .to_matchable(),
4906                AnyNumberOf::new(vec![
4907                    Sequence::new(vec![
4908                        Ref::keyword("DEFAULT").to_matchable(),
4909                        Ref::keyword("TABLESPACE").to_matchable(),
4910                        Ref::new("ObjectReferenceSegment").to_matchable(),
4911                    ])
4912                    .to_matchable(),
4913                    Sequence::new(vec![
4914                        Ref::keyword("TEMPORARY").to_matchable(),
4915                        Ref::keyword("TABLESPACE").to_matchable(),
4916                        Ref::new("ObjectReferenceSegment").to_matchable(),
4917                    ])
4918                    .to_matchable(),
4919                    Sequence::new(vec![
4920                        Ref::keyword("QUOTA").to_matchable(),
4921                        one_of(vec![
4922                            Ref::new("NumericLiteralSegment").to_matchable(),
4923                            Ref::keyword("UNLIMITED").to_matchable(),
4924                        ])
4925                        .to_matchable(),
4926                        Ref::keyword("ON").to_matchable(),
4927                        Ref::new("ObjectReferenceSegment").to_matchable(),
4928                    ])
4929                    .to_matchable(),
4930                    Sequence::new(vec![
4931                        Ref::keyword("PROFILE").to_matchable(),
4932                        one_of(vec![
4933                            Ref::keyword("DEFAULT").to_matchable(),
4934                            Ref::new("ObjectReferenceSegment").to_matchable(),
4935                        ])
4936                        .to_matchable(),
4937                    ])
4938                    .to_matchable(),
4939                    Sequence::new(vec![
4940                        Ref::keyword("PASSWORD").to_matchable(),
4941                        Ref::keyword("EXPIRE").to_matchable(),
4942                    ])
4943                    .to_matchable(),
4944                    Sequence::new(vec![
4945                        Ref::keyword("ACCOUNT").to_matchable(),
4946                        one_of(vec![
4947                            Ref::keyword("LOCK").to_matchable(),
4948                            Ref::keyword("UNLOCK").to_matchable(),
4949                        ])
4950                        .to_matchable(),
4951                    ])
4952                    .to_matchable(),
4953                    Sequence::new(vec![
4954                        Ref::keyword("CONTAINER").to_matchable(),
4955                        Ref::new("EqualsSegment").to_matchable(),
4956                        one_of(vec![
4957                            Ref::keyword("CURRENT").to_matchable(),
4958                            Ref::keyword("ALL").to_matchable(),
4959                        ])
4960                        .to_matchable(),
4961                    ])
4962                    .to_matchable(),
4963                ])
4964                .to_matchable(),
4965            ])
4966            .to_matchable()
4967        })
4968        .to_matchable()
4969        .into(),
4970    )]);
4971
4972    // ---- AlterSessionStatementSegment: add ROW ARCHIVAL VISIBILITY and CONTAINER ----
4973    // SQLFluff has many SET options; our simplified version adds the missing ones
4974    oracle.add([(
4975        "AlterSessionStatementSegment".into(),
4976        NodeMatcher::new(SyntaxKind::OracleAlterSessionStatement, |_| {
4977            Sequence::new(vec![
4978                Ref::keyword("ALTER").to_matchable(),
4979                Ref::keyword("SESSION").to_matchable(),
4980                one_of(vec![
4981                    Sequence::new(vec![
4982                        Ref::keyword("ADVISE").to_matchable(),
4983                        one_of(vec![
4984                            Ref::keyword("COMMIT").to_matchable(),
4985                            Ref::keyword("ROLLBACK").to_matchable(),
4986                            Ref::keyword("NOTHING").to_matchable(),
4987                        ])
4988                        .to_matchable(),
4989                    ])
4990                    .to_matchable(),
4991                    Sequence::new(vec![
4992                        Ref::keyword("CLOSE").to_matchable(),
4993                        Ref::keyword("DATABASE").to_matchable(),
4994                        Ref::keyword("LINK").to_matchable(),
4995                        Ref::new("DatabaseLinkReferenceSegment").to_matchable(),
4996                    ])
4997                    .to_matchable(),
4998                    Sequence::new(vec![
4999                        one_of(vec![
5000                            Ref::keyword("ENABLE").to_matchable(),
5001                            Ref::keyword("DISABLE").to_matchable(),
5002                        ])
5003                        .to_matchable(),
5004                        one_of(vec![
5005                            Ref::keyword("GUARD").to_matchable(),
5006                            Ref::keyword("RESUMABLE").to_matchable(),
5007                            Sequence::new(vec![
5008                                Ref::keyword("COMMIT").to_matchable(),
5009                                Ref::keyword("IN").to_matchable(),
5010                                Ref::keyword("PROCEDURE").to_matchable(),
5011                            ])
5012                            .to_matchable(),
5013                            Sequence::new(vec![
5014                                Ref::keyword("PARALLEL").to_matchable(),
5015                                one_of(vec![
5016                                    Ref::keyword("DML").to_matchable(),
5017                                    Ref::keyword("DDL").to_matchable(),
5018                                    Ref::keyword("QUERY").to_matchable(),
5019                                ])
5020                                .to_matchable(),
5021                            ])
5022                            .to_matchable(),
5023                            Sequence::new(vec![
5024                                Ref::keyword("SHARD").to_matchable(),
5025                                Ref::keyword("DDL").to_matchable(),
5026                            ])
5027                            .to_matchable(),
5028                        ])
5029                        .to_matchable(),
5030                    ])
5031                    .to_matchable(),
5032                    Sequence::new(vec![
5033                        Ref::keyword("FORCE").to_matchable(),
5034                        Ref::keyword("PARALLEL").to_matchable(),
5035                        one_of(vec![
5036                            Ref::keyword("DML").to_matchable(),
5037                            Ref::keyword("DDL").to_matchable(),
5038                            Ref::keyword("QUERY").to_matchable(),
5039                        ])
5040                        .to_matchable(),
5041                    ])
5042                    .to_matchable(),
5043                    Sequence::new(vec![
5044                        Ref::keyword("SYNC").to_matchable(),
5045                        Ref::keyword("WITH").to_matchable(),
5046                        Ref::keyword("PRIMARY").to_matchable(),
5047                    ])
5048                    .to_matchable(),
5049                    Sequence::new(vec![
5050                        Ref::keyword("SET").to_matchable(),
5051                        AnyNumberOf::new(vec![
5052                            Sequence::new(vec![
5053                                Ref::keyword("ISOLATION_LEVEL").to_matchable(),
5054                                Ref::new("EqualsSegment").to_matchable(),
5055                                one_of(vec![
5056                                    Ref::keyword("SERIALIZABLE").to_matchable(),
5057                                    Sequence::new(vec![
5058                                        Ref::keyword("READ").to_matchable(),
5059                                        Ref::keyword("COMMITTED").to_matchable(),
5060                                    ])
5061                                    .to_matchable(),
5062                                ])
5063                                .to_matchable(),
5064                            ])
5065                            .to_matchable(),
5066                            Sequence::new(vec![
5067                                one_of(vec![
5068                                    Ref::keyword("CONSTRAINT").to_matchable(),
5069                                    Ref::keyword("CONSTRAINTS").to_matchable(),
5070                                ])
5071                                .to_matchable(),
5072                                Ref::new("EqualsSegment").to_matchable(),
5073                                one_of(vec![
5074                                    Ref::keyword("IMMEDIATE").to_matchable(),
5075                                    Ref::keyword("DEFERRED").to_matchable(),
5076                                    Ref::keyword("DEFAULT").to_matchable(),
5077                                ])
5078                                .to_matchable(),
5079                            ])
5080                            .to_matchable(),
5081                            Sequence::new(vec![
5082                                Ref::keyword("TIME_ZONE").to_matchable(),
5083                                Ref::new("EqualsSegment").to_matchable(),
5084                                one_of(vec![
5085                                    Ref::keyword("LOCAL").to_matchable(),
5086                                    Ref::keyword("DBTIMEZONE").to_matchable(),
5087                                    Ref::new("QuotedLiteralSegment").to_matchable(),
5088                                ])
5089                                .to_matchable(),
5090                            ])
5091                            .to_matchable(),
5092                            // ROW ARCHIVAL VISIBILITY = ACTIVE/ALL
5093                            Sequence::new(vec![
5094                                Ref::keyword("ROW").to_matchable(),
5095                                Ref::keyword("ARCHIVAL").to_matchable(),
5096                                Ref::keyword("VISIBILITY").to_matchable(),
5097                                Ref::new("EqualsSegment").to_matchable(),
5098                                one_of(vec![
5099                                    Ref::keyword("ACTIVE").to_matchable(),
5100                                    Ref::keyword("ALL").to_matchable(),
5101                                ])
5102                                .to_matchable(),
5103                            ])
5104                            .to_matchable(),
5105                            // CONTAINER = object
5106                            Sequence::new(vec![
5107                                Ref::keyword("CONTAINER").to_matchable(),
5108                                Ref::new("EqualsSegment").to_matchable(),
5109                                Ref::new("ObjectReferenceSegment").to_matchable(),
5110                            ])
5111                            .to_matchable(),
5112                            // Generic: param = value
5113                            Sequence::new(vec![
5114                                Ref::new("ParameterNameSegment").to_matchable(),
5115                                Ref::new("EqualsSegment").to_matchable(),
5116                                one_of(vec![
5117                                    Ref::keyword("DEFAULT").to_matchable(),
5118                                    Ref::new("ExpressionSegment").to_matchable(),
5119                                ])
5120                                .to_matchable(),
5121                            ])
5122                            .to_matchable(),
5123                        ])
5124                        .config(|config| {
5125                            config.min_times = 1;
5126                        })
5127                        .to_matchable(),
5128                    ])
5129                    .to_matchable(),
5130                ])
5131                .to_matchable(),
5132            ])
5133            .to_matchable()
5134        })
5135        .to_matchable()
5136        .into(),
5137    )]);
5138
5139    // ---- AccessPermissionSegment: Oracle system privileges ----
5140    // SQLFluff: long list of Oracle-specific privilege keywords
5141    oracle.add([(
5142        "AccessPermissionSegment".into(),
5143        one_of(vec![
5144            Ref::keyword("ADMINISTER").to_matchable(),
5145            Ref::keyword("ADVISOR").to_matchable(),
5146            Ref::keyword("ALL").to_matchable(),
5147            Ref::keyword("ALTER").to_matchable(),
5148            Ref::keyword("ANALYZE").to_matchable(),
5149            Ref::keyword("AUDIT").to_matchable(),
5150            Ref::keyword("BACKUP").to_matchable(),
5151            Sequence::new(vec![
5152                Ref::keyword("BECOME").to_matchable(),
5153                Ref::keyword("USER").to_matchable(),
5154            ])
5155            .to_matchable(),
5156            Ref::keyword("COMMENT").to_matchable(),
5157            Ref::keyword("CREATE").to_matchable(),
5158            Ref::keyword("DEBUG").to_matchable(),
5159            Ref::keyword("DELETE").to_matchable(),
5160            Ref::keyword("DROP").to_matchable(),
5161            Ref::keyword("EXECUTE").to_matchable(),
5162            Ref::keyword("EXEMPT").to_matchable(),
5163            Ref::keyword("FLASHBACK").to_matchable(),
5164            Ref::keyword("FORCE").to_matchable(),
5165            Ref::keyword("GRANT").to_matchable(),
5166            Ref::keyword("INDEX").to_matchable(),
5167            Ref::keyword("INHERIT").to_matchable(),
5168            Ref::keyword("INSERT").to_matchable(),
5169            Ref::keyword("KEEP").to_matchable(),
5170            Ref::keyword("LOCK").to_matchable(),
5171            Ref::keyword("LOGMINING").to_matchable(),
5172            Ref::keyword("MANAGE").to_matchable(),
5173            Ref::keyword("MERGE").to_matchable(),
5174            Ref::keyword("READ").to_matchable(),
5175            Ref::keyword("REFERENCES").to_matchable(),
5176            Ref::keyword("RESTRICTED").to_matchable(),
5177            Ref::keyword("SELECT").to_matchable(),
5178            Ref::keyword("SET").to_matchable(),
5179            Ref::keyword("TRANSLATE").to_matchable(),
5180            Ref::keyword("UNDER").to_matchable(),
5181            Ref::keyword("UNLIMITED").to_matchable(),
5182            Ref::keyword("UPDATE").to_matchable(),
5183            Ref::keyword("USE").to_matchable(),
5184            Ref::keyword("WRITE").to_matchable(),
5185        ])
5186        .to_matchable()
5187        .into(),
5188    )]);
5189
5190    // ---- AccessObjectSegment: Oracle access object types ----
5191    // SQLFluff: SESSION, TABLE, VIEW, etc. as standalone keywords matching access targets
5192    oracle.add([(
5193        "AccessObjectSegment".into(),
5194        one_of(vec![
5195            Sequence::new(vec![
5196                Ref::keyword("CONNECT").to_matchable(),
5197                Ref::keyword("SESSION").to_matchable(),
5198            ])
5199            .to_matchable(),
5200            Ref::keyword("CLUSTER").to_matchable(),
5201            Ref::keyword("CONTAINER").to_matchable(),
5202            Ref::keyword("CONTEXT").to_matchable(),
5203            Sequence::new(vec![
5204                Ref::keyword("DATABASE").to_matchable(),
5205                one_of(vec![
5206                    Ref::keyword("LINK").to_matchable(),
5207                    Ref::keyword("TRIGGER").to_matchable(),
5208                ])
5209                .config(|c| c.optional())
5210                .to_matchable(),
5211            ])
5212            .to_matchable(),
5213            Ref::keyword("DICTIONARY").to_matchable(),
5214            Ref::keyword("DIMENSION").to_matchable(),
5215            Ref::keyword("DIRECTORY").to_matchable(),
5216            Ref::keyword("EDITION").to_matchable(),
5217            Ref::keyword("HIERARCHY").to_matchable(),
5218            Ref::keyword("INDEX").to_matchable(),
5219            Ref::keyword("INDEXTYPE").to_matchable(),
5220            Ref::keyword("JOB").to_matchable(),
5221            Ref::keyword("LIBRARY").to_matchable(),
5222            Sequence::new(vec![
5223                Ref::keyword("LOCKDOWN").to_matchable(),
5224                Ref::keyword("PROFILE").to_matchable(),
5225            ])
5226            .to_matchable(),
5227            Sequence::new(vec![
5228                Ref::keyword("MATERIALIZED").to_matchable(),
5229                Ref::keyword("VIEW").to_matchable(),
5230            ])
5231            .to_matchable(),
5232            Sequence::new(vec![
5233                Ref::keyword("MINING").to_matchable(),
5234                Ref::keyword("MODEL").to_matchable(),
5235            ])
5236            .to_matchable(),
5237            Ref::keyword("OPERATOR").to_matchable(),
5238            Ref::keyword("OUTLINE").to_matchable(),
5239            Sequence::new(vec![
5240                Ref::keyword("PLUGGABLE").to_matchable(),
5241                Ref::keyword("DATABASE").to_matchable(),
5242            ])
5243            .to_matchable(),
5244            Ref::keyword("PRIVILEGE").to_matchable(),
5245            Ref::keyword("PRIVILEGES").to_matchable(),
5246            Ref::keyword("PROCEDURE").to_matchable(),
5247            Ref::keyword("PROFILE").to_matchable(),
5248            Ref::keyword("PROGRAM").to_matchable(),
5249            Ref::keyword("ROLE").to_matchable(),
5250            Ref::keyword("SCHEDULER").to_matchable(),
5251            Ref::keyword("SEQUENCE").to_matchable(),
5252            Ref::keyword("SESSION").to_matchable(),
5253            Ref::keyword("SYNONYM").to_matchable(),
5254            Ref::keyword("SYSTEM").to_matchable(),
5255            Ref::keyword("TABLE").to_matchable(),
5256            Ref::keyword("TABLESPACE").to_matchable(),
5257            Ref::keyword("TRANSACTION").to_matchable(),
5258            Ref::keyword("TRIGGER").to_matchable(),
5259            Ref::keyword("TYPE").to_matchable(),
5260            Ref::keyword("USER").to_matchable(),
5261            Ref::keyword("VIEW").to_matchable(),
5262        ])
5263        .to_matchable()
5264        .into(),
5265    )]);
5266
5267    // ---- AccessPermissionsSegment: Oracle permission+object combos ----
5268    // SQLFluff: Delimited(Sequence(permission, ANY?, object?), role)
5269    oracle.add([(
5270        "AccessPermissionsSegment".into(),
5271        Delimited::new(vec![
5272            Sequence::new(vec![
5273                Ref::new("AccessPermissionSegment").to_matchable(),
5274                one_of(vec![
5275                    Ref::keyword("ANY").to_matchable(),
5276                    Ref::keyword("PUBLIC").to_matchable(),
5277                ])
5278                .config(|config| config.optional())
5279                .to_matchable(),
5280                Ref::new("AccessObjectSegment").optional().to_matchable(),
5281            ])
5282            .to_matchable(),
5283            Ref::new("RoleReferenceSegment").to_matchable(),
5284        ])
5285        .to_matchable()
5286        .into(),
5287    )]);
5288
5289    // ---- GrantStatementSegment ----
5290    // SQLFluff: Oracle GRANT with system privs, ON clause, CONTAINER
5291    oracle.add([(
5292        "GrantStatementSegment".into(),
5293        NodeMatcher::new(SyntaxKind::AccessStatement, |_| {
5294            Sequence::new(vec![
5295                Ref::keyword("GRANT").to_matchable(),
5296                Ref::new("AccessPermissionsSegment").to_matchable(),
5297                Sequence::new(vec![
5298                    Ref::keyword("ON").to_matchable(),
5299                    one_of(vec![
5300                        Ref::keyword("USER").to_matchable(),
5301                        Ref::keyword("DIRECTORY").to_matchable(),
5302                        Ref::keyword("EDITION").to_matchable(),
5303                        Sequence::new(vec![
5304                            Ref::keyword("MINING").to_matchable(),
5305                            Ref::keyword("MODEL").to_matchable(),
5306                        ])
5307                        .to_matchable(),
5308                        Sequence::new(vec![
5309                            Ref::keyword("JAVA").to_matchable(),
5310                            one_of(vec![
5311                                Ref::keyword("SOURCE").to_matchable(),
5312                                Ref::keyword("RESOURCE").to_matchable(),
5313                            ])
5314                            .to_matchable(),
5315                        ])
5316                        .to_matchable(),
5317                        Sequence::new(vec![
5318                            Ref::keyword("SQL").to_matchable(),
5319                            Ref::keyword("TRANSLATION").to_matchable(),
5320                            Ref::keyword("PROFILE").to_matchable(),
5321                        ])
5322                        .to_matchable(),
5323                    ])
5324                    .config(|config| config.optional())
5325                    .to_matchable(),
5326                    Ref::new("ObjectReferenceSegment").to_matchable(),
5327                ])
5328                .config(|config| config.optional())
5329                .to_matchable(),
5330                Ref::keyword("TO").to_matchable(),
5331                Delimited::new(vec![
5332                    one_of(vec![
5333                        Ref::keyword("PUBLIC").to_matchable(),
5334                        Ref::new("ObjectReferenceSegment").to_matchable(),
5335                    ])
5336                    .to_matchable(),
5337                ])
5338                .to_matchable(),
5339                Sequence::new(vec![
5340                    Ref::keyword("IDENTIFIED").to_matchable(),
5341                    Ref::keyword("BY").to_matchable(),
5342                    Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
5343                        .to_matchable(),
5344                ])
5345                .config(|config| config.optional())
5346                .to_matchable(),
5347                Sequence::new(vec![
5348                    Ref::keyword("WITH").to_matchable(),
5349                    one_of(vec![
5350                        Ref::keyword("ADMIN").to_matchable(),
5351                        Ref::keyword("DELEGATE").to_matchable(),
5352                        Ref::keyword("GRANT").to_matchable(),
5353                        Ref::keyword("HIERARCHY").to_matchable(),
5354                    ])
5355                    .to_matchable(),
5356                    Ref::keyword("OPTION").to_matchable(),
5357                ])
5358                .config(|config| config.optional())
5359                .to_matchable(),
5360                Sequence::new(vec![
5361                    Ref::keyword("CONTAINER").to_matchable(),
5362                    Ref::new("EqualsSegment").to_matchable(),
5363                    one_of(vec![
5364                        Ref::keyword("CURRENT").to_matchable(),
5365                        Ref::keyword("ALL").to_matchable(),
5366                    ])
5367                    .to_matchable(),
5368                ])
5369                .config(|config| config.optional())
5370                .to_matchable(),
5371            ])
5372            .to_matchable()
5373        })
5374        .to_matchable()
5375        .into(),
5376    )]);
5377
5378    // ---- RevokeStatementSegment ----
5379    // SQLFluff: Oracle REVOKE
5380    oracle.add([(
5381        "RevokeStatementSegment".into(),
5382        NodeMatcher::new(SyntaxKind::AccessStatement, |_| {
5383            Sequence::new(vec![
5384                Ref::keyword("REVOKE").to_matchable(),
5385                Ref::new("AccessPermissionsSegment").to_matchable(),
5386                Sequence::new(vec![
5387                    Ref::keyword("ON").to_matchable(),
5388                    one_of(vec![
5389                        Ref::keyword("USER").to_matchable(),
5390                        Ref::keyword("DIRECTORY").to_matchable(),
5391                        Ref::keyword("EDITION").to_matchable(),
5392                        Sequence::new(vec![
5393                            Ref::keyword("MINING").to_matchable(),
5394                            Ref::keyword("MODEL").to_matchable(),
5395                        ])
5396                        .to_matchable(),
5397                    ])
5398                    .config(|config| config.optional())
5399                    .to_matchable(),
5400                    Ref::new("ObjectReferenceSegment").to_matchable(),
5401                ])
5402                .config(|config| config.optional())
5403                .to_matchable(),
5404                Ref::keyword("FROM").to_matchable(),
5405                Delimited::new(vec![
5406                    one_of(vec![
5407                        Ref::keyword("PUBLIC").to_matchable(),
5408                        Ref::new("ObjectReferenceSegment").to_matchable(),
5409                    ])
5410                    .to_matchable(),
5411                ])
5412                .to_matchable(),
5413                one_of(vec![
5414                    Sequence::new(vec![
5415                        Ref::keyword("CASCADE").to_matchable(),
5416                        Ref::keyword("CONSTRAINTS").to_matchable(),
5417                    ])
5418                    .to_matchable(),
5419                    Ref::keyword("FORCE").to_matchable(),
5420                ])
5421                .config(|config| config.optional())
5422                .to_matchable(),
5423                Sequence::new(vec![
5424                    Ref::keyword("CONTAINER").to_matchable(),
5425                    Ref::new("EqualsSegment").to_matchable(),
5426                    one_of(vec![
5427                        Ref::keyword("CURRENT").to_matchable(),
5428                        Ref::keyword("ALL").to_matchable(),
5429                    ])
5430                    .to_matchable(),
5431                ])
5432                .config(|config| config.optional())
5433                .to_matchable(),
5434            ])
5435            .to_matchable()
5436        })
5437        .to_matchable()
5438        .into(),
5439    )]);
5440
5441    // ---- Fix CreateUserStatementSegment QUOTA with size unit ----
5442    oracle.add([(
5443        "CreateUserStatementSegment".into(),
5444        NodeMatcher::new(SyntaxKind::OracleCreateUserStatement, |_| {
5445            Sequence::new(vec![
5446                Ref::keyword("CREATE").to_matchable(),
5447                Ref::keyword("USER").to_matchable(),
5448                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
5449                Ref::new("RoleReferenceSegment").to_matchable(),
5450                one_of(vec![
5451                    Sequence::new(vec![
5452                        Ref::keyword("IDENTIFIED").to_matchable(),
5453                        one_of(vec![
5454                            Sequence::new(vec![
5455                                Ref::keyword("BY").to_matchable(),
5456                                Ref::new("SingleIdentifierGrammar").to_matchable(),
5457                            ])
5458                            .to_matchable(),
5459                            Sequence::new(vec![
5460                                one_of(vec![
5461                                    Ref::keyword("EXTERNALLY").to_matchable(),
5462                                    Ref::keyword("GLOBALLY").to_matchable(),
5463                                ])
5464                                .to_matchable(),
5465                                Sequence::new(vec![
5466                                    Ref::keyword("AS").to_matchable(),
5467                                    one_of(vec![
5468                                        Ref::new("QuotedIdentifierSegment").to_matchable(),
5469                                        Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
5470                                    ])
5471                                    .to_matchable(),
5472                                ])
5473                                .config(|config| config.optional())
5474                                .to_matchable(),
5475                            ])
5476                            .to_matchable(),
5477                        ])
5478                        .to_matchable(),
5479                    ])
5480                    .to_matchable(),
5481                    Sequence::new(vec![
5482                        Ref::keyword("NO").to_matchable(),
5483                        Ref::keyword("AUTHENTICATION").to_matchable(),
5484                    ])
5485                    .to_matchable(),
5486                ])
5487                .to_matchable(),
5488                AnyNumberOf::new(vec![
5489                    Sequence::new(vec![
5490                        Ref::keyword("DEFAULT").to_matchable(),
5491                        Ref::keyword("TABLESPACE").to_matchable(),
5492                        Ref::new("ObjectReferenceSegment").to_matchable(),
5493                    ])
5494                    .to_matchable(),
5495                    Sequence::new(vec![
5496                        Ref::keyword("LOCAL").optional().to_matchable(),
5497                        Ref::keyword("TEMPORARY").to_matchable(),
5498                        Ref::keyword("TABLESPACE").to_matchable(),
5499                        Ref::new("ObjectReferenceSegment").to_matchable(),
5500                    ])
5501                    .to_matchable(),
5502                    // QUOTA size ON tablespace — size can be "10M", "5G" etc.
5503                    Sequence::new(vec![
5504                        Ref::keyword("QUOTA").to_matchable(),
5505                        one_of(vec![
5506                            Sequence::new(vec![
5507                                Ref::new("NumericLiteralSegment").to_matchable(),
5508                                // Size suffix like K, M, G, T, P, E
5509                                Ref::new("SingleIdentifierGrammar")
5510                                    .optional()
5511                                    .to_matchable(),
5512                            ])
5513                            .to_matchable(),
5514                            Ref::keyword("UNLIMITED").to_matchable(),
5515                        ])
5516                        .to_matchable(),
5517                        Ref::keyword("ON").to_matchable(),
5518                        Ref::new("ObjectReferenceSegment").to_matchable(),
5519                    ])
5520                    .to_matchable(),
5521                    Sequence::new(vec![
5522                        Ref::keyword("PROFILE").to_matchable(),
5523                        one_of(vec![
5524                            Ref::keyword("DEFAULT").to_matchable(),
5525                            Ref::new("ObjectReferenceSegment").to_matchable(),
5526                        ])
5527                        .to_matchable(),
5528                    ])
5529                    .to_matchable(),
5530                    Sequence::new(vec![
5531                        Ref::keyword("PASSWORD").to_matchable(),
5532                        Ref::keyword("EXPIRE").to_matchable(),
5533                    ])
5534                    .to_matchable(),
5535                    Sequence::new(vec![
5536                        Ref::keyword("ACCOUNT").to_matchable(),
5537                        one_of(vec![
5538                            Ref::keyword("LOCK").to_matchable(),
5539                            Ref::keyword("UNLOCK").to_matchable(),
5540                        ])
5541                        .to_matchable(),
5542                    ])
5543                    .to_matchable(),
5544                    Sequence::new(vec![
5545                        Ref::keyword("ENABLE").to_matchable(),
5546                        Ref::keyword("EDITIONS").to_matchable(),
5547                    ])
5548                    .to_matchable(),
5549                    Sequence::new(vec![
5550                        Ref::keyword("CONTAINER").to_matchable(),
5551                        Ref::new("EqualsSegment").to_matchable(),
5552                        one_of(vec![
5553                            Ref::keyword("CURRENT").to_matchable(),
5554                            Ref::keyword("ALL").to_matchable(),
5555                        ])
5556                        .to_matchable(),
5557                    ])
5558                    .to_matchable(),
5559                ])
5560                .to_matchable(),
5561            ])
5562            .to_matchable()
5563        })
5564        .to_matchable()
5565        .into(),
5566    )]);
5567
5568    // ---- CreatePackageStatementSegment: add IF NOT EXISTS ----
5569    oracle.add([(
5570        "CreatePackageStatementSegment".into(),
5571        NodeMatcher::new(SyntaxKind::OracleCreatePackageStatement, |_| {
5572            Sequence::new(vec![
5573                Ref::keyword("CREATE").to_matchable(),
5574                Sequence::new(vec![
5575                    Ref::keyword("OR").to_matchable(),
5576                    Ref::keyword("REPLACE").to_matchable(),
5577                ])
5578                .config(|config| {
5579                    config.optional();
5580                })
5581                .to_matchable(),
5582                one_of(vec![
5583                    Ref::keyword("EDITIONABLE").to_matchable(),
5584                    Ref::keyword("NONEDITIONABLE").to_matchable(),
5585                ])
5586                .config(|config| {
5587                    config.optional();
5588                })
5589                .to_matchable(),
5590                Ref::keyword("PACKAGE").to_matchable(),
5591                Ref::keyword("BODY").optional().to_matchable(),
5592                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
5593                Ref::new("ObjectReferenceSegment").to_matchable(),
5594                Ref::new("SharingClauseGrammar").optional().to_matchable(),
5595                AnyNumberOf::new(vec![
5596                    Ref::new("DefaultCollationClauseGrammar").to_matchable(),
5597                    Ref::new("InvokerRightsClauseGrammar").to_matchable(),
5598                    Ref::new("AccessibleByClauseGrammar").to_matchable(),
5599                ])
5600                .config(|config| {
5601                    config.optional();
5602                })
5603                .to_matchable(),
5604                one_of(vec![
5605                    Ref::keyword("IS").to_matchable(),
5606                    Ref::keyword("AS").to_matchable(),
5607                ])
5608                .to_matchable(),
5609                Ref::new("DeclareSegment").to_matchable(),
5610                Ref::keyword("END").to_matchable(),
5611                Ref::new("ObjectReferenceSegment").optional().to_matchable(),
5612            ])
5613            .to_matchable()
5614        })
5615        .to_matchable()
5616        .into(),
5617    )]);
5618
5619    // ---- SingleIdentifierGrammar: add SqlplusSubstitutionVariable ----
5620    // SQLFluff: ansi SingleIdentifierGrammar.copy(insert=[Ref("SqlplusSubstitutionVariableSegment")])
5621    {
5622        let existing = oracle.grammar("SingleIdentifierGrammar");
5623        oracle.replace_grammar(
5624            "SingleIdentifierGrammar",
5625            existing.copy(
5626                Some(vec![
5627                    Ref::new("SqlplusSubstitutionVariableSegment").to_matchable(),
5628                ]),
5629                None,
5630                None,
5631                None,
5632                vec![],
5633                false,
5634            ),
5635        );
5636    }
5637
5638    // ---- BaseExpressionElementGrammar: add ConnectByRoot + SqlplusSubstitutionVariable ----
5639    // SQLFluff: ansi BaseExpressionElementGrammar.copy(insert=[ConnectByRootGrammar, SqlplusSubstitutionVariableSegment])
5640    {
5641        let existing = oracle.grammar("BaseExpressionElementGrammar");
5642        oracle.replace_grammar(
5643            "BaseExpressionElementGrammar",
5644            existing.copy(
5645                Some(vec![
5646                    Ref::new("ConnectByRootGrammar").to_matchable(),
5647                    Ref::new("SqlplusSubstitutionVariableSegment").to_matchable(),
5648                    Ref::new("TriggerPredicatesGrammar").to_matchable(),
5649                ]),
5650                None,
5651                None,
5652                None,
5653                vec![],
5654                false,
5655            ),
5656        );
5657    }
5658
5659    // ---- TableExpressionSegment: add SqlplusSubstitutionVariable ----
5660    // SQLFluff: ansi.TableExpressionSegment.match_grammar.copy(insert=[Ref("SqlplusSubstitutionVariableSegment")])
5661    oracle.replace_grammar(
5662        "TableExpressionSegment",
5663        one_of(vec![
5664            Ref::new("ValuesClauseSegment").to_matchable(),
5665            Ref::new("BareFunctionSegment").to_matchable(),
5666            Ref::new("FunctionSegment").to_matchable(),
5667            Ref::new("TableReferenceSegment").to_matchable(),
5668            Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(),
5669            Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()]).to_matchable(),
5670            Ref::new("SqlplusSubstitutionVariableSegment").to_matchable(),
5671        ])
5672        .to_matchable(),
5673    );
5674
5675    // ---- Fix GRANT: add QUERY REWRITE to AccessPermissionSegment ----
5676    oracle.add([(
5677        "AccessPermissionSegment".into(),
5678        one_of(vec![
5679            Ref::keyword("ADMINISTER").to_matchable(),
5680            Ref::keyword("ADVISOR").to_matchable(),
5681            Ref::keyword("ALL").to_matchable(),
5682            Ref::keyword("ALTER").to_matchable(),
5683            Ref::keyword("ANALYZE").to_matchable(),
5684            Ref::keyword("AUDIT").to_matchable(),
5685            Ref::keyword("BACKUP").to_matchable(),
5686            Sequence::new(vec![
5687                Ref::keyword("BECOME").to_matchable(),
5688                Ref::keyword("USER").to_matchable(),
5689            ])
5690            .to_matchable(),
5691            Ref::keyword("COMMENT").to_matchable(),
5692            Ref::keyword("CREATE").to_matchable(),
5693            Ref::keyword("DEBUG").to_matchable(),
5694            Ref::keyword("DELETE").to_matchable(),
5695            Ref::keyword("DROP").to_matchable(),
5696            Ref::keyword("EXECUTE").to_matchable(),
5697            Ref::keyword("EXEMPT").to_matchable(),
5698            Ref::keyword("FLASHBACK").to_matchable(),
5699            Ref::keyword("FORCE").to_matchable(),
5700            Ref::keyword("GRANT").to_matchable(),
5701            Ref::keyword("INDEX").to_matchable(),
5702            Ref::keyword("INHERIT").to_matchable(),
5703            Ref::keyword("INSERT").to_matchable(),
5704            Ref::keyword("KEEP").to_matchable(),
5705            Ref::keyword("LOCK").to_matchable(),
5706            Ref::keyword("LOGMINING").to_matchable(),
5707            Ref::keyword("MANAGE").to_matchable(),
5708            Ref::keyword("MERGE").to_matchable(),
5709            Sequence::new(vec![
5710                Ref::keyword("ON").to_matchable(),
5711                Ref::keyword("COMMIT").to_matchable(),
5712                Ref::keyword("REFRESH").to_matchable(),
5713            ])
5714            .to_matchable(),
5715            Ref::keyword("PURGE").to_matchable(),
5716            // SQLFluff: Sequence(Ref.keyword("GLOBAL", optional=True), "QUERY", "REWRITE")
5717            Sequence::new(vec![
5718                Ref::keyword("GLOBAL").optional().to_matchable(),
5719                Ref::keyword("QUERY").to_matchable(),
5720                Ref::keyword("REWRITE").to_matchable(),
5721            ])
5722            .to_matchable(),
5723            Ref::keyword("READ").to_matchable(),
5724            Ref::keyword("REDEFINE").to_matchable(),
5725            Ref::keyword("REFERENCES").to_matchable(),
5726            Ref::keyword("RESTRICTED").to_matchable(),
5727            Ref::keyword("RESUMABLE").to_matchable(),
5728            Ref::keyword("SELECT").to_matchable(),
5729            Ref::keyword("SET").to_matchable(),
5730            Ref::keyword("SIGN").to_matchable(),
5731            Sequence::new(vec![
5732                Ref::keyword("TABLE").to_matchable(),
5733                Ref::keyword("RETENTION").to_matchable(),
5734            ])
5735            .to_matchable(),
5736            Ref::keyword("TRANSLATE").to_matchable(),
5737            Ref::keyword("UNDER").to_matchable(),
5738            Ref::keyword("UNLIMITED").to_matchable(),
5739            Ref::keyword("UPDATE").to_matchable(),
5740            Ref::keyword("USE").to_matchable(),
5741            Ref::keyword("WRITE").to_matchable(),
5742        ])
5743        .to_matchable()
5744        .into(),
5745    )]);
5746
5747    // ---- Fix CreateTypeStatementSegment: add IF NOT EXISTS + VARRAY OF (type) NOT PERSISTABLE ----
5748    oracle.add([(
5749        "CreateTypeStatementSegment".into(),
5750        NodeMatcher::new(SyntaxKind::OracleCreateTypeStatement, |_| {
5751            Sequence::new(vec![
5752                Ref::keyword("CREATE").optional().to_matchable(),
5753                Sequence::new(vec![
5754                    Ref::keyword("OR").to_matchable(),
5755                    Ref::keyword("REPLACE").to_matchable(),
5756                ])
5757                .config(|config| config.optional())
5758                .to_matchable(),
5759                one_of(vec![
5760                    Ref::keyword("EDITIONABLE").to_matchable(),
5761                    Ref::keyword("NONEDITIONABLE").to_matchable(),
5762                ])
5763                .config(|config| config.optional())
5764                .to_matchable(),
5765                Ref::keyword("TYPE").to_matchable(),
5766                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
5767                Ref::new("ObjectReferenceSegment").to_matchable(),
5768                Ref::keyword("FORCE").optional().to_matchable(),
5769                Ref::new("SharingClauseGrammar").optional().to_matchable(),
5770                Ref::new("DefaultCollationClauseGrammar")
5771                    .optional()
5772                    .to_matchable(),
5773                AnyNumberOf::new(vec![
5774                    Ref::new("InvokerRightsClauseGrammar").to_matchable(),
5775                    Ref::new("AccessibleByClauseGrammar").to_matchable(),
5776                ])
5777                .config(|config| config.optional())
5778                .to_matchable(),
5779                one_of(vec![
5780                    Ref::keyword("IS").to_matchable(),
5781                    Ref::keyword("AS").to_matchable(),
5782                ])
5783                .config(|config| config.optional())
5784                .to_matchable(),
5785                one_of(vec![
5786                    Ref::new("ObjectTypeAndSubtypeDefGrammar").to_matchable(),
5787                    Ref::new("VarrayAndNestedTypeSpecGrammar").to_matchable(),
5788                ])
5789                .to_matchable(),
5790            ])
5791            .to_matchable()
5792        })
5793        .to_matchable()
5794        .into(),
5795    )]);
5796
5797    // ---- Fix VarrayAndNestedTypeSpecGrammar: support (type) NOT PERSISTABLE ----
5798    oracle.add([(
5799        "VarrayAndNestedTypeSpecGrammar".into(),
5800        Sequence::new(vec![
5801            one_of(vec![
5802                Sequence::new(vec![
5803                    one_of(vec![
5804                        Ref::keyword("VARRAY").to_matchable(),
5805                        Sequence::new(vec![
5806                            Ref::keyword("VARYING").optional().to_matchable(),
5807                            Ref::keyword("ARRAY").to_matchable(),
5808                        ])
5809                        .to_matchable(),
5810                    ])
5811                    .to_matchable(),
5812                    Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
5813                        .to_matchable(),
5814                ])
5815                .to_matchable(),
5816                Ref::keyword("TABLE").to_matchable(),
5817            ])
5818            .to_matchable(),
5819            Ref::keyword("OF").to_matchable(),
5820            one_of(vec![
5821                // Bracketed type with optional NOT PERSISTABLE
5822                Sequence::new(vec![
5823                    Bracketed::new(vec![
5824                        Sequence::new(vec![
5825                            Ref::new("DatatypeSegment").to_matchable(),
5826                            Sequence::new(vec![
5827                                Ref::keyword("NOT").to_matchable(),
5828                                Ref::keyword("NULL").to_matchable(),
5829                            ])
5830                            .config(|config| config.optional())
5831                            .to_matchable(),
5832                        ])
5833                        .to_matchable(),
5834                    ])
5835                    .to_matchable(),
5836                    Ref::keyword("NOT").optional().to_matchable(),
5837                    Ref::keyword("PERSISTABLE").optional().to_matchable(),
5838                ])
5839                .to_matchable(),
5840                // Unbracketed type
5841                Sequence::new(vec![
5842                    Ref::new("DatatypeSegment").to_matchable(),
5843                    Sequence::new(vec![
5844                        Ref::keyword("NOT").to_matchable(),
5845                        Ref::keyword("NULL").to_matchable(),
5846                    ])
5847                    .config(|config| config.optional())
5848                    .to_matchable(),
5849                ])
5850                .to_matchable(),
5851            ])
5852            .to_matchable(),
5853        ])
5854        .to_matchable()
5855        .into(),
5856    )]);
5857
5858    // ---- Fix CreateTriggerStatementSegment: add REFERENCING clause ----
5859    // SQLFluff includes ReferencingClauseSegment after DmlEventClauseSegment
5860    oracle.add([(
5861        "ReferencingClauseSegment".into(),
5862        NodeMatcher::new(SyntaxKind::OracleReferencingClause, |_| {
5863            Sequence::new(vec![
5864                Ref::keyword("REFERENCING").to_matchable(),
5865                AnyNumberOf::new(vec![
5866                    Sequence::new(vec![
5867                        Ref::new("TriggerCorrelationNameSegment").to_matchable(),
5868                        Ref::keyword("AS").optional().to_matchable(),
5869                        Ref::new("NakedIdentifierSegment").to_matchable(),
5870                    ])
5871                    .to_matchable(),
5872                ])
5873                .to_matchable(),
5874            ])
5875            .to_matchable()
5876        })
5877        .to_matchable()
5878        .into(),
5879    )]);
5880
5881    oracle.add([(
5882        "CreateTriggerStatementSegment".into(),
5883        NodeMatcher::new(SyntaxKind::OracleCreateTriggerStatement, |_| {
5884            Sequence::new(vec![
5885                Ref::keyword("CREATE").to_matchable(),
5886                Sequence::new(vec![
5887                    Ref::keyword("OR").to_matchable(),
5888                    Ref::keyword("REPLACE").to_matchable(),
5889                ])
5890                .config(|config| config.optional())
5891                .to_matchable(),
5892                one_of(vec![
5893                    Ref::keyword("EDITIONABLE").to_matchable(),
5894                    Ref::keyword("NONEDITIONABLE").to_matchable(),
5895                ])
5896                .config(|config| config.optional())
5897                .to_matchable(),
5898                Ref::keyword("TRIGGER").to_matchable(),
5899                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
5900                Ref::new("TriggerReferenceSegment").to_matchable(),
5901                Ref::new("SharingClauseGrammar").optional().to_matchable(),
5902                Ref::new("DefaultCollationClauseGrammar")
5903                    .optional()
5904                    .to_matchable(),
5905                // Trigger timing and event
5906                Sequence::new(vec![
5907                    one_of(vec![
5908                        one_of(vec![
5909                            Ref::keyword("BEFORE").to_matchable(),
5910                            Ref::keyword("AFTER").to_matchable(),
5911                        ])
5912                        .to_matchable(),
5913                        Sequence::new(vec![
5914                            Ref::keyword("INSTEAD").to_matchable(),
5915                            Ref::keyword("OF").to_matchable(),
5916                        ])
5917                        .to_matchable(),
5918                        Ref::keyword("FOR").to_matchable(),
5919                    ])
5920                    .to_matchable(),
5921                    Ref::new("DmlEventClauseSegment").to_matchable(),
5922                ])
5923                .to_matchable(),
5924                // SQLFluff: ReferencingClauseSegment
5925                Ref::new("ReferencingClauseSegment")
5926                    .optional()
5927                    .to_matchable(),
5928                Sequence::new(vec![
5929                    Ref::keyword("FOR").to_matchable(),
5930                    Ref::keyword("EACH").to_matchable(),
5931                    Ref::keyword("ROW").to_matchable(),
5932                ])
5933                .config(|config| config.optional())
5934                .to_matchable(),
5935                // CROSSEDITION
5936                Sequence::new(vec![
5937                    one_of(vec![
5938                        Ref::keyword("FORWARD").to_matchable(),
5939                        Ref::keyword("REVERSE").to_matchable(),
5940                    ])
5941                    .config(|config| config.optional())
5942                    .to_matchable(),
5943                    Ref::keyword("CROSSEDITION").to_matchable(),
5944                ])
5945                .config(|config| config.optional())
5946                .to_matchable(),
5947                // FOLLOWS / PRECEDES
5948                Sequence::new(vec![
5949                    one_of(vec![
5950                        Ref::keyword("FOLLOWS").to_matchable(),
5951                        Ref::keyword("PRECEDES").to_matchable(),
5952                    ])
5953                    .to_matchable(),
5954                    Delimited::new(vec![Ref::new("TriggerReferenceSegment").to_matchable()])
5955                        .to_matchable(),
5956                ])
5957                .config(|config| config.optional())
5958                .to_matchable(),
5959                one_of(vec![
5960                    Ref::keyword("ENABLE").to_matchable(),
5961                    Ref::keyword("DISABLE").to_matchable(),
5962                ])
5963                .config(|config| config.optional())
5964                .to_matchable(),
5965                Sequence::new(vec![
5966                    Ref::keyword("WHEN").to_matchable(),
5967                    Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
5968                        .to_matchable(),
5969                ])
5970                .config(|config| config.optional())
5971                .to_matchable(),
5972                // Body: compound trigger or statements
5973                one_of(vec![
5974                    Ref::new("CompoundTriggerBlock").to_matchable(),
5975                    Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
5976                ])
5977                .to_matchable(),
5978                Ref::keyword("END").optional().to_matchable(),
5979                Ref::new("TriggerReferenceSegment")
5980                    .optional()
5981                    .to_matchable(),
5982            ])
5983            .to_matchable()
5984        })
5985        .to_matchable()
5986        .into(),
5987    )]);
5988
5989    // ---- CompoundTriggerBlock ----
5990    // SQLFluff: COMPOUND TRIGGER [DeclareSegment] AnyNumberOf(TimingPointSectionSegment)
5991    oracle.add([(
5992        "CompoundTriggerBlock".into(),
5993        NodeMatcher::new(SyntaxKind::CompoundTriggerStatement, |_| {
5994            Sequence::new(vec![
5995                Ref::keyword("COMPOUND").to_matchable(),
5996                Ref::keyword("TRIGGER").to_matchable(),
5997                Ref::new("DeclareSegment").optional().to_matchable(),
5998                AnyNumberOf::new(vec![Ref::new("TimingPointSectionSegment").to_matchable()])
5999                    .to_matchable(),
6000            ])
6001            .to_matchable()
6002        })
6003        .to_matchable()
6004        .into(),
6005    )]);
6006
6007    // ---- TimingPointSectionSegment ----
6008    oracle.add([(
6009        "TimingPointSectionSegment".into(),
6010        NodeMatcher::new(SyntaxKind::TimingPointSection, |_| {
6011            Sequence::new(vec![
6012                Ref::new("TimingPointGrammar").to_matchable(),
6013                Ref::keyword("IS").to_matchable(),
6014                Ref::keyword("BEGIN").to_matchable(),
6015                Ref::new("OneOrMoreStatementsGrammar").to_matchable(),
6016                Sequence::new(vec![
6017                    Ref::keyword("END").to_matchable(),
6018                    Ref::new("TimingPointGrammar").to_matchable(),
6019                ])
6020                .to_matchable(),
6021                Ref::new("DelimiterGrammar").to_matchable(),
6022            ])
6023            .to_matchable()
6024        })
6025        .to_matchable()
6026        .into(),
6027    )]);
6028
6029    oracle
6030}