Skip to main content

sqlparser/dialect/
oracle.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use log::debug;
19
20use crate::{
21    parser::{Parser, ParserError},
22    tokenizer::Token,
23};
24
25use super::{
26    keywords::{Keyword, RESERVED_FOR_TABLE_FACTOR},
27    Dialect, Precedence,
28};
29
30const RESERVED_KEYWORDS_FOR_SELECT_ITEM_OPERATOR: [Keyword; 1] = [Keyword::CONNECT_BY_ROOT];
31
32/// A [`Dialect`] for [Oracle Databases](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/index.html)
33#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
34#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
35pub struct OracleDialect;
36
37impl Dialect for OracleDialect {
38    // ~ appears not to be called anywhere
39    fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
40        Some('"')
41    }
42
43    fn is_delimited_identifier_start(&self, ch: char) -> bool {
44        ch == '"'
45    }
46
47    fn is_identifier_start(&self, ch: char) -> bool {
48        ch.is_alphabetic()
49    }
50
51    fn is_identifier_part(&self, ch: char) -> bool {
52        ch.is_alphanumeric() || ch == '_' || ch == '$' || ch == '#' || ch == '@'
53    }
54
55    /// LIMIT is not a reserved word in Oracle SQL.
56    /// See <https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Oracle-SQL-Reserved-Words.html>
57    fn is_table_factor(&self, kw: &Keyword, _parser: &mut Parser) -> bool {
58        kw == &Keyword::LIMIT || !RESERVED_FOR_TABLE_FACTOR.contains(kw)
59    }
60
61    fn supports_outer_join_operator(&self) -> bool {
62        true
63    }
64
65    fn supports_connect_by(&self) -> bool {
66        true
67    }
68
69    fn supports_execute_immediate(&self) -> bool {
70        true
71    }
72
73    fn supports_match_recognize(&self) -> bool {
74        true
75    }
76
77    fn supports_window_function_null_treatment_arg(&self) -> bool {
78        true
79    }
80
81    fn supports_boolean_literals(&self) -> bool {
82        false
83    }
84
85    fn supports_comment_on(&self) -> bool {
86        true
87    }
88
89    fn supports_create_table_select(&self) -> bool {
90        true
91    }
92
93    fn supports_set_stmt_without_operator(&self) -> bool {
94        true
95    }
96
97    fn get_next_precedence(&self, parser: &Parser) -> Option<Result<u8, ParserError>> {
98        let t = parser.peek_token_ref();
99        debug!("get_next_precedence() {t:?}");
100
101        match &t.token {
102            Token::StringConcat => Some(Ok(self.prec_value(Precedence::PlusMinus))),
103            _ => None,
104        }
105    }
106
107    fn supports_group_by_expr(&self) -> bool {
108        true
109    }
110
111    fn get_reserved_keywords_for_select_item_operator(&self) -> &[Keyword] {
112        &RESERVED_KEYWORDS_FOR_SELECT_ITEM_OPERATOR
113    }
114
115    fn supports_quote_delimited_string(&self) -> bool {
116        true
117    }
118
119    fn supports_comment_optimizer_hint(&self) -> bool {
120        true
121    }
122
123    fn supports_insert_table_alias(&self) -> bool {
124        true
125    }
126
127    /// See <https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/INSERT.html#GUID-903F8043-0254-4EE9-ACC1-CB8AC0AF3423__I2126242>
128    fn supports_insert_table_query(&self) -> bool {
129        true
130    }
131}