sqlparser/dialect/
oracle.rs1// 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::{keywords::Keyword, Dialect, Precedence};
26
27const RESERVED_KEYWORDS_FOR_SELECT_ITEM_OPERATOR: [Keyword; 1] = [Keyword::CONNECT_BY_ROOT];
28
29/// A [`Dialect`] for [Oracle Databases](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/index.html)
30#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
31#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
32pub struct OracleDialect;
33
34impl Dialect for OracleDialect {
35 // ~ appears not to be called anywhere
36 fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
37 Some('"')
38 }
39
40 fn is_delimited_identifier_start(&self, ch: char) -> bool {
41 ch == '"'
42 }
43
44 fn is_identifier_start(&self, ch: char) -> bool {
45 ch.is_alphabetic()
46 }
47
48 fn is_identifier_part(&self, ch: char) -> bool {
49 ch.is_alphanumeric() || ch == '_' || ch == '$' || ch == '#' || ch == '@'
50 }
51
52 fn supports_outer_join_operator(&self) -> bool {
53 true
54 }
55
56 fn supports_connect_by(&self) -> bool {
57 true
58 }
59
60 fn supports_execute_immediate(&self) -> bool {
61 true
62 }
63
64 fn supports_match_recognize(&self) -> bool {
65 true
66 }
67
68 fn supports_window_function_null_treatment_arg(&self) -> bool {
69 true
70 }
71
72 fn supports_boolean_literals(&self) -> bool {
73 false
74 }
75
76 fn supports_comment_on(&self) -> bool {
77 true
78 }
79
80 fn supports_create_table_select(&self) -> bool {
81 true
82 }
83
84 fn supports_set_stmt_without_operator(&self) -> bool {
85 true
86 }
87
88 fn get_next_precedence(&self, parser: &Parser) -> Option<Result<u8, ParserError>> {
89 let t = parser.peek_token();
90 debug!("get_next_precedence() {t:?}");
91
92 match t.token {
93 Token::StringConcat => Some(Ok(self.prec_value(Precedence::PlusMinus))),
94 _ => None,
95 }
96 }
97
98 fn supports_group_by_expr(&self) -> bool {
99 true
100 }
101
102 fn get_reserved_keywords_for_select_item_operator(&self) -> &[Keyword] {
103 &RESERVED_KEYWORDS_FOR_SELECT_ITEM_OPERATOR
104 }
105
106 fn supports_quote_delimited_string(&self) -> bool {
107 true
108 }
109
110 fn supports_comment_optimizer_hint(&self) -> bool {
111 true
112 }
113}