Skip to content

Commit f99bc23

Browse files
committed
List Oracle SQL functions
1 parent 118e07a commit f99bc23

File tree

1 file changed

+234
-1
lines changed

1 file changed

+234
-1
lines changed

src/languages/plsql.formatter.ts

Lines changed: 234 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,239 @@ import Tokenizer from 'src/core/Tokenizer';
33
import { EOF_TOKEN, isReserved, isToken, type Token, TokenType } from 'src/core/token';
44
import { dedupe } from 'src/utils';
55

6+
// https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm
7+
const reservedFunctions = {
8+
numeric: [
9+
'ABS',
10+
'ACOS',
11+
'ASIN',
12+
'ATAN',
13+
'ATAN2',
14+
'BITAND',
15+
'CEIL',
16+
'COS',
17+
'COSH',
18+
'EXP',
19+
'FLOOR',
20+
'LN',
21+
'LOG',
22+
'MOD',
23+
'NANVL',
24+
'POWER',
25+
'REMAINDER',
26+
'ROUND',
27+
'SIGN',
28+
'SIN',
29+
'SINH',
30+
'SQRT',
31+
'TAN',
32+
'TANH',
33+
'TRUNC',
34+
'WIDTH_BUCKET',
35+
],
36+
character: [
37+
'CHR',
38+
'CONCAT',
39+
'INITCAP',
40+
'LOWER',
41+
'LPAD',
42+
'LTRIM',
43+
'NLS_INITCAP',
44+
'NLS_LOWER',
45+
'NLSSORT',
46+
'NLS_UPPER',
47+
'REGEXP_REPLACE',
48+
'REGEXP_SUBSTR',
49+
'REPLACE',
50+
'RPAD',
51+
'RTRIM',
52+
'SOUNDEX',
53+
'SUBSTR',
54+
'TRANSLATE',
55+
'TREAT',
56+
'TRIM',
57+
'UPPER',
58+
59+
'NLS_CHARSET_DECL_LEN',
60+
'NLS_CHARSET_ID',
61+
'NLS_CHARSET_NAME',
62+
63+
'ASCII',
64+
'INSTR',
65+
'LENGTH',
66+
'REGEXP_INSTR',
67+
],
68+
datetime: [
69+
'ADD_MONTHS',
70+
'CURRENT_DATE',
71+
'CURRENT_TIMESTAMP',
72+
'DBTIMEZONE',
73+
'EXTRACT',
74+
'FROM_TZ',
75+
'LAST_DAY',
76+
'LOCALTIMESTAMP',
77+
'MONTHS_BETWEEN',
78+
'NEW_TIME',
79+
'NEXT_DAY',
80+
'NUMTODSINTERVAL',
81+
'NUMTOYMINTERVAL',
82+
'ROUND',
83+
'SESSIONTIMEZONE',
84+
'SYS_EXTRACT_UTC',
85+
'SYSDATE',
86+
'SYSTIMESTAMP',
87+
'TO_CHAR',
88+
'TO_TIMESTAMP',
89+
'TO_TIMESTAMP_TZ',
90+
'TO_DSINTERVAL',
91+
'TO_YMINTERVAL',
92+
'TRUNC',
93+
'TZ_OFFSET',
94+
],
95+
comparison: ['GREATEST', 'LEAST'],
96+
conversion: [
97+
'ASCIISTR',
98+
'BIN_TO_NUM',
99+
'CAST',
100+
'CHARTOROWID',
101+
'COMPOSE',
102+
'CONVERT',
103+
'DECOMPOSE',
104+
'HEXTORAW',
105+
'NUMTODSINTERVAL',
106+
'NUMTOYMINTERVAL',
107+
'RAWTOHEX',
108+
'RAWTONHEX',
109+
'ROWIDTOCHAR',
110+
'ROWIDTONCHAR',
111+
'SCN_TO_TIMESTAMP',
112+
'TIMESTAMP_TO_SCN',
113+
'TO_BINARY_DOUBLE',
114+
'TO_BINARY_FLOAT',
115+
'TO_CHAR',
116+
'TO_CLOB',
117+
'TO_DATE',
118+
'TO_DSINTERVAL',
119+
'TO_LOB',
120+
'TO_MULTI_BYTE',
121+
'TO_NCHAR',
122+
'TO_NCLOB',
123+
'TO_NUMBER',
124+
'TO_DSINTERVAL',
125+
'TO_SINGLE_BYTE',
126+
'TO_TIMESTAMP',
127+
'TO_TIMESTAMP_TZ',
128+
'TO_YMINTERVAL',
129+
'TO_YMINTERVAL',
130+
'TRANSLATE',
131+
'UNISTR',
132+
],
133+
largeObject: ['BFILENAME', 'EMPTY_BLOB,', 'EMPTY_CLOB'],
134+
collection: ['CARDINALITY', 'COLLECT', 'POWERMULTISET', 'POWERMULTISET_BY_CARDINALITY', 'SET'],
135+
hierarchical: ['SYS_CONNECT_BY_PATH'],
136+
dataMining: [
137+
'CLUSTER_ID',
138+
'CLUSTER_PROBABILITY',
139+
'CLUSTER_SET',
140+
'FEATURE_ID',
141+
'FEATURE_SET',
142+
'FEATURE_VALUE',
143+
'PREDICTION',
144+
'PREDICTION_COST',
145+
'PREDICTION_DETAILS',
146+
'PREDICTION_PROBABILITY',
147+
'PREDICTION_SET',
148+
],
149+
xml: [
150+
'APPENDCHILDXML',
151+
'DELETEXML',
152+
'DEPTH',
153+
'EXTRACT',
154+
'EXISTSNODE',
155+
'EXTRACTVALUE',
156+
'INSERTCHILDXML',
157+
'INSERTXMLBEFORE',
158+
'PATH',
159+
'SYS_DBURIGEN',
160+
'SYS_XMLAGG',
161+
'SYS_XMLGEN',
162+
'UPDATEXML',
163+
'XMLAGG',
164+
'XMLCDATA',
165+
'XMLCOLATTVAL',
166+
'XMLCOMMENT',
167+
'XMLCONCAT',
168+
'XMLFOREST',
169+
'XMLPARSE',
170+
'XMLPI',
171+
'XMLQUERY',
172+
'XMLROOT',
173+
'XMLSEQUENCE',
174+
'XMLSERIALIZE',
175+
'XMLTABLE',
176+
'XMLTRANSFORM',
177+
],
178+
encoding: ['DECODE', 'DUMP', 'ORA_HASH', 'VSIZE'],
179+
nullRelated: ['COALESCE', 'LNNVL', 'NULLIF', 'NVL', 'NVL2'],
180+
env: ['SYS_CONTEXT', 'SYS_GUID', 'SYS_TYPEID', 'UID', 'USER', 'USERENV'],
181+
aggregate: [
182+
'AVG',
183+
'COLLECT',
184+
'CORR',
185+
'CORR_S',
186+
'CORR_K',
187+
'COUNT',
188+
'COVAR_POP',
189+
'COVAR_SAMP',
190+
'CUME_DIST',
191+
'DENSE_RANK',
192+
'FIRST',
193+
'GROUP_ID',
194+
'GROUPING',
195+
'GROUPING_ID',
196+
'LAST',
197+
'MAX',
198+
'MEDIAN',
199+
'MIN',
200+
'PERCENTILE_CONT',
201+
'PERCENTILE_DISC',
202+
'PERCENT_RANK',
203+
'RANK',
204+
'REGR_SLOPE',
205+
'REGR_INTERCEPT',
206+
'REGR_COUNT',
207+
'REGR_R2',
208+
'REGR_AVGX',
209+
'REGR_AVGY',
210+
'REGR_SXX',
211+
'REGR_SYY',
212+
'REGR_SXY',
213+
'STATS_BINOMIAL_TEST',
214+
'STATS_CROSSTAB',
215+
'STATS_F_TEST',
216+
'STATS_KS_TEST',
217+
'STATS_MODE',
218+
'STATS_MW_TEST',
219+
'STATS_ONE_WAY_ANOVA',
220+
'STATS_T_TEST_ONE',
221+
'STATS_T_TEST_PAIRED',
222+
'STATS_T_TEST_INDEP',
223+
'STATS_T_TEST_INDEPU',
224+
'STATS_WSR_TEST',
225+
'STDDEV',
226+
'STDDEV_POP',
227+
'STDDEV_SAMP',
228+
'SUM',
229+
'VAR_POP',
230+
'VAR_SAMP',
231+
'VARIANCE',
232+
],
233+
// Windowing functions (minus the ones already listed in aggregates)
234+
window: ['FIRST_VALUE', 'LAG', 'LAST_VALUE', 'LEAD', 'NTILE', 'RATIO_TO_REPORT', 'ROW_NUMBER'],
235+
objectReference: ['DEREF', 'MAKE_REF', 'REF', 'REFTOHEX', 'VALUE'],
236+
model: ['CV', 'ITERATION_NUMBER', 'PRESENTNNV', 'PRESENTV', 'PREVIOUS'],
237+
};
238+
6239
/**
7240
* Priority 5 (last)
8241
* Full list of reserved words
@@ -460,7 +693,7 @@ export default class PlSqlFormatter extends Formatter {
460693
reservedBinaryCommands,
461694
reservedDependentClauses,
462695
reservedLogicalOperators: ['AND', 'OR', 'XOR'],
463-
reservedKeywords: dedupe(reservedKeywords),
696+
reservedKeywords: dedupe([...reservedKeywords, ...Object.values(reservedFunctions).flat()]),
464697
// TODO: support custom-delimited strings: Q'{..}' q'<..>' etc
465698
stringTypes: [{ quote: "''", prefixes: ['N'] }],
466699
identTypes: [`""`],

0 commit comments

Comments
 (0)