Sadas SQL Reference

Transcription

Sadas SQL Reference
SQL Reference Guide
Release: 6.0.6.0
Last update: 18/02/2014
Sadas SQL Reference
© 2014 Advanced Systems srl
All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or
mechanical, including photocopying, recording, taping, or information storage and retrieval systems - without the
written permission of the publisher.
Products that are referred to in this document may be either trademarks and/or registered trademarks of the
respective owners. The publisher and the author make no claim to these trademarks.
While every precaution has been taken in the preparation of this document, the publisher and the author assume no
responsibility for errors or omissions, or for damages resulting from the use of information contained in this
document or from the use of programs and source code that may accompany it. In no event shall the publisher and
the author be liable for any loss of profit or any other commercial damage caused or alleged to have been caused
directly or indirectly by this document.
The SQL Reference Guide for the SADAS dbms
by Advanced Systems srl
This reference guide contains a complete description of the Structured Query
Language (SQL) used to manage information in a SADAS database.
SADAS SQL is a subset of the American National Standards Institute (ANSI) and
the International Standards Organization (ISO) SQL:1999 standard.
This document is intended for all users of SADAS SQL and SADAS database.
The SQL Reference Guide for the SADAS dbms
by Advanced Systems srl
This is the SQL Reference for the SADAS database on release 6.0.6.0
Copyright © 2005, 2014, SADAS. All rights reserved.
Author: Vincenzo Minei
Table of Contents
0
Part I Introduction to SADAS SQL
18
1 History...................................................................................................................................
of SQL
18
2 SQL Standards
................................................................................................................................... 18
How SQL Works
.......................................................................................................................................................... 19
Common Language
..........................................................................................................................................................
for All Relational Databases
20
3 Lexical
...................................................................................................................................
Conventions
20
4 Tools ................................................................................................................................... 21
5 SADAS
...................................................................................................................................
Datatypes
22
6 SADAS
...................................................................................................................................
Supported Datatypes
23
7 Character
...................................................................................................................................
datatypes
25
8 Numeric
...................................................................................................................................
datatypes
25
9 Datetime
...................................................................................................................................
datatypes
27
DATE Datatype .......................................................................................................................................................... 27
TIME Datatype .......................................................................................................................................................... 27
TIMESTAMP Datatype
.......................................................................................................................................................... 28
10 Code datatype
................................................................................................................................... 28
11 Datatype
...................................................................................................................................
Comparison Rules
28
Numeric Values.......................................................................................................................................................... 28
Datetime Values.......................................................................................................................................................... 28
Character Values
.......................................................................................................................................................... 28
Binary Comparisons
......................................................................................................................................................... 29
Blank-Padded
.........................................................................................................................................................
Comparison Semantics
29
12 Literals
................................................................................................................................... 32
Text Literals .......................................................................................................................................................... 32
Numeric Literals.......................................................................................................................................................... 33
Integer Literals
......................................................................................................................................................... 33
NUMBER and
.........................................................................................................................................................
Floating-Point Literals
34
Datetime Literals
......................................................................................................................................................... 35
13 Comments
................................................................................................................................... 35
14 Schema/Database
...................................................................................................................................
Objects
36
Schema/Database
..........................................................................................................................................................
Objects
36
Nonschema Objects
.......................................................................................................................................................... 37
Part II Pseudocolumns
39
1 ROWID
...................................................................................................................................
Pseudocolumn
39
2 ROWNUM
...................................................................................................................................
Pseudocolumn
40
Part III Operators
42
1 About...................................................................................................................................
SQL Operators
42
Unary and Binary
..........................................................................................................................................................
Operators
42
Operator Precedence
.......................................................................................................................................................... 42
© 2014 Advanced Systems srl
2 Arithmetic
...................................................................................................................................
Operators
43
3 Concatenation
...................................................................................................................................
Operators
44
4 Set Operators
................................................................................................................................... 45
Part IV SQL Functions
47
1 About...................................................................................................................................
SQL Functions
47
Single-Row Functions
.......................................................................................................................................................... 48
Numeric Functions
......................................................................................................................................................... 48
Character Functions
.........................................................................................................................................................
Returning Character Values
49
Character Functions
.........................................................................................................................................................
Returning Numeric Values (COPY)
50
Datetime Functions
......................................................................................................................................................... 50
General Comparison
.........................................................................................................................................................
Functions
51
Conversion.........................................................................................................................................................
Functions
51
Encoding and
.........................................................................................................................................................
Decoding Functions
52
Masking functions
......................................................................................................................................................... 52
Aggregate Functions
.......................................................................................................................................................... 53
2 ABS ................................................................................................................................... 54
3 ACOS................................................................................................................................... 54
4 ADD_MONTHS
................................................................................................................................... 55
5 ASCII................................................................................................................................... 56
6 ASIN ................................................................................................................................... 56
7 ATAN................................................................................................................................... 57
8 AVG ................................................................................................................................... 57
9 BIN_TO_NUM
................................................................................................................................... 58
10 BITAND
................................................................................................................................... 59
11 BITOR................................................................................................................................... 59
12 BITXOR
................................................................................................................................... 60
13 CEIL[ING]
................................................................................................................................... 61
14 CHR ................................................................................................................................... 62
15 CONCAT
................................................................................................................................... 62
16 COS ................................................................................................................................... 63
17 COSH................................................................................................................................... 63
18 COUNT
................................................................................................................................... 64
19 CURDATE
................................................................................................................................... 65
20 CURRENT_DATE
................................................................................................................................... 65
21 CURRENT_TIME
................................................................................................................................... 65
22 CURRENT_TIMESTAMP
................................................................................................................................... 66
23 CURTIME
................................................................................................................................... 66
24 DATEADD
................................................................................................................................... 66
25 DATEDIFF
................................................................................................................................... 68
26 DATEPART
................................................................................................................................... 70
27 DATE_TO_JULIAN
................................................................................................................................... 72
© 2014 Advanced Systems srl
28 DAYNAME
................................................................................................................................... 72
29 DAYOFWEEK
................................................................................................................................... 73
30 DAYOFYEAR
................................................................................................................................... 74
31 DECODE
................................................................................................................................... 75
32 DIGITS
................................................................................................................................... 76
33 EXP ................................................................................................................................... 77
34 EXTFUNC
................................................................................................................................... 78
35 FIRST_DAY
................................................................................................................................... 80
36 FIRST_WORK_DAY
................................................................................................................................... 81
37 FLOOR
................................................................................................................................... 81
38 GREATEST
................................................................................................................................... 82
39 GROUPING
................................................................................................................................... 83
40 HEXTONUM
................................................................................................................................... 84
41 HEXTOSTR
................................................................................................................................... 84
42 INITCAP
................................................................................................................................... 85
43 INSTR................................................................................................................................... 86
44 JULIAN_TO_DATE
................................................................................................................................... 86
45 ISNUMERIC
................................................................................................................................... 87
46 LAST_DAY
................................................................................................................................... 87
47 LAST_WORK_DAY
................................................................................................................................... 88
48 LCASE
................................................................................................................................... 88
49 LEAST
................................................................................................................................... 89
50 LENGTH
................................................................................................................................... 89
51 LN
................................................................................................................................... 90
52 LOCALTIMESTAMP
................................................................................................................................... 90
53 LOG ................................................................................................................................... 91
54 LOWER
................................................................................................................................... 91
55 LPAD................................................................................................................................... 92
56 LTRIM................................................................................................................................... 93
57 MAX ................................................................................................................................... 94
58 MIN ................................................................................................................................... 94
59 MOD ................................................................................................................................... 95
60 MONTHNAME
................................................................................................................................... 96
61 MONTHS_BETWEEN
................................................................................................................................... 96
62 NEXT_DAY
................................................................................................................................... 97
63 NEXT_WORK_DAY
................................................................................................................................... 97
64 NOW ................................................................................................................................... 98
65 NUMTOHEX
................................................................................................................................... 98
66 PI
................................................................................................................................... 98
© 2014 Advanced Systems srl
67 POSITION
................................................................................................................................... 99
68 POWER
................................................................................................................................... 99
69 PREVIOUS_DAY
................................................................................................................................... 100
70 PREVIOUS_WORK_DAY
................................................................................................................................... 100
71 RATIO_TO_REPORT
................................................................................................................................... 101
72 REGEXP_INSTR
................................................................................................................................... 101
73 REGEXP_REPLACE
................................................................................................................................... 101
74 REGEXP_SUBSTR
................................................................................................................................... 101
75 REMAINDER
................................................................................................................................... 102
76 REPLACE
................................................................................................................................... 102
77 ROUND
................................................................................................................................... 102
78 RPAD
................................................................................................................................... 103
79 RTRIM
................................................................................................................................... 104
80 SDS_HASH
................................................................................................................................... 105
81 SDS_HASH_SH1
................................................................................................................................... 106
82 SIGN................................................................................................................................... 107
83 SIN ................................................................................................................................... 108
84 SINH................................................................................................................................... 108
85 SHUFFLE
................................................................................................................................... 109
86 SOUNDEX
................................................................................................................................... 109
87 SQRT
................................................................................................................................... 110
88 STDDEV
................................................................................................................................... 111
89 STRTOHEX
................................................................................................................................... 112
90 SUBSTITUTE_WITH
................................................................................................................................... 112
91 SUBSTR[ING]
................................................................................................................................... 113
92 SUM................................................................................................................................... 114
93 SYSDATE
................................................................................................................................... 114
94 SYSTIME
................................................................................................................................... 115
95 SYSTIMESTAMP
................................................................................................................................... 115
96 TAN ................................................................................................................................... 115
97 TANH
................................................................................................................................... 116
98 TO_BASE
................................................................................................................................... 116
99 TO_CHAR
...................................................................................................................................
(character)
117
100 TO_CHAR
...................................................................................................................................
(datetime)
117
101 TO_CHAR
...................................................................................................................................
(number)
122
102 TO_CODE
................................................................................................................................... 125
103 TO_DATE
................................................................................................................................... 125
104 TO_DESC
................................................................................................................................... 126
105 TO_NUMBER
................................................................................................................................... 127
© 2014 Advanced Systems srl
106 TO_TIME
................................................................................................................................... 128
107 TO_TIMESTAMP
................................................................................................................................... 128
108 TODAY
................................................................................................................................... 129
109 TRANSLATE
................................................................................................................................... 129
110 TRIM................................................................................................................................... 131
111 TRUNC[ATE]
...................................................................................................................................
(number)
131
112 UCASE
................................................................................................................................... 132
113 UPPER
................................................................................................................................... 132
114 VARIANCE
................................................................................................................................... 132
115 VSIZE
................................................................................................................................... 133
Part V Expressions
135
1 About
...................................................................................................................................
SQL Expressions
135
2 Simple
...................................................................................................................................
Expressions
137
3 Compound
...................................................................................................................................
Expressions
138
4 Case...................................................................................................................................
Expressions
138
5 Datetime
...................................................................................................................................
Expressions
140
6 Function
...................................................................................................................................
Expressions
140
7 Scalar
...................................................................................................................................
Subquery Expressions
141
8 Expression
...................................................................................................................................
Lists
141
Part VI Conditions
144
1 About
...................................................................................................................................
SQL Conditions
144
Condition Precedence
.......................................................................................................................................................... 145
2 Comparison
...................................................................................................................................
Conditions
146
Simple Comparison
..........................................................................................................................................................
Conditions
147
3 Logical
...................................................................................................................................
Conditions
148
4 Pattern-matching
...................................................................................................................................
Conditions
150
LIKE Condition.......................................................................................................................................................... 150
Case Sensitivity
.......................................................................................................................................................... 152
Pattern Matching
..........................................................................................................................................................
on Indexed Columns
152
LIKE Condition:..........................................................................................................................................................
General Examples
153
5 Range
...................................................................................................................................
Conditions
153
6 Null Conditions
................................................................................................................................... 154
7 Compound
...................................................................................................................................
Conditions
155
8 EXISTS
...................................................................................................................................
Condition
156
9 IN Condition
................................................................................................................................... 156
Part VII SQL DDL Clauses (constraint)
159
1 Primary
...................................................................................................................................
Key Constraints
161
2 Foreign
...................................................................................................................................
Key Constraints
161
3 Virtual
...................................................................................................................................
Constraints
162
© 2014 Advanced Systems srl
Part VIII SQL Queries and Subqueries
164
1 About
...................................................................................................................................
Queries and Subqueries
164
2 Creating
...................................................................................................................................
Simple Queries
165
3 The UNION
...................................................................................................................................
[ALL], INTERSECT, MINUS Operators
166
4 Sorting
...................................................................................................................................
Query Results
168
5 Joins................................................................................................................................... 169
Join Conditions.......................................................................................................................................................... 169
Equijoins
.......................................................................................................................................................... 170
Self Joins
.......................................................................................................................................................... 170
Special notes .......................................................................................................................................................... 171
Special outer joins
.......................................................................................................................................................... 173
6 Using...................................................................................................................................
Subqueries
173
7 Unnesting
...................................................................................................................................
of Nested Subqueries
174
8 Selecting
...................................................................................................................................
from the DUAL Table
175
Part IX SQL STATEMENTS
177
1 Types
...................................................................................................................................
of SQL Statements
177
2 Data...................................................................................................................................
Definition Language (DDL) Statements
177
3 Data...................................................................................................................................
Manipulation Language (DML) Statements
178
4 ALTER
...................................................................................................................................
TABLE
178
5 ALTER
...................................................................................................................................
USER
183
6 ALTER
...................................................................................................................................
VIEW
185
7 APPEND
...................................................................................................................................
TABLE
186
8 COMMENT
...................................................................................................................................
ON COLUMN
188
9 COMMENT
...................................................................................................................................
ON TABLE
190
10 CONNECT
................................................................................................................................... 191
11 CREATE
...................................................................................................................................
DATABASE
193
12 CREATE
...................................................................................................................................
DBADMIN
194
13 CREATE
...................................................................................................................................
DOMAIN
195
14 CREATE
...................................................................................................................................
EXPRESSION
196
15 CREATE
...................................................................................................................................
INDEX
198
16 CREATE
...................................................................................................................................
SYNONYM
199
17 CREATE
...................................................................................................................................
TABLE
200
18 CREATE
...................................................................................................................................
USER
204
19 CREATE
...................................................................................................................................
VIEW
206
20 DEACTIVATE
...................................................................................................................................
DATABASE
208
21 DEACTIVATE
...................................................................................................................................
TABLE
209
22 DELETE
...................................................................................................................................
STORED QUERIES
209
23 DELETE
...................................................................................................................................
TABLE
211
24 DELETE
...................................................................................................................................
KEYS
213
© 2014 Advanced Systems srl
25 DESCRIBE
...................................................................................................................................
TABLE
215
26 DESCRIBE
...................................................................................................................................
STORED QUERIES
217
27 DESCRIBE
...................................................................................................................................
SYSALLCOLUMNS
218
28 DESCRIBE
...................................................................................................................................
SYSDB
219
29 DESCRIBE
...................................................................................................................................
SYSDOMAINS
220
30 DESCRIBE
...................................................................................................................................
SYSFOREIGNKEYS
221
31 DESCRIBE
...................................................................................................................................
SYSKEYS
221
32 DESCRIBE
...................................................................................................................................
SYSLOG
222
33 DESCRIBE
...................................................................................................................................
SYSOBJECTS
223
34 DESCRIBE
...................................................................................................................................
SYSSYNONYMS
224
35 DESCRIBE
...................................................................................................................................
SYSTABLES
225
36 DESCRIBE
...................................................................................................................................
SYSUSERS
226
37 DESCRIBE
...................................................................................................................................
SYSVIEWS
227
38 DESCRIBE
...................................................................................................................................
USER
228
39 DISABLE
...................................................................................................................................
INDEXGBY
229
40 DISCONNECT
................................................................................................................................... 230
41 DROP
...................................................................................................................................
DATABASE
230
42 DROP
...................................................................................................................................
DOMAIN
231
43 DROP
...................................................................................................................................
EXPRESSION
232
44 DROP
...................................................................................................................................
EXPRESSIONS
233
45 DROP
...................................................................................................................................
GENERATED COLUMNS
234
46 DROP
...................................................................................................................................
INDEX
235
47 DROP
...................................................................................................................................
SYNONYM
236
48 DROP
...................................................................................................................................
TABLE
237
49 DROP
...................................................................................................................................
USER
238
50 DROP
...................................................................................................................................
VIEW
239
51 DUPLICATE
...................................................................................................................................
DATABASE
240
52 DUPLICATE
...................................................................................................................................
TABLE
241
53 DUPLICATE
...................................................................................................................................
USER
243
54 ENABLE
...................................................................................................................................
INDEXGBY
243
55 EXECUTE
...................................................................................................................................
STORED QUERIES
244
56 GRANT
................................................................................................................................... 245
57 INSERT
................................................................................................................................... 247
58 INSERT
...................................................................................................................................
TABLE
248
59 INTERSECT
................................................................................................................................... 251
60 LOAD
...................................................................................................................................
COLUMNS
253
61 LOAD
...................................................................................................................................
DATABASE
254
62 LOAD
...................................................................................................................................
TABLE
255
63 LOCK
...................................................................................................................................
TABLE
258
© 2014 Advanced Systems srl
64 LOCK
...................................................................................................................................
USER
259
65 MINUS
................................................................................................................................... 260
66 RENAME
...................................................................................................................................
COLUMN
261
67 RENAME
...................................................................................................................................
DATABASE
263
68 RENAME
...................................................................................................................................
DOMAIN
264
69 RENAME
...................................................................................................................................
TABLE
265
70 RENAME
...................................................................................................................................
VIEW
266
71 REPLICATE
...................................................................................................................................
DATABASE
267
72 REPLICATE
...................................................................................................................................
TABLE
268
73 REVOKE
................................................................................................................................... 270
74 REWRITE
...................................................................................................................................
DATABASE
272
75 REWRITE
...................................................................................................................................
TABLE
273
76 SELECT
................................................................................................................................... 275
77 SET ...................................................................................................................................
LANGUAGE
293
78 SET ...................................................................................................................................
VARIABLE
294
79 TRUNCATE
...................................................................................................................................
DATABASE
295
80 TRUNCATE
...................................................................................................................................
TABLE
296
81 UNION
................................................................................................................................... 296
82 UNLOAD
...................................................................................................................................
DATABASE
298
83 UNLOAD
...................................................................................................................................
TABLE
299
84 UNLOCK
...................................................................................................................................
USER
301
85 UNLOCK
...................................................................................................................................
TABLE
302
86 UPDATE
................................................................................................................................... 303
87 UPDATE
...................................................................................................................................
COLUMNS
305
88 UPDATE
...................................................................................................................................
TABLE
307
89 UNSET
...................................................................................................................................
VARIABLE
308
Part X Compendium of Sadas SQL Syntax
311
Part XI Sadas Database Reserved Words
319
Part XII Sadas Database SQL Errors
326
1 SDS-0000
...................................................................................................................................
"No error"
326
2 SDS-0001
...................................................................................................................................
"Null SQL script"
326
3 SDS-0002
...................................................................................................................................
"Encountered end of file in comments"
326
4 SDS-0003
...................................................................................................................................
"Non terminated text literal"
327
5 SDS-0004
...................................................................................................................................
"Text literal too long"
327
6 SDS-0005
...................................................................................................................................
"Unknown character"
328
7 SDS-0006
...................................................................................................................................
"Identifier name too long"
328
8 SDS-0007
...................................................................................................................................
"Illegal identifier"
329
© 2014 Advanced Systems srl
9 SDS-0008
...................................................................................................................................
"Illegal numeric literal"
329
10 SDS-0009
...................................................................................................................................
"Syntax error"
330
11 SDS-0010
...................................................................................................................................
"Expected relational operator"
331
12 SDS-0011
...................................................................................................................................
"Expected logical operator"
331
13 SDS-0012
...................................................................................................................................
"Expected arithmetic operator"
332
14 SDS-0013
...................................................................................................................................
"Expected identifier after point"
332
15 SDS-0014
...................................................................................................................................
"Expected identifier or constant value"
333
16 SDS-0015
...................................................................................................................................
"Unknown table/view name"
333
17 SDS-0016
...................................................................................................................................
"Unknown column name"
334
18 SDS-0017
...................................................................................................................................
"Wrong use of function TO_DATE"
335
19 SDS-0018
...................................................................................................................................
"Operands of different datatypes"
336
20 SDS-0019
...................................................................................................................................
"Exceeded the limit of the number precision"
336
21 SDS-0020
...................................................................................................................................
"Alias name already used"
337
22 SDS-0021
...................................................................................................................................
"Wrong use of function TO_TIMESTAMP"
338
23 SDS-0022
...................................................................................................................................
"Illegal GROUP BY clause"
338
24 SDS-0023
...................................................................................................................................
"Alias name is already a column name"
339
25 SDS-0024
...................................................................................................................................
"Illegal operation on operands"
339
26 SDS-0025
...................................................................................................................................
"Wrong number of parameters"
340
27 SDS-0026
...................................................................................................................................
"Illegal function in the context"
340
28 SDS-0027
...................................................................................................................................
"Improper use of alias name"
341
29 SDS-0028
...................................................................................................................................
"Unloaded table"
341
30 SDS-0029
...................................................................................................................................
"Unsupported function/operation"
342
31 SDS-0030
...................................................................................................................................
"Wrong use of function TO_TIME"
344
32 SDS-0031
...................................................................................................................................
"Illegal ORDER BY clause"
345
33 SDS-0032
...................................................................................................................................
"Improper use of DISTINCT clause"
345
34 SDS-0033
...................................................................................................................................
"Internal error; analyze the context!"
346
35 SDS-0034
...................................................................................................................................
"GROUP BY clause required in this case"
346
36 SDS-0035 "Expected a constant positive expression in column
definition"
................................................................................................................................... 346
37 SDS-0036
...................................................................................................................................
"Invalid column description"
347
38 SDS-0037
...................................................................................................................................
"Table/view already exists"
348
39 SDS-0038
...................................................................................................................................
"Table/view does not exist"
348
40 SDS-0039
...................................................................................................................................
"Invalid constraint"
349
41 SDS-0040
...................................................................................................................................
"Primary key is not unique"
350
42 SDS-0041
...................................................................................................................................
"Table/view auto-reference through FOREIGN KEY"
350
43 SDS-0042
...................................................................................................................................
"Duplicated FOREIGN KEY"
351
44 SDS-0043
...................................................................................................................................
"Column isn’t a PRIMARY KEY"
351
45 SDS-0044
...................................................................................................................................
"Column already exists"
352
46 SDS-0045
...................................................................................................................................
"Type mismatch for FOREIGN KEY"
353
© 2014 Advanced Systems srl
47 SDS-0046 "Invalid NOT STAR JOIN: SELECT clause cannot contain
fields...................................................................................................................................
of right table"
353
48 SDS-0047
...................................................................................................................................
"The comparison value for the coded field is too long"
354
49 SDS-0048
...................................................................................................................................
"Database already exists"
354
50 SDS-0049
...................................................................................................................................
"Database does not exist"
355
51 SDS-0050
...................................................................................................................................
"Illegal DISTINCT clause"
355
52 SDS-0051
...................................................................................................................................
"Too many DISTINCT clauses"
356
53 SDS-0052
...................................................................................................................................
"Non executable SQL"
357
54 SDS-0053
...................................................................................................................................
"Illegal UNION [ALL]/INTERSECT/MINUS"
357
55 SDS-0054
...................................................................................................................................
"User has no rights to execute this command"
359
56 SDS-0055
...................................................................................................................................
"Wrong hidden condition"
359
57 SDS-0056
...................................................................................................................................
"The user does not exist"
360
58 SDS-0057
...................................................................................................................................
"User already exists"
360
59 SDS-0058
...................................................................................................................................
"No database available"
361
60 SDS-0059
...................................................................................................................................
"No user connected"
361
61 SDS-0060
...................................................................................................................................
"Cannot DROP current database"
362
62 SDS-0061
...................................................................................................................................
"Division by zero"
362
63 SDS-0062
...................................................................................................................................
"Wrong use of function NEXT_DAY"
363
64 SDS-0063 "LPAD/RPAD functions: the second parameter must be a
not negative
...................................................................................................................................
integer constant"
363
65 SDS-0064
...................................................................................................................................
"LPAD/RPAD functions: the third parameter must be a char"
364
66 SDS-0065 "SUBSTR function accepts only not negative integer
parameters"
................................................................................................................................... 364
67 SDS-0066
...................................................................................................................................
"Root of a negative number"
365
68 SDS-0067
...................................................................................................................................
"Improper use of INFO/SHADOW keywords"
366
69 SDS-0068
...................................................................................................................................
"Illegal HAVING clause"
366
70 SDS-0069
...................................................................................................................................
"Illegal use of function TRANSLATE"
367
71 SDS-0070
...................................................................................................................................
"Table has not a PRIMARY KEY"
368
72 SDS-0071
...................................................................................................................................
"Database ID is wrong (<> 10 characters)"
368
73 SDS-0072
...................................................................................................................................
"Database ID already exists"
369
74 SDS-0073
...................................................................................................................................
"Wrong use of function DATEADD"
369
75 SDS-0074
...................................................................................................................................
"Wrong use of function DATEDIFF"
371
76 SDS-0075
...................................................................................................................................
"Wrong use of function DATEPART"
371
77 SDS-0078
...................................................................................................................................
"Wrong date"
372
78 SDS-0079
...................................................................................................................................
"Wrong time"
373
79 SDS-0089
...................................................................................................................................
"IN clause: expected constant expression"
373
80 SDS-0090 "TO_CHAR function: second and third parameter must be
string...................................................................................................................................
constants"
374
81 SDS-0091
...................................................................................................................................
"TO_CHAR function: erroneous NLS description"
374
82 SDS-0092
...................................................................................................................................
"TO_CHAR function: invalid numeric format model"
375
© 2014 Advanced Systems srl
83 SDS-0093
...................................................................................................................................
"TO_CHAR function: invalid date/time format model"
375
84 SDS-0094
...................................................................................................................................
"DECODE function: default parameter must be constant"
376
85 SDS-0095
...................................................................................................................................
"Scalar sub-query must return an unique value"
376
86 SDS-0096
...................................................................................................................................
"Wrong DISTRIBUTE parameter"
377
87 SDS-0097
...................................................................................................................................
"Illegal DISTRIBUTE clause"
378
88 SDS-0098
...................................................................................................................................
"Too many DISTRIBUTE column ranges"
379
89 SDS-0099
...................................................................................................................................
"Wrong DISTRIBUTE parameter configuration"
379
90 SDS-0100
...................................................................................................................................
"Too many DISTRIBUTE ranges"
380
91 SDS-0101
...................................................................................................................................
"Wrong timestamp"
380
92 SDS-0102
...................................................................................................................................
"STAR operand not supported in this context"
380
93 SDS-0103
...................................................................................................................................
"Too many elements in update list"
381
94 SDS-0104
...................................................................................................................................
"Illegal use of an aggregate function"
381
95 SDS-0105
...................................................................................................................................
"UPDATE is not allowed on primary key"
382
96 SDS-0106
...................................................................................................................................
"User domain does not exist"
382
97 SDS-0107
...................................................................................................................................
"Domain not enabled for user"
382
98 SDS-0108 "RATIO_TO_REPORT function: parameter must be a
column"
................................................................................................................................... 383
99 SDS-0109
...................................................................................................................................
"VSIZE function: parameter must be a column"
383
100 SDS-0110
...................................................................................................................................
"TO_NUMBER function: unable to convert the string"
384
101 SDS-0111
...................................................................................................................................
"Invalid numeric value for the function"
384
102 SDS-0112
...................................................................................................................................
"UPDATE not allowed on column ROWID"
385
103 SDS-0113
...................................................................................................................................
"Wrong use of function SUBSTITUTE_WITH"
385
104 SDS-0114
...................................................................................................................................
"Domain already exists"
386
105 SDS-0115
...................................................................................................................................
"Domain does not exist"
386
106 SDS-0116
...................................................................................................................................
"LIKE works only on alphanumeric columns"
387
107 SDS-0117
...................................................................................................................................
"Operands of different datatypes in between"
387
108 SDS-0118 "IN clause: operands of different datatypes in the list of
constants"
................................................................................................................................... 388
109 SDS-0119
...................................................................................................................................
"Join graph not supported"
388
110 SDS-0120 "Cannot use columns of code type as terms of an
expressions"
................................................................................................................................... 389
111 SDS-0121
...................................................................................................................................
"Illegal identifier: the first character must be a letter"
390
112 SDS-0122
...................................................................................................................................
"Null identifier"
390
113 SDS-0123
...................................................................................................................................
"Column not found in the sub-query of the FROM clause"
391
114 SDS-0124
...................................................................................................................................
"Too much tables in DELETE statement"
391
115 SDS-0125
...................................................................................................................................
"Not supported syntax for CREATE VIEW statement"
392
116 SDS-0126
...................................................................................................................................
"Cannot nest more group functions"
392
117 SDS-0127
...................................................................................................................................
"In DUAL SELECT following clause is not allowed"
393
118 SDS-0128
...................................................................................................................................
"UPDATE: group functions are not allowed on right part"
393
119 SDS-0129
...................................................................................................................................
"TRUNC/ROUND: exceeded the limit of decimals"
393
© 2014 Advanced Systems srl
120 SDS-0130
...................................................................................................................................
"DELETE KEYS statement is not allowed on a view"
394
121 SDS-0131
...................................................................................................................................
"Internal error; undefined type; analyze the context!"
394
122 SDS-0132
...................................................................................................................................
"External function not found in Catalog"
395
123 SDS-0133 "External function needs in the first parameter an
alphanumeric
...................................................................................................................................
constant (FunctionId)"
395
124 SDS-0134
...................................................................................................................................
"External function error"
395
125 SDS-0135
...................................................................................................................................
"Function not available in this Sadas version"
395
126 SDS-0136
...................................................................................................................................
"Data are not compatible with the Server"
396
127 SDS-0137 "Wrong number of columns in the sub-query of the FROM
clause"
................................................................................................................................... 396
128 SDS-0138
...................................................................................................................................
"INSERT: wrong number of constants"
397
129 SDS-0139
...................................................................................................................................
"INSERT: wrong type of a constant"
397
130 SDS-0140
...................................................................................................................................
"Table locked"
398
131 SDS-0141
...................................................................................................................................
"DIGITS function allows only one integer column"
398
Part XIII How to Read Syntax Diagrams
400
1 Graphic
...................................................................................................................................
Syntax Diagrams
400
Required Keyw..........................................................................................................................................................
ords and Parameters
402
Optional Keyw..........................................................................................................................................................
ords and Parameters
403
Syntax Loops .......................................................................................................................................................... 403
Multipart Diagrams
.......................................................................................................................................................... 404
2 Backus-Naur
...................................................................................................................................
Form Syntax
404
Index
© 2014 Advanced Systems srl
406
Part
I
Introduction to SADAS SQL
1
18
Introduction to SADAS SQL
Structured Query Language (SQL) is the set of statements used by any application needing to
access data in a SADAS database. Application programs and SADAS tools often allow users
to access the database without using SQL directly, but these applications in turn use SQL when
executing the user request.
1.1
History of SQL
Dr. E. F. Codd published the paper, "A Relational Model of Data for Large Shared Data
Banks", in June 1970 in the Association of Computer Machinery (ACM) journal,Communications
of the ACM. Codd's model is now accepted as the definitive model for relational database
management systems (RDBMS). The language, Structured English Query Language (SEQUEL)
was developed by IBM Corporation, Inc., to use Codd's model. SEQUEL later became SQL
(still pronounced "sequel"). In 1979, Relational Software, Inc.
introduced the first
commercially available implementation of SQL. Today, SQL is accepted as the standard
RDBMS language.
1.2
SQL Standards
Industry-accepted committees are the American National Standards Institute (ANSI) and the
International Organization for Standardization (ISO), which is affiliated with the International
Electrotechnical Commission (IEC). Both ANSI and the ISO/IEC have accepted SQL as the
standard language for relational databases. When a new SQL standard is simultaneously
published by these organizations, the names of the standards conform to conventions used by
the organization, but the standards are technically identical.
The latest SQL standard was adopted in July 2003 and is often called SQL:2003. One part of
the SQL standard, Part 14, SQL/XML (ISO/IEC 9075-14) was revised in 2006 and is often
referenced as "SQL/XML:2006".
The formal names of this standard, with the exception of SQL/XML, are:
ANSI/ISO/IEC 9075:2003, "Database Language SQL", Parts 1 ("SQL/Framework"),
2 ("SQL/Foundation"), 3 ("SQL/CLI"), 4 ("SQL/PSM"), 9 ("SQL/MED"), 10
© 2014 Advanced Systems srl
Introduction to SADAS SQL
19
("SQL/OLB"), 11("SQL/Schemata"), and 13 ("SQL/JRT")
ISO/IEC 9075:2003, "Database Language SQL", Parts 1 ("SQL/Framework"), 2
("SQL/Foundation"), 3 ("SQL/CLI"), 4 ("SQL/PSM"), 9 ("SQL/MED"), 10 ("SQL/
OLB"), 11("SQL/Schemata"), and 13 ("SQL/JRT")
The formal names of the revised part 14 are:
ANSI/ISO/IEC 9075-14:2006, "Database Language SQL", Part 14 ("SQL/XML")
ISO/IEC 9075-14:2006, "Database Language SQL", Part 14 ("SQL/XML")
1.2.1
How SQL Works
The strength of SQL provides benefits for all types of users, including application programmers,
database administrators, managers, and end users.
Technically speaking, SQL is a data sublanguage. The purpose of SQL is to provide an
interface to a relational database (such as SADAS database), and all SQL statements are
instructions to the database. In this SQL differs from general-purpose programming languages
like C and BASIC. Among the features of SQL are the following:
It processes sets of data as groups rather than as individual units.
It provides automatic navigation to the data.
It uses statements which are complex and powerful individually, and which therefore
stand alone.
SQL lets you work with data at the logical level. You need to be concerned with the
implementation details only when you want to manipulate the data. For example, to retrieve a
set of rows from a table, you define a condition used to filter the rows. All rows satisfying the
condition are retrieved in a single step and can be passed as a unit to the user, to another SQL
statement, or to an application. You need not deal with the rows one by one, nor do you have
to worry about how they are physically stored or retrieved.
All SQL statements use the optimizer, a part of SADAS database that determines the most
© 2014 Advanced Systems srl
Introduction to SADAS SQL
20
efficient means of accessing the specified data.
SQL provides statements for a variety of tasks, including:
Querying data
Creating, replacing, altering, and dropping objects
Controlling access to the database and its objects
Guaranteeing database consistency and integrity
SQL unifies all of the preceding tasks in one consistent language.
1.2.2
Common Language for All Relational Databases
All major relational database management systems support SQL, so you can transfer all skills
you have gained with SQL from one database to another. In addition, all programs written in
SQL are portable. They can often be moved from one database to another with very limited
changes.
1.3
Lexical Conventions
The following lexical conventions for issuing SQL statements apply specifically to the SADAS
database implementation of SQL, but are generally acceptable in other SQL implementations.
When you issue a SQL statement, you can include one or more tabs, carriage returns, spaces, or
comments anywhere a space occurs within the definition of the statement. Thus, SADAS
database evaluates the following two statements in the same manner:
SELECT last_name,salary*12,MONTHS_BETWEEN(hire_date, SYSDATE)
FROM employees
WHERE department_id = 30
ORDER BY last_name;
SELECT last_name,
salary * 12,
MONTHS_BETWEEN( hire_date, SYSDATE )
FROM employees
ORDER BY last_name;
© 2014 Advanced Systems srl
Introduction to SADAS SQL
21
Case is insignificant in reserved words, keywords, identifiers and parameters. However, case is
significant in text literals and quoted names.
SQL statements are terminated differently in different programming environments. This
documentation set uses the default SQL Editor character, the semicolon (;).
1.4
Tools
Sadas provides a number of utilities to facilitate your SQL development process:
SADASManager is a graphical tool (based on client-server architecture) that lets you
browse, create, edit, and delete (drop) database objects, run SQL statements and
scripts, manipulate and export data, and create and view reports. With SADASManager,
you can connect to any target SADAS database using standard SADAS database
authentication. Once connected, you can perform operations on objects in the
database.
SCL (SADAS Console) is an interactive and batch query tool that is installed with
every SADAS Database server or client installation. It has a command-line user
interface.
SADASWeb is a web tool that lets you browse, create, edit, and delete (drop) database
objects, run SQL statements and scripts, manipulate and export data, and create and
view reports. You can also connect to schemas for selected third-party (non-SADAS)
databases, such as Oracle, DB2, MySQL, Microsoft SQL Server, and Microsoft Access,
view metadata and data in these databases, and migrate these databases to SADAS.
The SADAS Call Interface and SADAS Package let you embed standard SQL statements
within a procedural programming language.
The SADAS Call Interface (SCI) lets you embed SQL statements in C programs.
The SADAS Package lets you embed SQL statements in GUI and WEB Delphi
© 2014 Advanced Systems srl
Introduction to SADAS SQL
22
programs.
1.5
SADAS Datatypes
Each value manipulated by the SADAS database has a datatype. The datatype of a value
associates a fixed set of properties to the value. These properties cause SADAS to treat values
of each datatype differently from other datatypes.
When you create a table, you must specify a datatype for each of its columns. These datatypes
define the domain of values that each column can contain or each argument can have. For
example, DATE columns cannot accept the value February 29 (except for a leap year) or the
values 2 or 'SKY'. Each value subsequently placed in a column assumes the datatype of the
column. For example, if you have '01/01/1998' into a DATE column, then Sadas treats
the '01/01/1998' character string as a DATE value after verifying that it translates to a valid
date.
The syntax of SADAS datatypes appears in the next section diagrams.
A datatype can be either scalar or nonscalar. A scalar type contains an atomic value, whereas a
nonscalar (sometimes called a "collection") contains a set of values. SADAS supports only
scalar datatypes.
© 2014 Advanced Systems srl
Introduction to SADAS SQL
1.6
23
SADAS Supported Datatypes
The following table summarizes all datatypes supported by SADAS.
Datatype
Description
CHAR
CHARACTER
These datatypes are included in alphanumeric domains. Size is an optional
parameter and can range from 1 to 65535.
© 2014 Advanced Systems srl
Introduction to SADAS SQL
Datatype
24
Description
VARCHAR
[ (size) ]
NUMBER (p [, s])
It's a number having precision p (not optional) and scale s (optional): p and s are
ranging from 1 to 18. The default value for p is 1, the default value for s is 0: if
the scale is specified SADAS rounds values to scale. Both precision and scale are
in decimal digits. NUMBER values are represented internally as INT46 using a
number of bytes according to the size of max and min values. A number value
generally requires from 1 to 8 bytes.
DEC [ (p [, s]) ]
DECIMAL [ (p [, s]) ]
NUMERIC [ (p [, s]) ]
FLOAT [ (p [, s]) ]
REAL [ (p [, s]) ]
“DOUBLE
PRECISION” [ (p [, s]) ]
It's a number having precision p (optional) and scale s (optional). The
precision p can range from 1 to 18. The scale s can range from 1 to 18. Both
precision and scale are in decimal digits. A number value internally requires from
1 to 8 bytes. The default precision value is 1. If the scale is specified, SADAS
rounds values to scale; the default scale value is 0.
When precision (and optional scale) is specified the field is represented internally
as INT46, using a number of bytes to represent max and min value. When
precision (and optional scale) is not specified the field is represented internally as
DOUBLE of 8 bytes.
INT [ (size) ]
INTEGER [ (size) ]
SMALLINT [ (size) ]
It's an integer number and size is optional. The size parameter can range from 1
to 18. A number value internally requires from 1 to 8 bytes. The default value
for size is 1. The field is represented internally as INT46, using a number of bytes
according to the size of max and min values.
DATE
Valid dates range from 01/01/0001 to 31/12/9999. The default format is
‘DD/MM/YYYY’; the format can be determined explicitly by the
NLS_DATE_FORMAT parameter
or
implicitly
by
the NLS_TERRITORY parameter. The internal size is fixed at 3 bytes.
This datatype contains only the date fields YEAR, MONTH, DAY.
TIME
Valid time range from 00:00:00.001 to 23:59:59.999. The default format is ‘HH:
MM:SS:MS’; the format can be determined explicitly by the
NLS_DATE_FORMAT parameter
or
implicitly
by
the NLS_TERRITORY parameter. The internal size is fixed at 4 bytes. This
datatype contains only the time fields DAY, HOUR, MINUTE, SECOND,
MILLISECOND.
TIMESTAMP
Valid timestamp range from 01/01/0001-00:00:00.001 to 31/12/999923:59:59.999. The default format is ‘DD/MM/YYYY-HH:MM:SS:MS’; the
format can be determined explicitly by the NLS_DATE_FORMAT parameter
or implicitly by the NLS_TERRITORY parameter. The internal size is fixed at 8
bytes.
This
datatype
contains
only
the
timestamp
fields YEAR, MONTH, DAY, HOUR, MINUTE,
SECOND,
MILLISECOND.
CODE
This datatype is to encode discrete and known field domains: the limit of distinct
values is 65535.
A CODE value is represented internally as a SMALLINT (1 or 2 bytes), with a
common decode table.
© 2014 Advanced Systems srl
Introduction to SADAS SQL
1.7
25
Character datatypes
Character datatypes
Character datatypes store character (alphanumeric) data, which are words and free-form text in
the database character set. They are less restrictive than other datatypes and consequently have
fewer properties. For example, character columns can store any alphanumeric value, while
NUMBER
columns can only store numeric values.
Following datatypes are used for character data:
CHAR Datatype
CHARACTER Datatype
VARCHAR Datatype
All these datatypes work as ANSI CHAR DATATYPE and type string columns. The size
parameter is optional. The default length for a CHAR column is 1 byte and the maximum
allowed is 65535 bytes.
These datatypes specify a fixed-length character string. SADAS computes at loading time the
proper size (length in bytes) for each column by setting this size to the largest value found in
the column (Max InfoLength). All values shorter than the column length are blank-padded to
the maximum length.
1.8
Numeric datatypes
The SADAS database numeric datatypes store null, positive and negative fixed and floatingpoint numbers. Size and scale can range from 1 to 18.
INT, INTEGER and SMALLINT datatypes need only size parameter, for numeric values
without decimals: these datatypes are represented internally as INT46 values.
NUMBER datatype needs precision parameter, with scale optional. If scale is specified, this
© 2014 Advanced Systems srl
Introduction to SADAS SQL
26
datatype represents fixed-point values, else INT64 values. This datatype is represented
internally as INT46 value.
All others numeric datatypes (DEC, DECIMALS, NUMERIC, FLOAT, REAL, DOUBLE
PRECISION) have optional parameters (precision and scale). If size and scale are not specified,
these datatypes represent floating-point values; the absence of precision and scale designators
specifies the maximum range and precision for a Sadas number. If precision only is specified, this
datatype represents INT64 values. If scale is specified, this datatype represents fixed-point
values. These datatypes are represented internally as INT46 or DOUBLE values.
An integer can be defined in the following form:
[type](p)
This represents a fixed-point number with precision p and scale 0 and is equivalent to NUMBER
(p,0).
A fixed-point number can be defined in the following form:
[type](p,s)
where:
p
is the precision, or the maximum number of significant decimal digits, where the most
significant digit is the left-most nonzero digit, and the least significant digit is the rightmost known digit. Sadas guarantees the portability of numbers with precision of up to
18 total digits, which is equivalent to max 18 decimal digits depending on the position
of the decimal point.
s
is the scale, or the number of digits from the decimal point to the least significant
digit. The scale can range from 1 to 18.
It is good practice to specify the scale and precision of a fixed-point number column for extra
integrity checking on input. Specifying scale and precision does not force all values to a fixed
length. If a value exceeds the max precision, then Sadas returns an error. If a value exceeds the
max scale, then Sadas returns an error.
A floating-point number can be defined in the following form:
[type]
© 2014 Advanced Systems srl
Introduction to SADAS SQL
1.9
27
Datetime datatypes
The datetime datatypes are DATE, TIME, and TIMESTAMP. Datetime datatypes are made up of
several fields and the values of such fields globally determine the value of the datatype.
Following table lists the datetime fields and their possible values.
Ta ble - Da t e t ime Fie lds a nd V a lue s
1.9.1
Datetime Field
Valid Values for Datetime
YEAR
1 to 9999 (excluding year 0)
MONTH
01 to 12
DAY
01 to 31 (limited by the values of MONTH and YEAR, according to the rules of
the current NLS calendar parameter)
HOUR
00 to 23
MINUTE
00 to 59
SECOND
00 to 59
MILLISECOND
000 to 999
DATE Datatype
The DATE datatype stores date information. Although date information can be represented in
both character and numeric datatypes, the DATE datatype has special associated properties. For
each DATE value, Sadas stores the following information: century, year, month, day.
1.9.2
TIME Datatype
The TIME datatype stores time information. Although time information can be represented in
both character and numeric datatypes, the TIME datatype has special associated properties. For
each TIME value, Sadas stores the following information: hour, minutes, seconds and
milliseconds.
© 2014 Advanced Systems srl
Introduction to SADAS SQL
1.9.3
28
TIMESTAMP Datatype
The TIMESTAMP datatype stores date and time information. Although date and time information
can be represented in both character and numeric datatypes, the TIMESTAMP datatype has
special associated properties. For each TIMESTAMP value, Sadas stores the following
information: century, year, month, day, hour, minutes, seconds and milliseconds.
1.10
Code datatype
The code datatype represents discrete domains of values (example: Nation, Region, …) where
each value is usually represented in input through a coding mechanism (i.e. NA=Naples,
MI=Milan, …). Sadas does not store explicitly such values but internally encodes them through
integer numbers, having length of 1 byte if distinct values are less than 256, or 2 bytes if
distinct values are less than 65536. Sadas mantains a catalog decode table to be used at
presentation time for recreating original values.
1.11
Datatype Comparison Rules
This section describes how Sadas Database compares values of each datatype.
1.11.1 Numeric Values
A larger value is considered greater than a smaller one. All negative numbers are lower than
zero and all positive numbers greater than zero. Thus, -1 is lower than 100; -100 is lower than 1.
1.11.2 Datetime Values
A later date is considered greater than an earlier one. For example, the date '29/03/2005' is
lower than
'05/01/2006' and '05/01/2006-13:35:00:000' is greater than '05/01/2006-
10:09:00:000'.
1.11.3 Character Values
Character values are compared on the basis of two measures:
Binary sorting
© 2014 Advanced Systems srl
Introduction to SADAS SQL
29
Blank-padded or nonpadded comparison semantics
The following subsections describe the two measures.
1.11.3.1 Binary Comparisons
In binary comparison, which is the default, Sadas compares character strings according to the
concatenated value of the numeric codes of the characters in the database character set. One
character is greater than another if it has a greater numeric value than the other in the character
set. Sadas considers blanks to be less than any other character, which is true in most character
sets.
These are some common character sets:
7-bit ASCII (American Standard Code for Information Interchange)
EBCDIC Code (Extended Binary Coded Decimal Interchange Code)
1.11.3.2 Blank-Padded Comparison Semantics
With blank-padded semantics, if the two values have different lengths, then Sadas first adds
blanks to the end of the shorter one so their lengths are equal. Sadas then compares the values
character by character up to the first character that differs. The value with the greater character
in the first differing position is considered greater. If two values have no differing characters,
then they are considered equal. This rule means that two values are equal if they differ only in
the number of trailing blanks. Sadas uses blank-padded comparison semantics only when values
in the comparison have not same length.
With nonpadded semantics, Sadas compares two values character by character up to the first
character that differs. The value with the greater character in that position is considered
greater. If two values of different length are identical up to the end of the shorter one, then the
longer value is considered greater. If two values of equal length have no differing characters,
then the values are considered equal. Sadas uses nonpadded comparison semantics only when
values in the comparison have same length or one or both of values are text literals.
The results of comparing two character values using different comparison semantics may vary.
The table that follows shows the results of comparing five pairs of character values using each
comparison semantic. Usually, the results of blank-padded and nonpadded comparisons are the
© 2014 Advanced Systems srl
Introduction to SADAS SQL
30
same. The last comparison in the table illustrates the differences between the blank-padded and
nonpadded comparison semantics.
Blank-Padded Nonpadded
'ac' > 'ab'
'ac' > 'ab'
'ab' > 'a '
'ab' > 'a
'
'ab' > 'a'
'ab' > 'a'
'ab' = 'ab'
'ab' = 'ab'
'a ' = 'a'
'a ' > 'a'
Portions of the ASCII and EBCDIC character sets appear in Table Ascii and Table EBCDIC.
Uppercase and lowercase letters are not equivalent. The numeric values for the characters of a
character set may not match the linguistic sequence for a particular language.
Ta ble - A SCII Cha ra ct e r Se t
Decimal
© 2014 Advanced Systems srl
Decimal
Symbol
value
Symbol
value
blank
32
;
59
!
33
<
60
"
34
=
61
#
35
>
62
$
36
?
63
%
37
@
64
&
38
A-Z
65-90
'
39
[
91
(
40
\
92
)
41
]
93
Introduction to SADAS SQL
31
Decimal
Decimal
Symbol
value
Symbol
value
*
42
^
94
+
43
_
95
,
44
'
96
-
45
a-z
97-122
.
46
{
123
/
47
|
124
0-9
48-57
}
125
:
58
~
126
Ta ble - EBCDIC Cha ra ct e r Se t
Decimal
© 2014 Advanced Systems srl
Decimal
Symbol
value
Symbol
value
blank
64
%
108
¢
74
_
109
.
75
>
110
<
76
?
111
(
77
:
122
+
78
#
123
|
79
@
124
&
80
'
125
!
90
=
126
Introduction to SADAS SQL
32
Decimal
1.12
Decimal
Symbol
value
Symbol
value
$
91
"
127
*
92
a-i
129-137
)
93
j-r
145-153
;
94
s-z
162-169
ÿ
95
A-I
193-201
-
96
J-R
209-217
/
97
S-Z
226-233
Literals
The terms literal and constant value are synonymous and refer to a fixed data value. For
example, 'JACK', 'BLUE ISLAND', and '101' are all character literals; 5001 is a numeric literal.
Character literals are enclosed in single quotation marks so that Sadas can distinguish them
from schema object names.
Many SQL statements and functions require you to specify character and numeric literal values.
You can also specify literals as part of expressions and conditions. You can specify character
literals with the 'text' notation and numeric literals with the integer, or number notation,
depending on the context of the literal. The syntactic forms of these notations appear in the
sections that follow.
To specify a datetime datatype as a literal, you must take into account any optional precisions
included in the datatypes.
1.12.1 Text Literals
Use the text literal notation to specify values whenever 'string' appears in the syntax of
expressions, conditions, SQL functions, and SQL statements in other parts of this reference.
© 2014 Advanced Systems srl
Introduction to SADAS SQL
33
This reference uses the terms text literal, character literal, and string interchangeably. Text,
character, and string literals are always surrounded by single quotation marks.
Here are some valid text literals:
'Hello'
'SADAS.dbs'
'Jackie''s raincoat'
'09/03/1998'
The syntax of text literals or strings follows:
string::=
1.12.2 Numeric Literals
Use numeric literal notation to specify fixed and floating-point numbers.
1.12.2.1 Integer Literals
You must use the integer notation to specify an integer whenever integer appears in
expressions, conditions, SQL functions, and SQL statements described in other parts of this
reference.
The syntax of integer follows:
integer::=
where digit is one of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
An integer can store a maximum of 20 digits of precision.
Here are some valid integers:
7
+255
© 2014 Advanced Systems srl
Introduction to SADAS SQL
34
1.12.2.2 NUMBER and Floating-Point Literals
You must use the number or floating-point notation to specify values whenever number or n
appears in expressions, conditions, SQL functions, and SQL statements in other parts of this
reference.
The syntax of number follows:
number::=
where
+ or - indicates a positive or negative value. If you omit the sign, then a positive value
is the default.
digit
is one of 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9.
e or E indicates that the number is specified in scientific notation. The digits after the E
specify the exponent. The exponent can range from -20 to 20.
Here are some valid NUMBER literals:
25
+6.34
0.5
25e-03
-1
© 2014 Advanced Systems srl
Introduction to SADAS SQL
35
1.12.2.3 Datetime Literals
Sadas Database supports three datetime datatypes: DATE, TIME and TIMESTAMP.
Date Literals: you can specify a DATE value as a string literal, or you can convert a character
value to a date value with the TO_DATE function.
Time Literals: you can specify a TIME value as a string literal, or you can convert a character
value to a time value with the TO_TIME function.
Timestamp Literals: you can specify a TIMESTAMP value as a string literal, or you can convert a
character value to a timestamp value with the TO_TIMESTAMP function.
The string format is fixed, as described in the following table:
1.13
Datatype
Format
DATE
'DD/MM/YYYY'
TIME
'HH:MM:SS:MS'
TIMESTAM
P
'DD/MM/YYYY-HH:MM:SS:MS
'
Comments
You can create comments within the SQL statements, which will be stored as part of the
application code that executes the SQL statements.
Comments can make your application easier for you to read and maintain. For example, you
can include a comment in a statement that describes the purpose of the statement within your
application. Comments within SQL statements do not affect the statement execution.
A comment can appear between any keywords, parameters, or punctuation marks in a
statement. You can include a comment in a statement in two ways:
© 2014 Advanced Systems srl
Introduction to SADAS SQL
36
Begin the comment with a slash and an asterisk (/*). Proceed with the text of the
comment. This text can span multiple lines. End the comment with an asterisk and a
slash (*/). The opening and terminating characters need not be separated from the text
by a space or a line break.
Begin the comment with -- (two hyphens). Proceed with the text of the comment. This
text cannot extend to a new line. End the comment with a line break.
A SQL statement can contain multiple comments of both styles. The text of a comment can
contain any printable characters in your database character set.
Example
These statements contain different comments:
SELECT last_name, salary + commission_pct ,
job_id, e.department_id
/* Select all employees whose compensation is
greater than that of Pataballa.*/
FROM employees e, departments d
WHERE e.department_id = d.department_id
AND salary + commission_pct > 0
SELECT last_name,
-- select the name
salary + commission_pct,
-- total compensation
job_id,
-- job
e.department_id
-- and department
FROM employees e,
-- of all employees
departments d
WHERE e.department_id = d.department_id
1.14
Schema/Database Objects
Sadas Database recognizes objects that are associated with a particular schema/database and
objects that are not associated with any particular schema, as described in the sections that
follow.
1.14.1 Schema/Database Objects
This reference uses the terms schema and database interchangeably. In Sadas a schema is a
collection of logical structures of data, or schema objects. A schema is owned by a database
user. Schema objects can be created and manipulated with SQL and include the following types
© 2014 Advanced Systems srl
Introduction to SADAS SQL
37
of objects:
Indexes
Tables
Views
Synonyms
1.14.2 Nonschema Objects
Other types of objects are also stored in the database and can be created and manipulated with
SQL, but are not contained in a schema:
Roles
Users
© 2014 Advanced Systems srl
Part
II
Pseudocolumns
2
39
Pseudocolumns
A pseudocolumn is an entity which behaves like a table column, but is not always physically
stored in the table. You can select from pseudocolumns, but you cannot update, or delete their
values.
A pseudocolumn is also similar to a function without arguments. However, functions without
arguments typically return the same value for every row in the result set, whereas
pseudocolumns typically return a different value for each row.
This chapter contains the following sections:
¦ ROWID Pseudocolumn
¦ ROWNUM Pseudocolumn
2.1
ROWID Pseudocolumn
For each row in a database table, the ROWID pseudocolumn returns the address of the row.
Sadas Database rowid values contain information necessary to locate a row:
¦ In Sadas the ordinal number of record if sufficient for identifying a record in a table.
Usually, a rowid value uniquely identifies a row within a table, but not within a database.
Values of the ROWID pseudocolumn have the datatype INTEGER.
Rowid values have several important uses:
¦ They are the fastest way to access a single row.
¦ They can show you how the rows in a table are stored.
¦ They are unique identifiers for rows in a table.
You cannot use ROWID as the primary key of a table.
Although you can use the ROWID pseudocolumn in the SELECT, WHERE, GROUP BY and
ORDER BY clause of a query, these pseudocolumn values are not physically stored stored in
the table but are referenced by all index files in the database.
You cannot update a value of the ROWID pseudocolumn.
© 2014 Advanced Systems srl
Pseudocolumns
40
Example This statement selects the address of all rows that contain data for employees in
department 20:
SELECT ROWID, last_name
FROM employees
WHERE department_id = 20;
2.2
ROWNUM Pseudocolumn
For each row returned by a query, the ROWNUM pseudocolumn represents a number
indicating the order in which Sadas selects the row from a table or set of joined rows. While
ROWID refers to the position of the row in the original table, ROWNUM refers to the position
of the row in the output set.
The first row selected has a ROWNUM of 1, the second has 2, and so on.
You can use ROWNUM only to limit the number of rows returned by a query, as in this
example:
SELECT * FROM employees WHERE ROWNUM < 11;
So you can use ROWNUM only in WHERE clause and only with (<, <=) relational operator.
© 2014 Advanced Systems srl
Part
III
Operators
3
42
Operators
An operator manipulates data items and returns a result. Syntactically, an operator appears
before or after an operand or between two operands.
This section discusses nonlogical (non-Boolean) operators. These operators cannot be used for
defining the conditions of a WHERE or HAVING clause in queries or subqueries. For information
on logical operators, which define conditions, refer to section “Conditions”.
3.1
About SQL Operators
Operators manipulate individual data items called operands or arguments. Operators are
represented by special characters or by keywords. For example, the multiplication operator is
represented by an asterisk (*).
3.1.1
Unary and Binary Operators
The two general classes of operators are:
unary: A unary operator operates on only one operand. A unary operator typically
appears with its operand in this format: operator operand
binary: A binary operator operates on two operands. A binary operator appears with its
operands in this format: operand1 operator operand2
Other operators with special formats accept more than two operands.
3.1.2
Operator Precedence
Precedence is the order in which Sadas Database evaluates different operators in the same
expression. When evaluating an expression containing multiple operators, Sadas evaluates
operators with higher precedence before evaluating those with lower precedence. Sadas
evaluates operators with equal precedence from left to right within an expression.
Following table lists the levels of precedence among SQL operators from high to low.
Operators listed on the same line have the same precedence.
Ta ble - SQL Ope ra t or Pre ce de nce
© 2014 Advanced Systems srl
Operators
43
Operator
+, -
Operation
(as unary operators)
Identity, negation
*, /
+, -
Multiplication, division
(as binary operators), + (as concatenation)
SQL conditions are evaluated after SQL operators
Addition, subtraction, concatenation
See "Condition Precedence"
Precedence Example:
In the following expression, multiplication has a higher precedence than addition, so Sadas first
multiplies 2 by 3 and then adds the result to 1.
1+2*3
You can use parentheses in an expression to override operator precedence. Sadas evaluates
expressions inside parentheses before evaluating those outside.
SQL also supports set operators (UNION, UNION ALL, INTERSECT, and MINUS), which combine
sets of rows returned by queries, rather than individual data items. All set operators have equal
precedence.
3.2
Arithmetic Operators
You can use an arithmetic operator with one or two arguments to negate, add, subtract,
multiply, and divide numeric values. Some of these operators are also used in arithmetic. The
arguments to the operator must be numeric datatypes.
Unary arithmetic operators return the same datatype as the numeric datatype of the argument.
For binary arithmetic operators, Sadas determines the argument with the highest numeric
precedence, implicitly converts the remaining arguments to that datatype, and returns that
datatype.
Following table lists arithmetic operators.
Ta ble - A rit hme t ic Ope ra t ors
© 2014 Advanced Systems srl
Operators
44
Operator Purpose
+-
Example
SELECT * FROM order_items
When these denote a positive or negative WHERE quantity = -1
expression, they are unary operators.
ORDER BY order_id,
line_item_id,
product_id;
+-
When they add or subtract, they are binary
operators.
*/
Multiply, divide. These are binary operators.
SELECT hire_date
FROM employees
WHERE quantiy - 100
> 1000 ORDER BY hire_date;
SELECT hire_date
FROM employees
WHERE 100*quantiy > 100000
ORDER BY hire_date;
Do not use two consecutive minus signs (--) in arithmetic expressions to indicate double
negation or the subtraction of a negative value. The characters -- are used to begin comments
within SQL statements. You should separate consecutive minus signs with a space or
parentheses.
3.3
Concatenation Operators
The concatenation operators manipulate character strings. Following table describes the
concatenation operators.
Ta ble - Conca t e na t ion Ope ra t ors
Operator
Purpose
Example
+
Concatenates character strings.
SELECT 'Name is ' + last_name
FROM employees;
||
Concatenates character strings.
SELECT 'Name is ' || last_name
FROM employees;
On most platforms, the concatenation operator is represented by two solid vertical bars,
however Sadas platform also accepts plus sign (+) for this purpose. You can use the two
concatenation operators simultaneously in the same SQL statement.
Concatenation Example
SELECT col1+col2+col3+col4 as "Concatenation" FROM tab1;
© 2014 Advanced Systems srl
Operators
45
SELECT col1||col2||col3||col4 as "Concatenation" FROM tab1;
SELECT col1+col2||col3||col4 as "Concatenation" FROM tab1;
3.4
Set Operators
Set operators combine the results of two component queries into a single result.
Queries containing set operators are called compound queries. Following table lists SQL set
operators. They are fully described, including examples and restrictions on these operators, in
chapter "The UNION [ALL], INTERSECT, MINUS Operators".
Ta ble - Se t Ope ra t ors
Operator
Returns
UNION
All distinct rows selected by either query
UNION ALL
All rows selected by either query, including all duplicates
INTERSECT
All distinct rows selected by both queries
MINUS
All distinct rows selected by the first query but not the second
© 2014 Advanced Systems srl
Part
IV
SQL Functions
4
47
SQL Functions
SQL functions are similar to operators since they manipulate data items and return a result,
however they differ from operators in the format of their arguments.
This format enables them to operate on zero, one, two, or more arguments:
function(argument, argument, ...)
4.1
About SQL Functions
SQL functions are built into Sadas Database and are available for use in various appropriate
SQL statements. If a SQL function is called with an argument of a datatype other than the
datatype expected by the SQL function, then Sadas returns an error.
In the syntax diagrams for SQL functions, arguments are indicated by their datatypes. When the
parameter function appears in SQL syntax, replace it with one of the functions described in
this section. Functions are grouped by the datatypes of their arguments and their return values.
The syntax for the different categories of functions is as follows:
function::==
single_row_function::=
© 2014 Advanced Systems srl
SQL Functions
48
numeric_function
character_function
datetime_function
conversion_function
code_function
The following sections will list the built-in SQL functions for each of the groups illustrated in
the preceding diagrams. All of the built-in SQL functions will be described in alphabetical
order.
4.1.1
Single-Row Functions
Single-row functions return a single result row for every row of a queried table or view. These
functions can appear in select lists, WHERE clauses and HAVING clauses.
4.1.1.1
Numeric Functions
Numeric functions accept numeric input and return numeric values. Most numeric functions
that return NUMBER values that are accurate to 18 decimal digits.
The numeric functions are:
ABS
ACOS
ASIN
ATAN
BITAND
BITOR
© 2014 Advanced Systems srl
SQL Functions
49
BITXOR
CEIL(ING)
COS
COSH
EXP
FLOOR
LN
LOG
M OD
PI
POWER
REM AINDER
ROUND
SIGN
SIN
SINH
SQRT
TAN
TANH
TRUNC(ATE)
4.1.1.2
Character Functions Returning Character Values
Character functions that return character values return values of the CHAR, CHARACTER
and VARCHAR datatypes, which have the same internal representation.
The length of the value returned by the function is limited by the maximum length of column
and constant parameters. In any case the maximum length can range from 1 to 2^32 bytes.
The character functions that return character values are:
CHR
CONCAT
INITCAP
LCASE
LOWER
LPAD
LTRIM
© 2014 Advanced Systems srl
SQL Functions
50
REGEXP_REPLACE
REGEXP_SUBSTR
REPLACE
RPAD
RTRIM
SOUNDEX
SUBSTR(ING)
TRANSLATE
TRIM
UCASE
UPPER
4.1.1.3
Character Functions Returning Numeric Values (COPY)
Character functions that return numeric values can accept arguments of any character datatype.
The character functions that return numeric values are:
ASCII
INSTR
LENGTH
POSITION
REGEXP_INSTR
4.1.1.4
Datetime Functions
Datetime functions operate on DATE, TIME and TIMESTAMP
The datetime functions are:
ADD_M ONTH
CURDATE
CURRENT_DATE
CURRENT_TIM E
CURRENT_TIM ESTAM P
CURTIM E
DATEADD
© 2014 Advanced Systems srl
SQL Functions
51
DATEDIFF
DATEPART
DAY_OF_TEAR
DAY_OF_WEEK
DAYNAM E
LAST_DAY
LAST_WORK_DAY
LOCALTIM ESTAM P
M ONTHNAM E
M ONTHS_BETWEEN
NEXT_DAY
NOW
SYSDATE
SYSTIM E
SYSTIM ESTAM P
TODAY
4.1.1.5
General Comparison Functions
The general comparison functions determine the greatest and or least value from a set of
values.
The general comparison functions are:
GREATEST
LEAST
4.1.1.6
Conversion Functions
Conversion functions convert a value from one datatype to another.
Generally, the form of the function names follows the convention " TO datatype ", where
the datatype is the output datatype.
The SQL conversion functions are:
BIN_TO_NUM
© 2014 Advanced Systems srl
SQL Functions
52
HEXTOSTR
STRTOHEX
TO_NUM BER
TO_TIM ESTAM P
TO_BASE
TO_CHAR
TO_CODE
TO_DATE
TO_DESC
TO_TIM E
4.1.1.7
Encoding and Decoding Functions
The encoding and decoding functions allow to inspect and decode data in the database.
The encoding and decoding functions are:
DECODE
SDS_HASH
VSIZE
4.1.1.8
Masking functions
Masking functions allow to change attribute values of each single row in a table while preserving global
characteristics of such values (i.e. distribution of effective values, form of names, etc.) .
They are normally used in order to easily derive from a production environment a realistic test database
having similar size and data characteristics, but without the same combination of data for each single
row (so inhibiting the reconstruction of attributes for the original items).
This activity is greatly facilitated by the physical column-based organization adopted by Sadas, where
each column can be easily manipulated on its own without impacting on the remaining attributes of the
table.
Masking functions are:
© 2014 Advanced Systems srl
SQL Functions
53
SHUFFLE
SUBSTITUTE_WITH
4.1.2
Aggregate Functions
Aggregate functions return a single result row based on groups of rows, rather than on single
rows.
Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are
commonly used with the GROUP BY [DISTRIBUTE BY] clause in a SELECT statement, where
Sadas Database divides the rows of a queried table or view into groups. In a query containing a
GROUP BY [DISTRIBUTE BY]
clause, the elements of the select list can be aggregate functions,
GROUP BY [DISTRIBUTE BY]
expressions, constants, or expressions involving one of these.
Sadas applies the aggregate functions to each group of rows and returns a single result row for
each group.
If you omit the GROUP BY [DISTRIBUTE BY] clause, then Sadas applies aggregate functions in
the select list to all the rows in the queried table or view. You use aggregate functions in the
HAVING
clause to eliminate groups from the output based on the results of the aggregate
functions, rather than on the values of the individual rows of the queried table or view.
All aggregate functions except COUNT(*) and GROUPING ignore nulls.
The aggregate functions are:
AVG
COUNT
M AX
M IN
STDDEV
SUM
VARIANCE
GROUPING
© 2014 Advanced Systems srl
SQL Functions
4.2
54
ABS
Syntax
Purpose
ABS
returns the absolute value of n.
This function takes as an argument any numeric datatype. The function returns the same
datatype as the numeric datatype of the argument.
Examples
The following example returns the absolute value of -15 and +3:
SELECT ABS(-15) as "Absolute" FROM DUAL;
Absolute
---------15
SELECT ABS(+3) as "Absolute" FROM DUAL;
Absolute
---------3
4.3
ACOS
Syntax
Purpose
ACOS
returns the arc cosine of n. The argument n must be in the range of -1 to 1, and the
function returns a value in the range of 0 to pi, expressed in radians.
This function takes as an argument any numeric datatype and returns FLOAT datatype.
© 2014 Advanced Systems srl
SQL Functions
55
Examples
The following example returns the arc cosine of 0.3:
SEL ECT ACOS( 0 . 3 ) " Ar c _ Co s i n e " FROM DUAL ;
Ar c _ Co s i n e
---------1. 2661036727795
4.4
ADD_MONTHS
Syntax
date
can be of datatype DATE, TIMESTAMP.
Purpose
ADD_MONTHS
returns the date date [timestamp] plus integer months. The date argument
must be a date or timestamp value. The integer argument must be an integer. The return
type is always DATE [TIMESTAMP], regardless of the datatype of date. If date [timestamp]
is the last day of the month or if the resulting month has fewer days than the day component of
date,
then the result is the last day of the resulting month. Otherwise, the result has the same
day component as date [timestamp].
Examples
The following example returns the month after the hire_date in the sample table employees:
SELECT ADD_MONTHS(hire_date,1) as "Next month"
FROM employees
WHERE last_name = 'Baer';
Next Month
----------07/07/1994
© 2014 Advanced Systems srl
SQL Functions
4.5
56
ASCII
Syntax
Purpose
ASCII
returns the decimal representation in the database character set of the first character of
char.
char
can be of datatype CHAR, VARCHAR, CHARACTER. The value returned is of datatype
INTEGER.
The database character set is 7-bit ASCII, then this function returns an ASCII value.
Examples
The following example returns employees whose last names begin with the letter L, whose
ASCII equivalent is 76:
SELECT last_name FROM employees
WHERE ASCII(SUBSTR(last_name, 1, 1,)) = 76;
LAST_NAME
------------------------Ladwig
Landry
Lee
Livingston
4.6
ASIN
Syntax
Purpose
ASIN
returns the arc sine of n. The argument n must be in the range of -1 to 1, and the
function returns a value in the range of - pi/2 to pi/2, expressed in radians.
This function takes as an argument any numeric datatype and returns FLOAT datatype.
© 2014 Advanced Systems srl
SQL Functions
57
Examples
The following example returns the arc sine of 0.3:
SELECT ASIN(0.3) "Arc_Sine" FROM DUAL;
Arc_Sine
-----------------0.304692654015398
4.7
ATAN
Syntax
Purpose
ATAN
returns the arc tangent of n. The argument n can be in an unbounded range and returns a
value in the range of - pi/2 to pi/2, expressed in radians.
This function takes as an argument any numeric datatype and returns FLOAT datatype.
Examples
The following example returns the arc tangent of 0.3:
SELECT ATAN(0.3) "Arc_Tangent" FROM DUAL;
Arc_Tangent
-----------------0.291456794477867
4.8
AVG
Syntax
Purpose
© 2014 Advanced Systems srl
SQL Functions
AVG
58
returns average value of expr.
This function takes as an argument any numeric datatype
The function always returns DOUBLE datatype.
Aggregate Example
The following example calculates the average salary of all employees in the hr.employees
table:
SELECT AVG(salary) as "Average" FROM employees;
Average
-------------6461.68224
4.9
BIN_TO_NUM
Syntax
Purpose
BI N_TO_NUM
converts a bit vector to its equivalent number. Each argument to this function
represents a bit in the bit vector. This function takes as arguments any numeric datatype. Each
ex pr
must evaluate to 0 or 1. This function returns I NTEGER. The supported size of bit vector
is 8, then you can specify max 8 e x p r parameters.
Example
The following example converts a binary value to a number:
SEL ECT BI N_ TO_ NUM( 1 , 0 , 1 , 0 )
Bi n a r y
-----10
© 2014 Advanced Systems srl
a s Bi n a r y FROM DUAL ;
SQL Functions
4.10
59
BITAND
Syntax
Purpose
The BI TAND function treats its inputs and its output as vectors of bits; the output is the
bitwise AND of the inputs. The types of e x p r 1 and e x p r 2 are I NTEGER, and the result is of
type I NTEGER.
The arguments must be in the range -(2(n-1)) .. (2(n-1)-1). If an argument is out of this range,
the result is undefined. The current implementation of BI TAND defines n = 64 .
Example
The following example performs an AND operation on the numbers 6 ( bi nar y 1, 1, 0) and 3
( bi nar y 0, 1, 1) :
SEL ECT BI TAND( 6 , 3 )
a s I NTAND FROM DUAL ;
I NTAND
-----2
This is the same as the following example, which shows the binary values of 6 and 3.
The BI TAND function operates only on the significant digits of the binary values:
SEL ECT BI TAND(
BI N_ TO_ NUM( 1 , 1 , 0 ) ,
BI N_ TO_ NUM( 0 , 1 , 1 ) )
FROM DUAL ;
Bi n a r y
---------2
4.11
BITOR
Syntax
Purpose
© 2014 Advanced Systems srl
a s " Bi n a r y "
SQL Functions
60
The BI TOR function treats its inputs and its output as vectors of bits; the output is the bitwise
OR
of the inputs. The types of e x p r 1
and e x p r 2 are I NTEGER, and the result is of type
I NTEGER.
The arguments must be in the range -(2(n-1)) .. (2(n-1)-1). If an argument is out of this range,
the result is undefined. The current implementation of BI TOR defines n = 64 .
Example
The following example performs an OR operation on the numbers 6 ( bi nar y 1, 1, 0) and 3
( bi nar y 0, 1, 1) :
SEL ECT BI TOR( 6 , 3 )
a s I NTOR FROM DUAL ;
I NTOR
-----7
This is the same as the following example, which shows the binary values of 6 and 3.
The BI TOR function operates only on the significant digits of the binary values:
SEL ECT BI TOR(
BI N_ TO_ NUM( 1 , 1 , 0 ) ,
BI N_ TO_ NUM( 0 , 1 , 1 ) )
FROM DUAL ;
a s " Bi n a r y "
Bi n a r y
---------7
4.12
BITXOR
Syntax
Purpose
The BI TXOR function treats its inputs and its output as vectors of bits; the output is the
bitwise XOR of the inputs. The types of e x p r 1 and e x p r 2 are I NTEGER, and the result is of
type I NTEGER.
The arguments must be in the range -(2(n-1)) .. (2(n-1)-1). If an argument is out of this range,
the result is undefined. The current implementation of BI TXOR defines n = 64 .
© 2014 Advanced Systems srl
SQL Functions
61
Example
The following example performs an XOR operation on the numbers 6 ( bi nar y 1, 1, 0) and 3
( bi nar y 0, 1, 1) :
SEL ECT BI TXOR( 6 , 3 )
a s I NTXOR FROM DUAL ;
I NTXOR
-----5
This is the same as the following example, which shows the binary values of 6 and 3.
The BI TOR function operates only on the significant digits of the binary values:
SEL ECT BI TXOR(
BI N_ TO_ NUM( 1 , 1 , 0 ) ,
BI N_ TO_ NUM( 0 , 1 , 1 ) )
FROM DUAL ;
a s " Bi n a r y "
Bi n a r y
---------5
4.13
CEIL[ING]
Syntax
Purpose
CEIL
(or CEILING) returns the smallest integer greater than or equal to n.
This function takes as an argument any numeric datatype.
The function returns the same datatype as the numeric datatype of the argument.
Examples
The following example returns the smallest integer greater than or equal to the order total of a
specified order:
SELECT order_total, CEIL(order_total) FROM orders
WHERE order_id = 2434;
ORDER_TOTAL CEIL(ORDER_TOTAL)
----------- ----------------268651.8
268652
© 2014 Advanced Systems srl
SQL Functions
4.14
62
CHR
Syntax
Purpose
CHR
returns the character having the binary equivalent to n as a CHAR value in 7-bit ASCII
character set.
If n > 256, then Sadas Database returns the binary equivalent of n mod 256.
This function takes as an argument a NUMBER value; if value has decimals, then Sadas truncate
input value.
Use of the CHR function results in code that is not portable between ASCII- and EBCDICbased machine architectures.
Example
SELECT CHR(67)+CHR(65)+CHR(84) "Dog" FROM DUAL;
Dog
--CAT
4.15
CONCAT
Syntax
Purpose
CONCAT
returns char1 concatenated with char2. Both char1 and char2 can be any
of the datatypes CHAR, CHARACTER, VARCHAR.
This function is equivalent to the concatenation operator (||).
© 2014 Advanced Systems srl
SQL Functions
63
Example
SELECT CONCAT('PRE ','COMPUTING') AS CTC FROM DUAL
CTC
-------------PRE COMPUTING
4.16
COS
Syntax
Purpose
COS
returns the cosine of n (an angle expressed in radians). The function returns FLOAT
datatype.
Examples
The following example returns the cosine of 180 degrees:
SELECT COS(180 * 3.14159265359/180) as "Cosine of 180 degrees" FROM DUAL;
Cosine of 180 degrees
---------------------1
4.17
COSH
Syntax
Purpose
COSH
returns the hyperbolic cosine of n. The function returns FLOAT datatype.
Examples
The following example returns the hyperbolic cosine of zero:
© 2014 Advanced Systems srl
SQL Functions
64
SELECT COSH(0) "Hyperbolic cosine of 0" FROM DUAL;
Hyperbolic cosine of 0
---------------------1
4.18
COUNT
Syntax
Purpose
COUNT
returns the number of rows returned by the query. You can use it as an aggregate.
If you specify expr, then COUNT returns the number of rows where expr is not null. You can
count either all rows, or only distinct values of expr.
If you specify the asterisk (*), then this function returns all rows, including duplicates.
In Sadas null value is as others value, then, if you specify the asterisk (*) or expr, the result is
the same.
COUNT
never returns null.
Aggregate Examples
The following examples use COUNT as an aggregate function:
SELECT COUNT(*) as "Total" FROM employees;
Total
---------107
SELECT COUNT(*) as "Allstars" FROM employees
WHERE commission_pct > 0;
Allstars
---------
© 2014 Advanced Systems srl
SQL Functions
65
35
SELECT COUNT(commission_pct) as "Count" FROM employees;
Count
---------35
SELECT COUNT(DISTINCT manager_id) as "Managers" FROM employees;
Managers
---------18
4.19
CURDATE
Refer to SYSDATE function.
4.20
CURRENT_DATE
Syntax
Purpose
CURRENT_DATE
returns the current date of system.
Example
SELECT CURRENT_DATE FROM DUAL;
CURRENT_DATE
-----------19/06/2008
4.21
CURRENT_TIME
Syntax
Purpose
© 2014 Advanced Systems srl
SQL Functions
66
CURRENT_TIME
returns the current time of system.
Example
SELECT CURRENT_TIME FROM DUAL;
CURRENT_TIME
-----------12:28:38:375
4.22
CURRENT_TIMESTAMP
Syntax
Purpose
CURRENT_TIMESTAMP
returns the current timestamp of system.
Example
SELECT CURRENT_TIMESTAMP FROM DUAL;
CURRENT_TIMESTAMP
----------------------19/06/2008-12:28:38:375
4.23
CURTIME
Refer to SYSTIME function.
4.24
DATEADD
Syntax
date
can be of datatype DATE, TIME or TIMESTAMP.
© 2014 Advanced Systems srl
SQL Functions
67
The DATEADD function syntax has these parts:
Part
Description
interval Required. String expression that is the interval you want to add. See Settings section for
values.
number Required. Numeric expression that is the number of interval you want to add. The numeric
expression can either be positive, for dates in the future, or negative, for dates in the past. If
the numeric expression has decimals or is float value, Sadas truncate the value.
date
Required. DATE, TIME or TIMESTAMP representing the datetime to which interval is
added.
The interval argument can have the following values (case insensitive):
Setting Descriptio
n
YY
Year
QQ
Quarter
MM
Month
DD
Day
WK
Week
HH
Hour
MI
Minute
SS
Second
MS
Millisecond
Purpose
Returns a date to which a specified date interval has been added.
You can use the DATEADD function to add or subtract a specified time interval from a date. For
© 2014 Advanced Systems srl
SQL Functions
68
example, you can use DATEADD to calculate a date 30 days from today or a time 45 minutes
from now.
Example
The DATEADD function won't return an invalid date.
SELECT DATEADD(‘MM’,1,’19/06/2008’) as NewDate FROM DUAL;
NEWDATE
---------19/07/2008
SELECT DATEADD('Mi',1,'01:01:56:001') as NewTime FROM DUAL;
NEWTIME
-----------01:02:56:001
4.25
DATEDIFF
Syntax
date1, date2
can be of datatype DATE, TIME or TIMESTAMP.
The DATEDIFF function syntax has these parts:
Part
Description
interval
Required. String expression that is the interval you want to use to calculate the differences
between date1 and date2. See Settings section for values.
date1,
Required. Date, time or timestamp expressions. Two dates you want to use in the
date2
calculation.
The interval argument can have the following values:
Setting Descriptio
n
© 2014 Advanced Systems srl
SQL Functions
69
YY
Year
QQ
Quarter
MM
Month
DD
Day
WK
Week
HH
Hour
MI
Minute
SS
Second
MS
Millisecond
Purpose
Returns the number of intervals between two dates.
You can use the DATEDIFF function to determine how many specified time intervals exist
between two dates. For example, you might use DATEDIFF to calculate the number of days
between two dates, or the number of weeks between today and the end of the year.
If interval is Week (‘WK’), however, the DATEDIFF function returns the number of calendar
weeks between the two dates. It counts the number of Sundays between date1 and date2.
DATEDIFF counts date2 if it falls on a Sunday; but it does not count date1, even if it does fall
on a Sunday. When comparing December 31 to January 1 of the immediately succeeding year,
DATEDIFF
for Year (‘YY’) returns 1 even though only a day has elapsed.
Example
SELECT DATEDIFF(‘DD’, ’19/06/2009’,’19/06/2008’) as Interval FROM DUAL;
INTERVAL
----------365
SELECT DATEDIFF('DD', '31/12/2007','01/01/2008') as Interval FROM DUAL;
INTERVAL
---------1
© 2014 Advanced Systems srl
SQL Functions
70
SELECT DATEDIFF('Mi','31/12/2007-12:10:12:900','01/02/2008-15:43:55:899')
as Interval FROM DUAL;
INTERVAL
---------46293
SELECT DATEDIFF('Mi','12:10:12:900','15:43:55:899') as Interval FROM DUAL;
INTERVAL
---------213
4.26
DATEPART
Syntax
date
can be of datatype DATE, TIME or TIMESTAMP.
The DATEPART function syntax has these parts:
Part
Description
interval Required. String expression that is the interval of time you want to return. See Settings section
for values.
date
Required. Date, time or timestamp expression you want to evaluate.
The interval argument can have the following values (case insensitive):
Setting Descriptio
n
© 2014 Advanced Systems srl
YY
Year
QQ
Quarter
MM
Month
SQL Functions
71
DD
Day
WK
Week
HH
Hour
MI
Minute
SS
Second
MS
Millisecond
Purpose
Returns the specified part of a given date.
You can use the DATEPART function to evaluate a date and return a specific interval of time.
For example, you might use DATEPART to calculate the day of the month or the current hour.
Example
SELECT DATEPART(‘DD’,’19/06/2009’) as Part FROM DUAL;
PART
---------19
SELECT DATEPART(‘YY’,’19/06/2009’) as Part FROM DUAL;
PART
---------2009
SELECT DATEPART(‘MS’,’19/06/2009-12:12:32:998’) as Part FROM DUAL;
PART
---------998
SELECT DATEPART(‘Mi’,’12:12:32:998’) as Part FROM DUAL;
PART
© 2014 Advanced Systems srl
SQL Functions
72
---------12
4.27
DATE_TO_JULIAN
Syntax
DATE_TO_JULIAN
(
date
)
Purpose
Julian day refers to a continuous count of days since the beginning of the Julian Period used
primarily by astronomers.
The Julian Day Number (JDN) is the integer assigned to a whole solar day in the Julian day
count starting from noon Greenwich Mean Time, with Julian day number 0 assigned to the day
starting at noon on January 1, 4713 BC proleptic Julian calendar. (November 24, 4714 BC in
the proleptic Gregorian calendar.).
For example, the Julian day number for 1 January 2000 was 2,451,545
The DATE_TO_JULIAN function a data type converts a JDN integer.
Examples
select date_to_julian('01/01/2000') as JulDate from dual;
DateJul
---------2451545
4.28
DAYNAME
Syntax
date
can be of datatype DATE, TIMESTAMP.
© 2014 Advanced Systems srl
SQL Functions
73
Purpose
Returns the name (string) of the day of a given date, using language of Sadas Server installation.
Example
SELECT DAYNAME('01/10/1998-00:01:12:233') as Name FROM DUAL;
NAME
---------Thursday
SELECT DAYNAME('01/11/2008') as Name FROM DUAL;
NAME
---------Saturday
4.29
DAYOFWEEK
Syntax
date
can be of datatype DATE, TIMESTAMP.
Purpose
Returns the ordinal of the day in the week of a given date.
Day
Ordin
al
© 2014 Advanced Systems srl
Monday
1
Tuesday
2
Wednesday
3
Thursday
4
Friday
5
Saturday
6
SQL Functions
74
Sunday
7
Example
SELECT DAYOFWEEK('01/10/1998-00:01:12:233') as Prog_Day FROM DUAL;
PROG_DAY
---------4
SELECT DAYOFWEEK('01/11/2008') as Prog_Day FROM DUAL;
PROG_DAY
---------6
4.30
DAYOFYEAR
Syntax
date
can be of datatype DATE, TIMESTAMP.
Purpose
Returns the ordinal of the day in the year of a given date.
Day
Ordina
l
01/01/
1
YYYY
Example
© 2014 Advanced Systems srl
…
…
31/12/
YYYY
365
[366]
SQL Functions
75
SELECT DAYOFYEAR('01/10/1998-00:01:12:233') as Prog_Day FROM DUAL;
PROG_DAY
---------274
SELECT DAYOFYEAR('01/11/2008') as Prog_Day FROM DUAL;
PROG_DAY
---------306
4.31
DECODE
Syntax
Purpose
DECODE
compares expr to each search value one by one. If expr is equal to a search, then
Sadas returns the corresponding result. If no match is found, then Sadas returns default. If
default
is omitted, then Sadas returns null value.
The arguments can be any of the numeric types or character types.
If expr and search are character data, then Sadas compares them using nonpadded
comparison semantics. expr, search, and result can be any of the datatypes CHAR,
CHARACTER, VARCHAR.
The string returned is of string datatype.
If the first search-result pair are numeric, then Sadas compares all search-result
expressions and the first expr to determine the argument with the highest numeric precedence,
implicitly converts the remaining arguments to that numeric (integer or double) datatype, and
returns that datatype.
The search, result, and default values can be derived from expressions. Sadas uses shortcircuit evaluation. The database evaluates each search value only before comparing it to expr,
© 2014 Advanced Systems srl
SQL Functions
76
rather than evaluating all search values before comparing any of them with expr.
Consequently, Sadas never evaluates a search if a previous search is equal to expr.
Sadas automatically converts expr and each search value to the datatype of the first search
value before comparing. Sadas automatically converts the return value to the same datatype as
the first result. You can also specify only expr and default parameters; in this case the
default
parameter must be a constant.
Examples
This example decodes the value warehouse_id. If warehouse_id is 1, then the function
returns 'Southlake'; if warehouse_id is 2, then it returns 'San Francisco'; and so forth. If
warehouse_id
is not 1, 2, 3, or 4, then the function returns 'Non domestic'.
SELECT product_id,
DECODE (warehouse_id, 1,
2,
3,
4,
'Southlake',
'San Francisco',
'New Jersey',
'Seattle',
'Non domestic') as "Location"
FROM inventories
WHERE product_id < 1775
ORDER BY product_id, "Location";
4.32
DIGITS
Syntax
DIGITS
(
col
)
Purpose
The DIGITS function returns a character string representation of the absolute value of a
number.
The argument must be a column of one of the following built-in numeric data types:
SMALLINT, INTEGER,
or DECIMAL.
The result of the function is a fixed-length character string representing the absolute value of
the argument without regard to its scale. The result does not include a sign or a decimal point.
Instead, it consists exclusively of digits, including, if necessary, leading zeros to fill out the
string. The length of the string is equal to the column length declared in the schema.
© 2014 Advanced Systems srl
SQL Functions
77
Examples
Assume that COLUMNX has the data type DECIMAL(6,2), and that one of its
values is -6.28.
Then, for this value:
SELECT DIGITS(COLUMNX) FROM T
the value '000628' is returned.
The result is a string of length six (the precision of the column) with
leading zeros padding the string
out
to
this
length.
Neither
sign
nor
decimal point appear in the result.
4.33
EXP
Syntax
Purpose
EXP
returns e raised to the nth power, where e = 2.71828183 ... The function returns a
value of the same type as the argument. This function takes as an argument any numeric
datatype.
Examples
The following example returns e to the 4th power:
SELECT EXP(4) "e to the 4th power" FROM DUAL;
E TO THE 4TH POWER
-----------------54.5981500331442
© 2014 Advanced Systems srl
SQL Functions
4.34
78
EXTFUNC
External Functions
To enable external functions, you need to create a file named
ExternalFunctions.sad
in the SADAS security folder (PATHS variable in the setting.txt configuration file)
ExternalFunctions.sad is a linesequential file and uses the ‘;’ character as a separator.
The semantics of the attributes is:
Identifier of Function
It is the identifier of the function. In the call to EXTFUNC the function identifier must be
defined as a constant alphanumeric and as the first parameter. It is not case sensitive.
DLL
It’s the full name of the DLL including the absolute or relative path to the current execution
path of the Sadas server. It is case sensitive on non-Windows systems (Linux, Unix, etc.).
Function
It’s the name of the function exported from the DLL. It’s case sensitive on non-Windows
systems (Linux, Unix, etc.). It’s a required value.
The function’s prototype implemented in the DLL must have this syntax:
int64_t Funzione(void* out,void** inParam);
out points to the value returned by the function.
The output area is allocated outside the function.
The ‘inParam’ parameters are the possible pointers to the input values.
The maximum number of input parameters is 5.
If the return value is less than zero the function is in error.
Before the return stage starts, the function must deallocate all allocated variables on the
heap to avoid memory leaks.
Initialization
Name of the function exported by the DLL to initialize the DLL itself. It's case sensitive on
© 2014 Advanced Systems srl
SQL Functions
79
non-Windows systems (Linux, Unix,etc.). It’s called only once in connection with
the LoadLibrary. Definition is not compulsory.
The function’s prototype implemented in the DLL must have this syntax:
void Inizializza(void* Istanza);
The pointer to ‘Istanza’ must be casted to char* and contain the name of the SADAS’
instance.
Closing
Name of the function exported by the DLL to initialize the DLL itself. It's case sensitive on
non-Windows systems (Linux, Unix, etc.). It is called only once when the SADAS server
shutdown event occurs. Definition is not required.
The prototype implemented in the DLL must have this syntax:
void Chiudi(void* Istanza);
The pointer to ‘Istanza’ must be casted to char * and contain the name of the SADAS’
instance.
Output type
Required. Indicates the type of output returned. Can take the following values:
C
string
I
signed integer on 64 bit
F
float (double precision)
Output lenght
Required. Indicates the length of the output returned. It is meaningless for integer or float (set
at 8 at runtime) data types while for string (C) data types, if greater than 0, it indicates the
length of the string without the null terminator: if lower than 0, the absolute value of the
parameter indicates the progressive input from which to copy the length at runtime. If the
value is 0, the length is calculated as the sum of the lengths of all input parameters of type C.
© 2014 Advanced Systems srl
SQL Functions
80
Number of Input parameters
Required. Indicates the number of input parameters. It ranges between 0 and 8. The next
two attributes are repeated for all the input parameters. Parameters will be passed to the
function call in the same order: this order needs to be respected when writing
in SQL (excluding in this case the implicit parameters).
Input type
Required. Indicates the type of input to be passed to the function. Can take the
following values:
C
string
I
signed integer on 64 bit
F
float (double precision)
U
string with the name of the current user
D
string with the name of the current DB
S
string with the name of the current instance
The values U, D and S do not correspond to the SQL syntax for the function call. They are
passed to the DLL implicitly using the values of the current session's connection. The implicit
values are always passed as strings.
4.35
FIRST_DAY
Syntax
date can be DATE or TIMESTAMP.
Purpose
FIRST_DAY
returns the date of the first day of the month that contains date. The return type is
DATE [TIMESTAMP].
Examples
SELECT SYSDATE,
FIST_DAY(SYSDATE) as "First"
© 2014 Advanced Systems srl
SQL Functions
81
FROM DUAL;
SYSDATE
First
---------- ---------20/06/2008 01/06/2008
4.36
FIRST_WORK_DAY
Syntax
date can be DATE or TIMESTAMP.
Purpose
FIRST_WORK_DAY
returns the date of the first day of the month that contains date, after first
saturday and sunday of month. The return type is DATE [TIMESTAMP].
Examples
SELECT '12/12/2012' as DTA,
FIRST_WORK_DAY(DTA) as "FirstWorking"
FROM DUAL;
DTA
FirstWorking
---------- ---------12/12/2012 03/12/2012
4.37
FLOOR
Syntax
Purpose
FLOOR
returns the largest integer equal to or less than n.
This function takes as an argument any numeric datatype.
The function returns the same datatype as the numeric datatype of the argument.
© 2014 Advanced Systems srl
SQL Functions
82
Examples
The following example returns the largest integer equal to or less than 15.7:
SELECT FLOOR(15.7) as "Floor" FROM DUAL;
Floor
---------15
4.38
GREATEST
Syntax
Purpose
GREATEST
returns the greatest of the list of one or more expressions. Sadas uses the first expr
to determine the type of return field .
If all expr are numeric, then Sadas determines the argument with the highest numeric
precedence, implicitly converts the remaining arguments to that numeric datatype (integer or
double) before the comparison, and returns that datatype.
If there is any not numeric expr , than all others expr must be of the same type.
In this case Sadas compares each expr using nonpadded comparison semantics.
Examples
The following statement selects the string with the greatest value:
SELECT GREATEST ('HARRY', 'HARRIOT', 'HAROLD')
As "Great" FROM DUAL;
Great
-------HARRY
SELECT GREATEST(1.8,2) FROM DUAL;
© 2014 Advanced Systems srl
SQL Functions
83
Greatest
-------2
4.39
GROUPING
Syntax
Purpose
GROUPI NG distinguishes
superaggregate rows from regular grouped rows. GROUP BY extensions
such as ROLLUP and CUBE produce superaggregate rows where the set of all values is
represented by null.
Using the GROUPING function, you can distinguish a null representing the set of all values in
a superaggregate row from a null in a regular row.
The expr in the GROUPI NG function must match one of the expressions in the GROUP BY clause.
The function returns a value of 1 if the value of expr in the row is a null representing the set of
all values. Otherwise, it returns zero. The datatype of the value returned by the GROUPI NG
function is I NTEGER. .
Examples
Cube
SELECT O_ORDERSTATUS, COUNT(*),
SUM(O_TOTALPRICE), MAX(O_SHIPPRIORITY),
CASE GROUPING(O_ORDERSTATUS) WHEN 0 THEN 'YES' ELSE 'NO' END as FLAG
FROM
ORDERS
WHERE O_ORDERDATE < '01/02/1992'
GROUP BY CUBE(O_ORDERSTATUS)
© 2014 Advanced Systems srl
SQL Functions
84
Rollup
SELECT O_ORDERSTATUS, COUNT(*),
SUM(O_TOTALPRICE), MAX(O_SHIPPRIORITY),
CASE GROUPING(O_ORDERSTATUS) WHEN 0 THEN 'YES' ELSE 'NO' END as FLAG
FROM
ORDERS
WHERE O_ORDERDATE < '01/02/1992'
GROUP BY ROLLUP(O_ORDERSTATUS)
4.40
HEXTONUM
Syntax
HEXTONUM
(
char
)
Purpose
HEXTONUM
converts char containing hexadecimal digits in the corresponding integer (64-bit)
value.
Examples
SELECT HEXTONUM('61626364') as HTONUM FROM DUAL;
HTONUM
---------1633837924
4.41
HEXTOSTR
Syntax
Purpose
HEXTOSTR
converts char containing hexadecimal digits in the CHAR, CHARACTER, VARCHAR
value.
© 2014 Advanced Systems srl
SQL Functions
85
Examples
SELECT HEXTOSTR('61626364') as HTOSTR FROM DUAL;
HTOSTR
-----abcd
4.42
INITCAP
Syntax
Purpose
INITCAP
returns string, with the first letter of each word in uppercase, all other letters in
lowercase. Words are delimited by white space or characters that are not alphanumeric.
char
can be of any of the datatypes CHAR, CHARACTER, VARCHAR. The return value is the same
datatype as char.
Examples
The following example capitalizes each word in the string:
SELECT INITCAP('the soap') "Capitals" FROM DUAL;
Capitals
--------The Soap
SELECT INITCAP('the@soap') "Capitals" FROM DUAL;
Capitals
--------The@Soap
© 2014 Advanced Systems srl
SQL Functions
4.43
86
INSTR
Syntax
Purpose
The INSTR functions search string for substring. The function returns an integer indicating
the position of the character in string that is the first character of first occurrence.
Both string and substring can be any of the datatypes CHAR, CHARACTER, VARCHAR. The
value returned is of NUMBER datatype (integer).
Examples
SELECT INSTR('CORPORATE FLOOR','OR') as "Instring" FROM DUAL;
Instring
---------2
4.44
JULIAN_TO_DATE
Syntax
JULIAN_TO_DATE
(
n
)
Purpose
Julian day refers to a continuous count of days since the beginning of the Julian Period used
primarily by astronomers.
The Julian Day Number (JDN) is the integer assigned to a whole solar day in the Julian day
count starting from noon Greenwich Mean Time, with Julian day number 0 assigned to the day
starting at noon on January 1, 4713 BC proleptic Julian calendar. (November 24, 4714 BC in
the proleptic Gregorian calendar.).
For example, the Julian day number for 1 January 2000 was 2,451,545 .
© 2014 Advanced Systems srl
SQL Functions
87
The JULIAN_TO_DATE function converts an integer (as JDN) in a data type.
Examples
select julian_to_date(2451545) as DateJul from dual;
DateJul
---------01/01/2000
4.45
ISNUMERIC
Syntax
expr
(
ISNUMERIC
CC
expr
)
can be all character datatypes.
Purpose
IS_NUMERIC
try to convert expr to a value of NUMBER datatype. The expr can be a value of
CHAR, CHARACTER,
VARCHAR
datatype containing a number. The result type is an integer and
assumes 1 if expr is numeric, else 0.
Example
SEL ECT I SNUMERI C( ' - 1 0 0 ' )
a s " I SNUM" FROM DUAL ;
I SNUM
------1
4.46
LAST_DAY
Syntax
date can be DATE or TIMESTAMP.
Purpose
LAST_DAY
returns the date of the last day of the month that contains date. The return type is
DATE [TIMESTAMP].
© 2014 Advanced Systems srl
SQL Functions
88
Examples
SELECT SYSDATE,
LAST_DAY(SYSDATE) as "Last"
FROM DUAL;
SYSDATE
Last
---------- ---------20/06/2008 30/06/2008
4.47
LAST_WORK_DAY
Syntax
date can be DATE or TIMESTAMP.
Purpose
LAST_WORK_DAY
returns the date of the last day of the month that contains date, before
last saturday and sunday of month.
The return type is DATE [TIMESTAMP].
Examples
SELECT SYSDATE,
LAST_WORK_DAY(SYSDATE) as "LastWorking"
FROM DUAL;
SYSDATE
LastWorking
---------- ---------20/06/2008 30/06/2008
4.48
LCASE
Refer to LOWER function.
© 2014 Advanced Systems srl
SQL Functions
4.49
89
LEAST
Syntax
Purpose
LEAST
returns the least of the list of one or more expressions. Sadas uses the first expr to
determine the type of the return field .
If all expr are numeric, then Sadas determines the argument with the highest numeric
precedence, implicitly converts the remaining arguments to that numeric datatype (integer or
double) before the comparison, and returns that datatype.
If there is any not numeric expr , than all others expr must be of the same type.
Sadas compares each expr using nonpadded comparison semantics.
Examples
The following statement selects the string with the least value:
SELECT LEAST('HARRY','HARRIOT','HAROLD') "LEAST"
FROM DUAL;
LEAST
-----HAROLD
4.50
LENGTH
Syntax
Purpose
The LENGTH functions return the length of char.
char
can be any of the datatypes CHAR, CHARACTER, VARCHAR. The return value is of datatype
© 2014 Advanced Systems srl
SQL Functions
90
NUMBER
(integer).
Examples
SELECT LENGTH('CANDIDE') as "LengthO"
FROM DUAL;
LengthO
------7
4.51
LN
Syntax
Purpose
LN
returns the natural logarithm of n, where n is greater than 0.
This function takes as an argument any numeric datatype. The function returns always
FLOAT
datatype.
Examples
The following example returns the natural logarithm of 95:
SELECT LN(95) "Natural log of 95" FROM DUAL;
Natural log of 95
----------------4.55387689160054
4.52
LOCALTIMESTAMP
Refer to SYSTIMESTAMP function.
© 2014 Advanced Systems srl
SQL Functions
4.53
91
LOG
Syntax
Purpose
LOG
returns the logarithm, base n2, of n1. The base n1 can be any positive value other than 0
or 1 and n2 can be any positive value.
This function takes as arguments any numeric datatype and returns always FLOAT.
Examples
The following example returns the log of 100:
SELECT LOG( 10, 100) " Log bas e 10 of 100" FROM DUAL;
Log bas e 10 of 100
-----------------2
4.54
LOWER
Syntax
Purpose
LOWER
returns char, with all letters lowercase. char can be any of the datatypes CHAR,
CHARACTER, VARCHAR.
The return value is the same datatype as char.
Examples
The following example returns a string in lowercase:
SELECT LOWER('MR. SCOTT MCMILLAN') "Lowercase"
FROM DUAL;
Lowercase
-------------------mr. scott mcmillan
© 2014 Advanced Systems srl
SQL Functions
4.55
92
LPAD
Syntax
expr1
n
can be a char expression.
must be a constant cardinal number.
expr2
must be a single char. If a longer string is specified, SADAS will use only its first
character to process the function.
Purpose
LPAD
returns expr1, left-padded to length n (cardinal) characters with the character in
expr2.
This function is useful for formatting the output of a query.
expr1
can be any of the datatypes CHAR, CHARACTER, VARCHAR. The argument n must be a
NUMBER
integer and cannot be an expression or field.
If you do not specify expr2, then the default is a single blank. If expr1 is longer than n, then
this function returns the portion of expr1 that fits in n.
Examples
The following example left-pads a string with the asterisk (*) characters:
SELECT LPAD('Page 1',15,'*') "LPAD example"
FROM DUAL;
LPAD example
--------------*********Page 1
© 2014 Advanced Systems srl
SQL Functions
4.56
93
LTRIM
Syntax
Purpose
LTRIM
removes from the left end of char all of the characters contained in set. If you do not
specify set, then it defaults to a single blank. Sadas Database begins scanning char from its
first character and removes all characters that appear in set until reaching a character not in
set
and then returns the result. Both char and set can be any of the string datatypes.
Examples
SELECT Ltrim(' X10') "LTRIM example"
FROM DUAL;
LTRIM example
------------X10
SELECT product_name, LTRIM(product_name, 'Monitor ') "Short Name"
FROM products
WHERE product_name LIKE 'Monitor%';
PRODUCT_NAME
-------------------Monitor 17/HR
Monitor 17/HR/F
Monitor 17/SD
Monitor 19/SD
Monitor 19/SD/M
Monitor 21/D
Monitor 21/HR
Monitor 21/HR/M
Monitor 21/SD
Monitor Hinge - HD
Monitor Hinge - STD
© 2014 Advanced Systems srl
Short Name
--------------17/HR
17/HR/F
17/SD
19/SD
19/SD/M
21/D
21/HR
21/HR/M
21/SD
Hinge - HD
Hinge - STD
SQL Functions
4.57
94
MAX
Syntax
Purpose
MAX
returns maximum value of expr. You can only use it as an aggregate.
Aggregate Example
The following example determines the highest salary in the hr.employees table:
SELECT MAX(salary) as "Maximum" FROM employees;
Maximum
---------24000
4.58
MIN
Syntax
Purpose
MIN
returns minimum value of expr. You can only use it as an aggregate.
Aggregate Example
The following statement returns the earliest hire date in the hr.employees table:
SELECT MIN(hire_date) as "Earliest" FROM employees;
Earliest
---------17/06/2004
© 2014 Advanced Systems srl
SQL Functions
4.59
95
MOD
Syntax
Purpose
MOD
returns the remainder of n2 divided by n1. Returns n2 if n1 is 0.
This function takes as arguments any numeric datatype. Sadas determines the argument with
the highest numeric precedence, implicitly converts the remaining arguments to that datatype,
and returns that datatype.
The following example returns the remainder of 11 divided by 4:
SELECT MOD(11,4) as "Modulus" FROM DUAL;
Modulus
---------3
This function behaves differently from the classical mathematical modulus function when m is
negative. The classical modulus can be expressed using the MOD function with this formula:
m - n * FLOOR(m/n)
The following table illustrates the difference between the MOD function and the classical
modulus:
© 2014 Advanced Systems srl
MOD(m,
Classical
m
n
n)
Modulus
11
4
3
3
11
-4
3
-1
-11
4
-3
1
-11
-4
-3
-3
SQL Functions
4.60
96
MONTHNAME
Syntax
date can be DATE or TIMESTAMP.
Purpose
MONTHNAME
returns the name of the month (in the date language of your session) of the date.
The return type is string.
Examples
select MONTHNAME('12/02/2008') as MName from lineitem
MName
---------February
4.61
MONTHS_BETWEEN
Syntax
date1, date2 can be DATE or TIMESTAMP.
Purpose
MONTHS_BETWEEN
returns number of months between dates date1 and date2. If date1 is later
than date2, then the result is positive. If date1 is earlier than date2, then the result is
negative. The result is always an integer.
Examples
The following example calculates the months between two dates:
select MONTHS_BETWEEN('12/02/2008','01/08/2009') as Months from dual
Months
------18
© 2014 Advanced Systems srl
SQL Functions
4.62
97
NEXT_DAY
Syntax
Purpose
NEXT_DAY
returns the date of the first weekday named by char that is later than the date date.
The return type is always DATE, regardless of the datatype of date. The argument char must be
a day of the week in the date language of your session, either the full name or the abbreviation.
The minimum number of letters required is the number of letters in the abbreviated version. If
date
is TIMESTAMP type, the return value has the same hours, minutes, and seconds
component as the argument date.
Examples
This example returns the date of the next Tuesday after February 2, 2001:
SELECT NEXT_DAY('02/01/2001','TUESDAY') as "NEXT DAY"
FROM DUAL;
NEXT DAY
---------06/02/2001
4.63
NEXT_WORK_DAY
Syntax
date can be DATE or TIMESTAMP.
Purpose
NEXT_WORK_DAY
returns the date of the next working day of the month that contains date,
skipping saturday and sunday of month. The return type is DATE [TIMESTAMP].
© 2014 Advanced Systems srl
SQL Functions
98
Examples
SELECT '12/12/2012' as DTA,
FIRST_WORK_DAY(DTA) as "FirstWorking"
FROM DUAL;
DTA
FirstWorking
---------- ---------12/12/2012 03/12/2012
4.64
NOW
Refer to SYSTIMESTAMP function.
4.65
NUMTOHEX
Syntax
NUMTOHEX
(
int
)
Purpose
NUMTOHEX
converts integer value in hexadecimal digits.
Examples
SELECT NUMTOHEX(1633837924) as NTOHEX FROM DUAL
NTOHEX
-------61626364
4.66
PI
Syntax
Purpose
PI
returns the value of greek pi constant.
© 2014 Advanced Systems srl
SQL Functions
99
Example
SELECT PI as PIGREEK FROM DUAL;
PIGREEK
---------------3.14159265358979
4.67
POSITION
Refer to INSTR function.
4.68
POWER
Syntax
Purpose
POWER
returns n2 raised to the n1 power. The base n2 and the exponent n1 can be any
numbers, but if n2 is negative, then n1 must be an integer.
This function takes as arguments any numeric datatype. The function always returns DOUBLE.
Examples
The following example returns 3 squared:
SELECT POWER(3,2) as "Raised" FROM DUAL;
Raised
---------9
SELECT POWER(9,0.5) as "Raised" FROM DUAL;
Raised
---------3
SELECT POWER(10,-1) as "Raised" FROM DUAL;
Raised
---------0.1
© 2014 Advanced Systems srl
SQL Functions
4.69
100
PREVIOUS_DAY
Syntax
date can be DATE or TIMESTAMP.
Purpose
PREVIOUS_DAY
returns the date of the previous weekday named by char that is earlier than the
date date. The return type is always DATE, regardless of the datatype of date. The argument
char
must be a day of the week in the date language of your session, either the full name or the
abbreviation. The minimum number of letters required is the number of letters in the
abbreviated version. If date is TIMESTAMP type, the return value has the same hours, minutes,
and seconds component as the argument date.
Examples
This example returns the date of the previous Tuesday after February 2, 2001:
SELECT PREVIOUS_DAY('02/01/2001','TUESDAY') as "PREV DAY"
FROM DUAL;
PREV DAY
---------26/12/2000
4.70
PREVIOUS_WORK_DAY
Syntax
date can be DATE or TIMESTAMP.
Purpose
PREVIOUS_WORK_DAY
date,
returns the date of the previous working day of the month that contains
skipping saturday and sunday of month. The return type is DATE [TIMESTAMP].
© 2014 Advanced Systems srl
SQL Functions
101
Examples
SELECT '03/12/2012' as DTA,
PREVIOUS_WORK_DAY(DTA) as "PreviousWorking"
FROM DUAL;
DTA
PreviousWorking
---------- --------------03/12/2012 30/11/2012
4.71
RATIO_TO_REPORT
Syntax
Purpose
RATIO_TO_REPORT
is an analytic function. It computes the ratio of a value of column to the
total sum over all table. The input parameter (expr) must be a column.
Examples
SELECT QUANTITY, RATIO_TO_REPORT(QUANTITY) AS RTP FROM PURCHASE WHERE
QUANTITY > 1100
QUANTI TY RTP
-------- ------10100
0. 1387
2100
0. 0288
...
4.72
REGEXP_INSTR
Refer to INSTR function.
4.73
REGEXP_REPLACE
Refer to REPLACE function.
4.74
REGEXP_SUBSTR
Refer to SUBSTR[ING] function.
© 2014 Advanced Systems srl
SQL Functions
4.75
102
REMAINDER
Refer to MOD function.
4.76
REPLACE
Syntax
Purpose
REPLACE
returns char
with every
occurrence
of search_string
replaced
with
replacement_string.
Sadas REPLACE needs all parameters:
if replacement_string is null string (“''”), Sadas delete search_string from string
value;
if search_string is null string (“''”), Sadas returns input string value.
Both search_string and replacement_string, as well as char, can be any of the datatypes
CHAR, CHARACTER
or VARCHAR.
Examples
The following example replaces occurrences of J with BL:
SELECT REPLACE('JACK and JUE','J','BL') "Changes"
FROM DUAL;
Changes
-------------BLACK and BLUE
4.77
ROUND
Syntax
,
ROUND
Purpose
© 2014 Advanced Systems srl
(
n
scale
e
)
SQL Functions
ROUND
103
returns n rounded to scale places to the right of the decimal point.
If you don't specify scale parameter, Sadas assumes 0 for scale parameter.
n
can be any numeric datatype. The function returns NUMBER.
Examples
SELECT ROUND(15.193) "Round" FROM DUAL;
Round
---------15
SELECT ROUND(15.193,2) "Round" FROM DUAL;
Round
---------15.19
SELECT ROUND(1.5), ROUND(2.5) FROM DUAL;
ROUND(1.5) ROUND(2.5)
---------- ---------2
3
SELECT ROUND(19.9) "Round" FROM DUAL;
Round
---------20
4.78
RPAD
Syntax
expr1
n
can be a char expression.
must be a constant cardinal number.
expr2
must be a single char. If a longer string is specified, SADAS will use only its first
character to process the function.
© 2014 Advanced Systems srl
SQL Functions
104
Purpose
RPAD
returns expr1, right-padded to length n (cardinal) characters with the character in
expr2.
This function is useful for formatting the output of a query.
expr1
can be any of the datatypes CHAR, CHARACTER, VARCHAR. The argument n must be a
NUMBER
integer and cannot be an expression or field.
If you do not specify expr2, then the default is a single blank. If expr1 is longer than n, then
this function returns the portion of expr1 that fits in n.
Examples
The following example right-pads a string with the asterisk (*) characters:
SELECT RPAD('Page 1',15,'*') "RPAD example"
FROM DUAL;
RPAD example
--------------Page 1*********
4.79
RTRIM
Syntax
Purpose
RTRIM
removes from the right end of char all of the characters that appear in set. This
function is useful for formatting the output of a query. If you do not specify set, then it
defaults to a single blank. RTRIM works similarly to LTRIM. Both char and set can be any of
the string datatypes.
Examples
SELECT RTRIM('X10 ') "RTRIM example"
FROM DUAL;
RTRIM example
© 2014 Advanced Systems srl
SQL Functions
105
------------X10
SELECT RTRIM('BROWNING: /=./=./=./=./=.','/=.') "RTRIM example" FROM DUAL
RTRIM exam
---------BROWNING:
4.80
SDS_HASH
Syntax
Purpose
SDS_HASH
is a function that computes a hash value for a given expression. This function is
useful for operations such as analyzing a subset of data and generating a random sample.
The expr argument determines the data for which you want Sadas Database to compute a hash
value. There are no restrictions on the length of data represented by expr, which commonly
resolves to a column name. The expr must be a string datatype.
The optional max_bucket argument determines the maximum bucket value returned by the
hash function. You can specify any value between 0 and 264. The default is 264.
The optional seed_value argument enables Sadas to produce many different results for the
same set of data. Sadas applies the hash function to the combination of expr and seed_value.
You can specify any value between 0 and 264. The default is 31.
The function returns a INT64 value.
Examples
© 2014 Advanced Systems srl
SQL Functions
106
SELECT SDS_HASH('SADAS') AS SADASHASH FROM DUAL
SADASHASH
--------78656104
SELECT SDS_HASH(TO_CHAR(20090101)) AS SADASHASH FROM DUAL
SADASHASH
----------2319993427
4.81
SDS_HASH_SH1
Syntax
SDS_HASH_SH1
(
expr
)
Purpose
SDS_HASH_SH1 is a function that computes a hash value for a given expression based on the
cryptographic hash function SHA-1.
In cryptography, SHA-1 is a cryptographic hash function designed by the National Security
Agency and published by the NIST as a U.S. Federal Information Processing Standard. SHA
stands for Secure Hash Algorithm. SHA-1 is the most widely used of the existing SHA hash
functions, and is employed in several widely-used security applications and protocols.
SHA-1 produces a 160-bit message digest based on principles similar to those used by Ronald
L. Rivest of MIT in the design of the MD4 and MD5 message digest algorithms, but has a more
conservative design.
The original specification of the algorithm was published in 1993 as the Secure Hash Standard,
FIPS PUB 180, by US government standards agency NIST (National Institute of Standards and
Technology). This version is now often referred to as SHA-0. It was withdrawn by NSA shortly
after publication and was superseded by the revised version, published in 1995 in FIPS PUB
180-1 and commonly referred to as SHA-1. SHA-1 differs from SHA-0 only by a single bitwise
rotation in the message schedule of its compression function; this was done, according to NSA,
to correct a flaw in the original algorithm which reduced its cryptographic security. However,
NSA did not provide any further explanation or identify the flaw that was corrected.
© 2014 Advanced Systems srl
SQL Functions
107
Weaknesses have subsequently been reported in both SHA and SHA-1. SHA-1 appears to
provide greater resistance to attacks, supporting the NSA’s assertion that the change increased
the security.
The expr argument determines the data for which you want Sadas Database to compute a
SHA-1 hash value. There are no restrictions on the length of data represented by expr, which
commonly resolves to a column name. The expr must be a string datatype.
The function returns a string in HEXADECIMAL format.
Example
SELECT SDS_HASH_SH1('SADAS') AS SADASHASH FROM DUAL
SADASHASH
---------------------------------------AE985C1820D588ECEE9BA150351EE8911BF58C67
4.82
SIGN
Syntax
Purpose
SIGN
returns the sign of n. This function takes as an argument any numeric datatype and
returns NUMBER.
For value of NUMBER type, the sign is:
-1 if n<0
0 if n=0
1 if n>0
Examples
The following example indicates that the argument of the function (-15) is <0:
SELECT SIGN(-15) "LSign" FROM DUAL;
LSign
---------© 2014 Advanced Systems srl
SQL Functions
108
-1
4.83
SIN
Syntax
Purpose
SIN
returns the sine of n (an angle expressed in radians). The function returns FLOAT datatype.
Examples
The following example returns the sine of 30 degrees:
SELECT SIN(30 * 3.14159265359/180) "Sine of 30 degrees" FROM DUAL;
Sine of 30 degrees
-----------------0.5
4.84
SINH
Syntax
Purpose
SINH
returns the hyperbolic sine of n. The function returns FLOAT datatype.
Examples
The following example returns the hyperbolic sine of 1:
SELECT SINH(1) "Hyperbolic sine of 1" FROM DUAL;
Hyperbolic sine of 1
--------------------
© 2014 Advanced Systems srl
SQL Functions
109
1.1752011936438
4.85
SHUFFLE
Syntax
Purpose
A technique similar to substitution except that the substitution data is derived from the column
itself.
Shuffle rules are designed to randomly re-distribute the data in a table column that means the
data in a column is randomly moved between rows until there is no longer any reasonable
correlation with the remaining information in the row.
Each Shuffle Rule affects only a
specified column in a specified table.
One of the interesting benefits of shuffle rules is that if applied against a column of number
data they can scramble the contents of a table column while still preserving the total sum of the
column. Since no new data has been added, (the numbers have just been moved around), the
total of all of the numbers will remain the same.
This technique can be used to mask data in the tables.
Examples
update employees set last_name = SHUFFLE(last_name);
4.86
SOUNDEX
Syntax
Purpose
SOUNDEX
returns a character string containing the phonetic representation of char. This
function lets you compare words that are spelled differently, but sound alike in English.
© 2014 Advanced Systems srl
SQL Functions
110
The phonetic representation is defined in The Art of Computer Programming, Volume 3:
Sorting and Searching, by Donald E. Knuth, as follows:
Retain the first letter of the string and remove all other occurrences of the following letters:
a, e, h, i, o, u, w, y.
Assign numbers to the remaining letters (after the first) as follows:
b, f, p, v = 1
c, g, j, k, q, s, x, z = 2
d, t = 3
l = 4
m, n = 5
r = 6
If two or more letters with the same number were adjacent in the original name (before step 1),
or adjacent except for any intervening h and w, then omit all but the first.
Return the first four bytes padded with 0.
char
can be of any of the datatypes CHAR, CHARACTER or VARCHAR. The return value is the
same datatype as char.
Examples
The following example returns the employees whose last names are a phonetic representation
of "Smyth":
SELECT last_name, first_name
FROM hr.employees
WHERE SOUNDEX(last_name)
= SOUNDEX('SMYTHE')
ORDER BY last_name, first_name;
LAST_NAME
---------Smith
Smith
4.87
FIRST_NAME
---------Lindsey
William
SQRT
Syntax
© 2014 Advanced Systems srl
SQL Functions
111
Purpose
SQRT
returns the square root of n.
This function takes as an argument any numeric datatype. The function always returns a real
number.
If n is negative, Sadas returns error.
Example
The following example returns the square root of 26:
SELECT SQRT(26) "Square root" FROM DUAL;
Square root
----------5.09901951
4.88
STDDEV
Syntax
Purpose
STDDEV
returns the sample standard deviation of expr, a set of numbers. You can only use it as
an aggregate.
Sadas calculates the standard deviation as the square root of the variance defined for the
VARIANCE
aggregate function.
This function takes as an argument any numeric datatype. The function always returns a real
number.
Aggregate Examples
The following example returns the standard deviation of the salaries in the sample
hr.employees
table:
SELECT STDDEV(salary) "Deviation"
FROM employees;
Deviation
---------3909.36575
© 2014 Advanced Systems srl
SQL Functions
4.89
112
STRTOHEX
Syntax
Purpose
STRTOHEX
converts char containing CHAR, CHARACTER, VARCHAR value in hexadecimal digits.
Examples
SELECT STRTOHEX('abc') as STRTOH FROM DUAL;
STRTOH
-----616263
4.90
SUBSTITUTE_WITH
Syntax
Purpose
This technique consists of randomly replacing the contents of a column of data with
information that looks similar but is completely unrelated to the real details.
For example, the surnames in a customer database could be sanitized by replacing the real
last names with surnames drawn from a largish random list.
A parallel table is created in Sadas schema and configured with the values which will replaced
the original one after the data masking procedure.
© 2014 Advanced Systems srl
SQL Functions
113
Through an algorithm configured on masking engine, the value in this field will be replaced
with the parallel table values.
This technique can be used to mask data in the tables.
Examples
update employees set last_name = SUBSTITUTE_WITH('T_NAME');
4.91
SUBSTR[ING]
Syntax
Purpose
The SUBSTR (or SUBSTRING) functions return a portion of char, beginning at character
position, substring_length
characters long. Position and substring_length must be
cardinal (integer not negative) numbers.
If position is 0, then it is treated as 0 null character of string.
If position is positive, then Sadas counts from the beginning of char to find the first
character.
char
can be any of the datatypes CHAR, CHARACTER or VARCHAR. Both position and
substring_length
must be cardinal (integer not negative) numbers. The return value is the
same datatype as char. Floating-point are not accepted.
Examples
The following example returns several specified substrings of "ABCDEFG":
SELECT SUBSTR('ABCDEFG',3,4) "Substring"
FROM DUAL;
Substring
--------CDEF
© 2014 Advanced Systems srl
SQL Functions
4.92
114
SUM
Syntax
Purpose
SUM
returns the sample sum of expr, a set of numbers. You can only use it as an aggregate.
This function takes as an argument any numeric datatype. The function returns the same
datatype as the numeric datatype of the argument.
Aggregate Example
The following example calculates the sum of all salaries in the sample hr.employees table:
SELECT SUM(salary) "Total"
FROM employees;
Total
---------691400
4.93
SYSDATE
Syntax
Purpose
SYSDATE
returns the current date of system.
Example
SELECT SYSDATE FROM DUAL;
SYSDATE
---------19/06/2008
© 2014 Advanced Systems srl
SQL Functions
4.94
115
SYSTIME
Syntax
Purpose
SYSTIME
returns the current time of system.
Example
SELECT SYSTIME FROM DUAL;
SYSTIME
-----------12:28:38:375
4.95
SYSTIMESTAMP
Syntax
Purpose
SYSTIMESTAMP
returns the current timestamp of system.
Example
SELECT SYSTIMESTAMP FROM DUAL;
SYSTIMESTAMP
----------------------19/06/2008-12:28:38:375
4.96
TAN
Syntax
© 2014 Advanced Systems srl
SQL Functions
116
Purpose
TAN
returns the tangent of n (an angle expressed in radians). The function returns FLOAT
datatype.
Examples
The following example returns the tangent of 135 degrees:
SELECT TAN(135 * PI/180) "Tangent of 135 degrees" FROM DUAL;
Tangent of 135 degrees
---------------------- 1
4.97
TANH
Syntax
Purpose
TANH
returns the hyperbolic tangent of n. The function returns FLOAT datatype.
Examples
The following example returns the hyperbolic tangent of 0.5:
SELECT TANH(0.5) "Hyperbolic tangent of .5" FROM DUAL;
Hyperbolic tangent of .5
-----------------------.46211715726001
4.98
TO_BASE
Syntax
© 2014 Advanced Systems srl
SQL Functions
code
117
can be only a code field.
Purpose
In select clause Sadas usually returns the decoded description of a code field.
TO_BASE
returns the base of a code field. The base of a code field is the input field value.
It is always a string, then the function returns a string.
Example
SELECT SESSO, TO_BASE(SESSO) FROM ANAGRAFICA
SESSO
----------------PERSONA GIURIDICA
PERSONA FISICA
4.99
TO_BASE(“Sesso”)
---------------G
F
TO_CHAR (character)
Syntax
Purpose
TO_CHAR
(character) converts CHAR, CHARACTER or VARCHAR data to the 7-bit ASCII set. The
value returned is always VARCHAR. In this case, Sadas eliminates the function and copies input
value in output.
Examples
The following example interprets a simple string as character data:
SELECT TO_CHAR('01110') FROM DUAL;
TO_CH
----01110
4.100 TO_CHAR (datetime)
Syntax
© 2014 Advanced Systems srl
SQL Functions
118
datetime
can be DATE, TIME or TIMESTAMP.
Purpose
TO_CHAR
(datetime) converts a datetime value of DATE, TIME or TIMESTAMP datatype to a
value of VARCHAR datatype in the format specified by the date format fmt. If you omit fmt,
then date is converted to a VARCHAR value as follows:
DATE
values are converted to values in the default date format (DD/MM/YYYY).
TIME
values are converted to values in the default time format (HH:MM:SS:MS).
TIMESTAMP
values are converted to values in the default timestamp format (DD/MM/
YYYY-HH:MM:SS:MS).
The 'nlsparam' argument specifies the language in which month and day names and
abbreviations are returned. This argument can have this form:
'NLS_DATE_LANGUAGE = language'
If you omit 'nlsparam', then this function uses the default date language for your session.
Following tables show the supported fmt and NLS parameters
Ta ble – Da t e t ime support e d fmt pa ra me t e r
Fmt
Description
/
,
.
;
:
"text"
Copies character
AD
A.D.
Indicator "Anno
Domini"
AM
A.M.
Indicator "Ante
Meridiem"
or text done
© 2014 Advanced Systems srl
Notes
SQL Functions
119
BC
B.C.
Indicator "Befor
Christ"
CC
SCC
Century
D
Day of week (17)
DAY
Day of
(name)
DD
Day of month (131)
DDD
Day of year (1365/366)
DL
Long date format Used only after 'TS' + blank parameter
DS
Short date format Used only after 'TS' + blank parameter
DY
Short name of
day
week Filled with blank (see FM and FX)
FF[1..9] Tenth of a second
FM
Eliminates in the
output
value
unused
blanks
and
'0' not
significants
FX
Not eliminate in
the output value
unused
blanks
and
'0' not
significants
HH
Hour (1-12)
HH12
Hour (1-12)
HH24
Hour (0-23)
J
Julian Day
MI
Minutes (0-59)
MM
Month (1-12)
MON
Month
name)
(short
MONT Month (full name)
© 2014 Advanced Systems srl
SQL Functions
120
H
PM
P.M.
Indicator "Post
Meridiem"
Q
Quarter
RM
Month
format)
RR
RRRR
Year
SS
Seconds (0-59)
SSSSS
Seconds
midnight
86399).
after
(0-
TS
Standard
format
date See DL and DS
WW
Week of year (153)
W
Week of month
(1-4[5])
Y,YYY
Year
(','
in
specified position)
(roman
YEAR Year; for BC
SYEAR generates initial '-'
YYYY Year; for BC
SYYYY generates initial '-'
YYY
YY
Y
Last 3, 2 o 1
digits of year
Ta ble – Da t e t ime support e d NLS pa ra me t e r
Parametro NLS
Sup Effect
Notes
port
ed
NLS_CALENDAR
YE Calendar type
S
NLS_CHARACTERSET
NO
NLS_COMP
NO
© 2014 Advanced Systems srl
GREGORIAN
Comparison type for
order by clause and where
clause
SQL Functions
121
NLS_CURRENCY
YE Currency
S
NLS_DATE_FORMAT
YE Date format
S
NLS_DATE_LANGUAGE
YE Date format
S
NLS_DUAL_CURRENCY
YE Currency 2
S
NLS_ISO_CURRENCY
YE Currency
S
Territory currency
NLS_LANGUAGE
YE Language
S
ENGLISH, ITALIAN,
ROMANIAN
NLS_LENGTH_SEMANTICS
NO
Set string datatypes length
NLS_NCHAR_CHARACTER_SET
NO
NLS_NCHAR_CONV_EXCP
NO
NLS_NUMERIC_CHARACTERS
YE Numeric format
S
NLS_RDBMS_VERSION
NO Version
NLS_SORT
NO Sort
NLS_TERRITORY
YE Territory
S
EUROPE, ITALY,
ROMANIA
NLS_TIMESTAMP_FORMAT
NO
TIMESTAMP default
Signal error for type
conversions
format
NLS_TIMESTAMP_TZ_FORMAT
NO
NLS_TIME_FORMAT
YE Time format
S
NLS_TIME_TZ_FORMAT
NO
TIMESTAMP default
format with TIMEZONE
TIME default format with
TIMEZONE
NLS_TERRITORY parameter has following dependencies:
NLS_DATE_FORMAT, NLS_TIME_FORMAT, NLS_NUMERIC_CHARACTERS,
NLS_CURRENCY, NLS_DUAL_CURRENCY, NLS_ISO_CURRENCY,
NLS_LANGUAGE, NLS_DATE_LANGUAGE
Ta ble – Da t e t ime support e d NLS t e rrit ory
NLS_TERRITORY
© 2014 Advanced Systems srl
EUROPE
ITALY
ROMANIA
SQL Functions
122
NLS_DATE_FORMAT
DD/MM/YYYY DD/MM/YYYY DD/MM/YYYY
NLS_TIME_FORMAT
HH:MM:SS
HH:MM:SS
HH:MM:SS
NLS_NUMERIC_CHARACTERS ,.
,.
,.
NLS_CURRENCY
€
€
RON
NLS_DUAL_CURRENCY
€
€
RON
NLS_ISO_CURRENCY
EUROPE
ITALY
ROMANIA
NLS_LANGUAGE
ENGLISH
ITALIAN
ROMANIAN
NLS_DATE_LANGUAGE
ENGLISH
ITALIAN
ROMANIAN
Examples
SELECT TO_CHAR('05/01/2007', 'YY-MM-DD') FROM DUAL
DATE
-------07-01-05
SELECT TO_CHAR(L_SHIPTIMESTAMP, 'DD-MON-YYYY HH24:MI:SS.FF3') AS TS_DATE
FROM PROVATS
TS_DATE
-----------------------13-Mar-1996 11:17:25.776
12-Apr-1996 17:15:34.393
4.101 TO_CHAR (number)
Syntax
Purpose
TO_CHAR
(number) converts n to a value of string datatype, using the optional number
format fmt. The value n can be any numeric types. If you omit fmt, then n is converted to a
© 2014 Advanced Systems srl
SQL Functions
123
value exactly long enough to hold its significant digits.
string
The 'nlsparam' argument specifies these characters that are returned by number format
elements:
Decimal character
Group separator
Local currency symbol
International currency symbol
This argument can have this form:
NLS_NUMERIC_CHARACTERS = ''dg''
NLS_CURRENCY = ''text''
NLS_ISO_CURRENCY = territory
The characters d and g represent the decimal character and group separator, respectively. They
must be different single-byte characters. Within the quoted string, you must use two single
quotation marks around the parameter values. Ten characters are available for the currency
symbol.
If you omit 'nlsparam' or any one of the parameters, then this function uses the default
parameter values for your session.
Examples
SELECT TO_CHAR(0111 + 1000) FROM dual;
TO_C
---1111
In the next example, the output is blank padded to the left of the currency symbol.
SELECT TO_CHAR(-10000,'L99G999D99MI') "Amount"
FROM DUAL;
Amount
-------------€10,000.00-
Ta ble – Nume ric support e d forma t
Forma Exampl Description
t
e
© 2014 Advanced Systems srl
Notes
SQL Functions
124
,
9,999
Generates ',' in specified position ',' is generated "in situ"; to specify territory is
(group separator)
preferable 'G' format
.
9.99
Generates '.' in specified position '.' is generated "in situ"; to specify territory is
(decimal character)
preferable 'G' format
$
$9999
Generates '$'
€
€9999
Generates '€'
0
0999
9990
Generates leading blanks
Generates trealing blanks
9
9999
Generates output vlaue with
If the input value has less digits, generates leading
specified digits; positive value
blanks
has leading blank, negative value
has trailing ‘-‘
B
B9999
Leading blanks
C
C999
ISO symbol for currency
See NLS_ISO_CURRENCY
D
99D99
Generates decimal character in
specified position
See NLS_NUMERIC_CHARACTERS
E
EEEE
Generates scientific format
G
9G999
Generates group separator in
specified position
See NLS_NUMERIC_CHARACTERS
L
L999
Cuurency local symbol
See NLS_CURRENCY
MI
9999MI Generates trailing '-' for negative Allowed only at the end of format
values (blank for positive values)
PR
9999PR Generates negative values in
brackets (< >); otherwise
blanks
RN
RN
rn
rn
S
S9999
9999S
Generates '+' o '-' (at end or
begin)
TM
TM
TM9
TME
"Text Minimum" : generates the
shorter format.
© 2014 Advanced Systems srl
Allowed only at the end of format
Generates value in upper roman Only for values 1 – 3999
format
Generates value in lower roman
format
Allowed only at the end or begin of format
SQL Functions
125
4.102 TO_CODE
Syntax
code
can be only a code field.
Purpose
In select clause Sadas usually returns the decoded description of code field.
TO_CODE
returns the internal code of a code field. The internal code of a code field is the
internally representation of the field (numeric short value).
The function returns a unsigned short.
Example
SELECT SESSO, TO_CODE(SESSO) FROM ANAGRAFICA
SESSO
----------------PERSONA GIURIDICA
PERSONA FISICA
TO_CODE(“Sesso”)
---------------3
2
4.103 TO_DATE
Syntax
datetime
date_format
TO_DATE
string
datetime
string
can be DATE or TIMESTAMP datatypes.
can be all character datatypes.
Purpose
TO_DATE
converts char, character, varchar, date or timestamp to a value of DATE
© 2014 Advanced Systems srl
SQL Functions
126
datatype.
If string is not a DATE, Sadas returns error.
If you don't specify format_date, the input string must have the default date format of Sadas:
‘DD/MM/YYYY’
You ca use the following format_date values:
DDMMYY
YYMMDD
MMDDYY
DDMMYYYY
YYYYMMDD
MMDDYYYY
YYYYDDD
DD-MM-YY
YY-MM-DD
MM-DD-YY
DD-MM-YYYY
YYYY-MM-DD
MM-DD-YYYY
YYYY-DDD
In format_date values you can use any char for separator.
Examples
SELECT TO_DATE('01/01/2000-12:46:23:001') AS LDATE FROM DUAL
LDATE
---------01/01/2000
4.104 TO_DESC
Syntax
code
can be only a code field.
Purpose
In select clause Sadas usually returns the decoded description of code field.
TO_DESC
returns the description of a code field.
© 2014 Advanced Systems srl
SQL Functions
127
The function always returns a string.
Example
SELECT SESSO, TO_DESC(SESSO) FROM ANAGRAFICA
SESSO
----------------PERSONA GIURIDICA
PERSONA FISICA
TO_DESC(“Sesso”)
---------------PERSONA GIURIDICA
PERSONA FISICA
4.105 TO_NUMBER
Syntax
default value
TO_NUMBER
expr
(
expr
)
can be all character datatypes.
Purpose
TO_NUMBER
converts expr to a value of NUMBER datatype. The expr can be a value of CHAR,
CHARACTER,
TO_NUMBER
VARCHAR
datatype containing a number. The result type is always FLOAT.
converts expr to a value of NUMBER datatype, considering decimal point e
thousands separator in the current national format:
ITA: decimal separator is comma, thousands separator is point
ENG: decimal separator is point, thousands separator is comma
If expr cannot converted:
withouth default value, Sadas stops the query execution at the current row,
with default value, Sadas put default value in the returned value for the current row.
The default value is optional.
Example
SEL ECT TO_ NUMBER( ' - 1 0 0 ' )
Amo u n t
-------
© 2014 Advanced Systems srl
a s " Amo u n t " FROM DUAL ;
SQL Functions
128
- 100
4.106 TO_TIME
Syntax
datetime
string
can be TIME or TIMESTAMP datatypes.
can be all character datatypes.
Purpose
TO_TIME
converts char, character, varchar, time or timestamp to a value of TIME
datatype.
If string is not a TIME, Sadas returns error
Examples
SELECT TO_TIME('01/01/2000-12:46:23:001') AS LTIME FROM DUAL
LTIME
-----------12:46:23:001
4.107 TO_TIMESTAMP
Syntax
datetime
can be only TIMESTAMP.
© 2014 Advanced Systems srl
SQL Functions
129
string
can be all character datatypes.
Purpose
TO_TIMESTAMP
TIMESTAMP
converts char, character, varchar or timestamp to a value of
datatype. If string is not a TIMESTAMP, Sadas returns error. The input string must
have the default TIMESTAMP format of Sadas: ‘DD/MM/YYYY-HH:MI:SS:MS’
Examples
SELECT TO_TIMESTAMP('01/01/2000-12:46:23:001') AS LTIMESTAMP FROM DUAL
LTIMESTAMP
----------------------01/01/2000-12:46:23:001
4.108 TODAY
Syntax
Purpose
TODAY
returns the current date of system.
Example
SELECT TODAY FROM DUAL;
TODAY
---------19/06/2008
4.109 TRANSLATE
Syntax
Purpose
TRANSLATE
returns expr with all occurrences of each character in from_string replaced by its
© 2014 Advanced Systems srl
SQL Functions
130
corresponding character in to_string.
Characters in expr that are not in from_string are not replaced. If expr is a character string,
then you must enclose it in single quotation marks. The argument from_string can contain
more characters than to_string. In this case, the extra characters at the end of from_string
have no corresponding characters in to_string. If these extra characters appear in char, then
they are removed from the return value.
You cannot use an empty string for to_string to remove all characters in from_string from
the return value. Sadas interprets the empty string as null, and if this function has a null
argument, then it substitutes null.
TRANSLATE
REPLACE
provides functionalities related to those provided by the REPLACE function.
lets you substitute a single string for another single string, as well as remove character
strings. TRANSLATE lets you make several single-character, one-to-one substitutions in one
operation.
Examples
The following statement translates a book title into a string that could be used (for example) as
a filename. The from_string contains four characters: a space, asterisk, slash, and apostrophe
(with an extra apostrophe as the escape character). The to_string contains only three
underscores. This leaves the fourth character in the from_string without a corresponding
replacement, so apostrophes are dropped from the returned value.
SELECT TRANSLATE('SQL*Plus User''s Guide', ' */''', '___') FROM DUAL;
TRANSLATE('SQL*PLUSU
-------------------SQL_Plus_Users_Guide
© 2014 Advanced Systems srl
SQL Functions
131
4.110 TRIM
Syntax
Purpose
TRIM
removes from the left and the right end of char all of the characters that appear in set.
This function is useful for formatting the output of a query. If you do not specify set, then it
defaults to a single blank. Both char and set can be any of the string datatypes.
Example
SELECT TRIM(' X10 ') "TRIM example"
FROM DUAL;
TRIM example
------------X10
4.111 TRUNC[ATE] (number)
Syntax
TRUNC
(
n,dec
)
Purpose
The TRUNC function returns n truncated to dec decimal places.
This function takes as an argument any numeric datatype and always returns an integer type.
Examples
The following examples truncate numbers:
SELECT TRUNC(15.79) "LTruncate" FROM DUAL;
LTruncate
© 2014 Advanced Systems srl
SQL Functions
132
---------15
SELECT TRUNC(15.79,1) "LTruncate" FROM DUAL;
LTruncate
---------15.7
4.112 UCASE
Refer to UPPER function.
4.113 UPPER
Syntax
Purpose
UPPER
returns char, with all letters uppercase. char can be any of the datatypes CHAR,
CHARACTER, VARCHAR.
The return value is the same datatype as char.
Examples
The following example returns a string in uppercase:
SELECT UPPER('mr. scott mcmillan') "Uppercase"
FROM DUAL;
Uppercase
-------------------MR. SCOTT MCMILLAN
4.114 VARIANCE
Syntax
Purpose
VARIANCE
returns the variance of expr, a set of numbers. You can only use it as an aggregate.
Sadas calculates the variance. This function takes as an argument any numeric datatype and
© 2014 Advanced Systems srl
SQL Functions
133
always returns a real number.
Aggregate Examples
The following example returns the variance of the salaries in the sample hr.employees table:
SELECT VARIANCE(salary) "LVar"
FROM employees;
LVAR
---------15283140.5
4.115 VSIZE
Syntax
Purpose
VSIZE
returns the number of bytes in the Sadas internal representation of col.
Examples
SELECT VSIZE(L_QUANTITY) AS INTSIZE FROM LINEITEM
INTSIZE
--------
1
1
…
© 2014 Advanced Systems srl
Part
V
Expressions
5
135
Expressions
This chapter describes how to combine values, operators, and functions into expressions.
This chapter includes these sections:
About SQL Expressions
Simple Expressions
Compound Expressions
Case Expressions
Datetime Expressions
Function Expressions
Scalar Subquery Expressions
Expression Lists
5.1
About SQL Expressions
An expression is a combination of one or more values, operators and SQL functions that
evaluates to a value. An expression generally assumes the datatype of its components.
This simple expression evaluates to 4 and has datatype NUMBER (the same datatype as its
components):
2*2
The following expression is an example of a more complex expression that uses both functions
and operators. The expression truncates 3.2 value and adds seven, and converts the result to
CHAR
datatype:
TO_CHAR(TRUNC(3.2)+7)
© 2014 Advanced Systems srl
Expressions
136
You can use expressions in:
The select list of the SELECT statement
A condition of the WHERE clause and HAVING clause
The GROUP BY clause
The ORDER BY clause
Expressions have several forms, as shown in the following syntax:
Sadas does not accept all forms of expressions in all parts of all SQL statements. Refer to the
individual SQL statements for information on restrictions on the expressions in that statement.
You must use appropriate expression notation whenever expr appears in conditions, SQL
functions, or SQL statements in other parts of this reference. The sections that follow describe
and provide examples of the various forms of expressions.
© 2014 Advanced Systems srl
Expressions
5.2
Simple Expressions
A simple expression specifies a column, constant, or null.
Some valid simple expressions are:
employees.last_name
'this is a text string'
10
'this is an NCHAR string'
© 2014 Advanced Systems srl
137
Expressions
5.3
138
Compound Expressions
A compound expression specifies a combination of other expressions.
You can use any built-in function as an expression (See “Function Expressions” chapter).
However, in a compound expression, some combinations of functions are inappropriate and are
rejected. For example, the LENGTH function is inappropriate within an aggregate function.
Some valid compound expressions are:
('CLARK' + 'SMITH')
LENGTH('MOOSE') * 57
SQRT(144) + 72
SUBSTR(TO_CHAR(sysdate,'DD-MM-YY'),1,2)
5.4
Case Expressions
expressions let you use IF ... THEN ... ELSE logic in SQL statements without
having to invoke procedures.
CASE
© 2014 Advanced Systems srl
Expressions
139
simple_case_expression ::=
searched_case_expression ::=
else_clause ::=
In a simple CASE expression, Sadas Database searches for the first WHEN ... THEN pair for
which expr is equal to comparison_expr and returns return_expr. If none of the WHEN ... THEN
pairs meet this condition, and an ELSE clause exists, then Sadas returns else_expr. Otherwise,
Sadas returns null (blank for alphanumerics and zero for numerics).
In a searched CASE expression, Sadas searches from left to right until it finds an occurrence of
condition that is true, and then returns return_expr. If no condition is found to be true, and an
ELSE clause exists, then Sadas returns else_expr. Otherwise, Sadas returns null.
Sadas Database uses short-circuit evaluation.
For a simple CASE expression, the database evaluates each comparison_expr value only before
comparing it to expr, rather than evaluating all comparison_expr values before comparing any of
them with expr. Consequently, Sadas never evaluates a comparison_expr if a previous
comparison_expr is equal to expr.
For a searched CASE expression, the database evaluates each condition to determine whether it
is true, and never evaluates a condition if the previous condition was true.
For a simple CASE expression, the expr and all comparison_expr values must either have the
same datatype or must all have a numeric datatype. If all expressions have a numeric datatype,
then Sadas determines the argument with the highest numeric precedence, implicitly converts
the remaining arguments to that datatype, and returns that datatype.
© 2014 Advanced Systems srl
Expressions
140
For both simple and searched CASE expressions, all of the return_exprs must either have the
same datatype or must all have a numeric datatype. If all return expressions have a numeric
datatype, then Sadas determines the argument with the highest numeric precedence, implicitly
converts the remaining arguments to that datatype, and returns that datatype.
Simple CASE Example
For each customer in the sample oe. c us t omer s table, the following statement lists the credit
limit as "Low" if it equals $100, "High" if it equals $5000, and "Medium" if it equals anything
else.
SELECT c us t _l as t _name,
CASE c r edi t _l i mi t WHEN 100 THEN ' Low'
WHEN 5000 THEN ' Hi gh'
ELSE ' Medi um' END AS c r edi t
FROM c us t omer s
ORDER BY c us t _l as t _name, c r edi t ;
CUST_LAST_NAME
-------------------Adj ani
Adj ani
Al ex ander
Al ex ander
Al t man
Al t man
. . .
CREDI T
-----Medi um
Medi um
Medi um
Medi um
Hi gh
Medi um
Searched CASE Example
The following statement finds the average salary of the employees in the sample table
oe.employees, using $2000 as the lowest salary possible:
SELECT AVG( CASE WHEN e. s al ar y > 2000 THEN e. s al ar y
ELSE 2000 END) as " Av er age Sal ar y " FROM empl oy ees e;
Av er age Sal ar y
-------------6461. 68224
5.5
Datetime Expressions
A datetime expression yields a value of one of the datetime datatypes.
Datetime functions can be combined according to the rules defined in this SQL Reference.
5.6
Function Expressions
You can use any built-in SQL function as an expression.
Some valid built-in function expressions are:
LENGTH('BLAKE')
ROUND(1234.567*43)
SYSDATE
© 2014 Advanced Systems srl
Expressions
5.7
141
Scalar Subquery Expressions
A scalar subquery expression is a subquery that returns exactly one column value from one
row.
The value of the scalar subquery expression is the value of the select list item of the subquery.
If the subquery returns 0 rows, then the value of the scalar subquery expression is NULL. If the
subquery returns more than one row, then Sadas returns an error.
You can use a scalar subquery expression in most syntax that calls for an expression (expr).
A valid scalar subquery is
SELECT MAX(L_QUANTITY) FROM LINEITEM
5.8
Expression Lists
An expression list is a combination of other expressions.
Expression lists can appear in comparison and membership conditions and in GROUP BY clauses
of queries and subqueries.
Comparison and membership conditions appear in the conditions of WHERE clauses. They can
contain either one or more comma-delimited expressions or one or more sets of expressions
where each set contains one or more comma-delimited expressions.
Multiple sets of expressions are not supported.
The following are some valid expression lists in conditions:
© 2014 Advanced Systems srl
Expressions
142
(10, 20, 40)
('SCOTT', 'BLAKE', 'TAYLOR')
('Guy', 'Himuro', 'GHIMURO')
In this example, the number of expressions in each set must equal the number of expressions in
the first part of the condition. For example:
SELECT * FROM employees
WHERE first_name IN ('Guy', 'Himuro', 'GHIMURO')
Simple GROUP BY clause example:
SELECT department_id, salary, MIN(salary) min, MAX(salary) max FROM
employees
GROUP BY department_id, salary
ORDER BY department_id, min, max;
© 2014 Advanced Systems srl
Part
VI
Conditions
6
144
Conditions
A condition specifies a combination of one or more expressions and logical (Boolean)
operators and returns a value of TRUE, FALSE, or UNKNOWN.
This chapter contains the following sections:
About SQL Conditions
Comparison Conditions
Logical Conditions
Pattern-matching Conditions
Range Conditions
Null Conditions
Compound Conditions
EXISTS Condition
IN Condition
6.1
About SQL Conditions
Conditions can have several forms, as shown in the following syntax.
© 2014 Advanced Systems srl
Conditions
145
The sections that follow describe the various forms of conditions. You must use appropriate
condition syntax whenever condition appears in SQL statements.
You can use a condition in the WHERE clause of these statements:
DELETE
SELECT
You can use a condition in any of these clauses of the SELECT statement:
WHERE
HAVING
A condition could be said to be of a logical datatype, although Sadas does not formally support
such a datatype.
The following simple condition always evaluates to TRUE:
1 = 1
The following more complex condition adds the salary value to the commission_pct value
and determines whether the sum is greater than the number constant 25000:
salary + (salary*commission_pct - 1000) > 25000
Logical conditions can combine multiple conditions into a single condition. For example, you
can use the AND condition to combine two conditions:
(1 = 1) AND (5 < 7)
Here are some valid conditions:
name = 'SMITH'
employees.department_id_fk = departments.department_id_pk
hire_date > '01/02/2001'
job_id IN ('SA_MAN', 'SA_REP')
salary BETWEEN 5000 AND 10000
commission_pct = 0 AND salary = 2100
6.1.1
Condition Precedence
Precedence is the order in which Sadas evaluates different conditions in the same expression.
When evaluating an expression containing multiple conditions, Sadas evaluates conditions with
higher precedence before evaluating those with lower precedence. Sadas evaluates conditions
© 2014 Advanced Systems srl
Conditions
146
with equal precedence from left to right within an expression.
Following table lists the levels of precedence among SQL condition from high to low. As the
table indicates, Sadas evaluates operators before conditions.
Conditions listed on the same line have the same precedence.
The Optimizer decides the execution precedence.
Ta ble – SQL Condit ion pre ce de nce
Type of Condition
Purpose
SQL operators are evaluated before SQL See “Operator Precedence”
conditions
=, !=, <, >, <=, >=,
[NOT] LIKE,
EXISTS
6.2
BETWEEN,
comparison
[NOT]
IN, comparison
NOT
exponentiation,
negation
AND
conjunction
OR
disjunction
logical
Comparison Conditions
Comparison conditions compare one expression with another. The result of such a comparison
can be TRUE, FALSE, or NULL.
When comparing numeric expressions, Sadas uses numeric precedence to determine whether
the condition compares NUMBER or DOUBLE values.
Ta ble – SQL Compa rison condit ions
© 2014 Advanced Systems srl
Conditions
147
Type
Purpose
Example
=
Equality test.
SELECT *
FROM employees
WHERE salary = 2500
!=
^=
<>
Inequality test.
SELECT *
FROM employees
WHERE salary != 2500
>
Greater-than and less-than tests.
SELECT * FROM employees
WHERE salary > 2500
SELECT * FROM employees
WHERE salary < 2500
<
>=
Greater-than-or-equal-to and less-than-or-equal-to tests.
<=
6.2.1
SELECT * FROM employees
WHERE salary >= 2500
SELECT * FROM employees
WHERE salary <= 2500
Simple Comparison Conditions
A simple comparison condition specifies a comparison with expressions or scalar subquery
results.
simple_comparison_condition::=
© 2014 Advanced Systems srl
Conditions
6.3
148
Logical Conditions
A logical condition combines the results of two component conditions to produce a single
result based on them or to invert the result of a single condition.
Following table lists logical conditions.
© 2014 Advanced Systems srl
Conditions
149
Ta ble – Logica l Condit ions
Type Operation
Examples
NOT
SELECT *
FROM lineitem
WHERE NOT (l_quantity = 1);
Returns TRUE if the following condition is FALSE.
Returns FALSE if it is TRUE. If it is UNKNOWN,
then it remains UNKNOWN.
SELECT *
FROM lineitem
WHERE NOT
(l_quantity between 1
10);
AND
Returns TRUE if both component conditions are
TRUE. Returns FALSE if either is FALSE.
Otherwise returns UNKNOWN.
SELECT *
FROM lineitem
WHERE l_quantity = 1
AND l_orderkey < 10000
OR
Returns TRUE if either component condition is
TRUE. Returns FALSE if both are FALSE.
Otherwise returns UNKNOWN.
SELECT *
FROM lineitem
WHERE l_quantity = 1
OR l_orderkey < 10000
AND
Following table shows the result of applying the NOT condition to an expression.
Ta ble – NOT Trut h Ta ble
--
TRUE
FALSE
UNKNOWN
NOT
FALSE
TRUE
UNKNOWN
Following table shows the results of combining the AND condition to two expressions.
Ta ble - A ND Trut h Ta ble
AND
TRUE
FALSE
UNKNOWN
TRUE
TRUE
FALSE
UNKNOWN
FALSE
FALSE
FALSE
FALSE
UNKNOWN
UNKNOWN
FALSE
UNKNOWN
For example, in the WHERE clause of the following SELECT statement, the AND logical condition
is used to ensure that only those hired before 1989 and earning more than $2500 a month are
© 2014 Advanced Systems srl
Conditions
150
returned:
SELECT * FROM employees
WHERE hire_date < TO_DATE('01-JAN-1989', 'DD-MON-YYYY')
AND salary > 2500
ORDER BY employee_id;
Following table shows the results of applying OR to two expressions.
Ta ble - OR Trut h Ta ble
OR
TRUE
FALSE
UNKNOWN
TRUE
TRUE
TRUE
TRUE
FALSE
TRUE
FALSE
UNKNOWN
UNKNOWN
TRUE
UNKNOWN
UNKNOWN
For example, the following query returns employees who have a 40% commission rate or a
salary greater than $20,000:
SELECT employee_id FROM employees
WHERE commission_pct = .4 OR salary > 20000
ORDER BY employee_id;
6.4
Pattern-matching Conditions
The pattern-matching conditions compare character data.
6.4.1
LIKE Condition
The LIKE conditions specify a test involving pattern matching.
Whereas the equality operator (=) exactly matches one character value to another, the LIKE
conditions match a portion of one character value to another by searching the first value for the
pattern specified by the second. LIKE calculates strings using characters as defined by the 7-bit
ASCII character set.
© 2014 Advanced Systems srl
Conditions
151
In this syntax:
char1
is a character expression, such as a character column, called the search value.
char2
is a character expression, usually a literal, called the pattern.
The LIKE condition is the best choice in almost all situations.
All of the character expressions (char1 and char2) can be of any of the datatypes CHAR,
CHARACTER
or VARCHAR.
The pattern can contain special pattern-matching characters:
A percent sign (%) in the pattern can match zero or more characters in the value. The pattern
'%' cannot match a null.
Following table describes the LIKE conditions.
Ta ble - LIKE Condit ions
Type
Operation
Example
x [NOT] LIKE
y
TRUE if x does [not] match the pattern y. Within y, the
character % matches any string of zero or more
characters except null.
SELECT last_name
FROM employees
WHERE last_name
LIKE '%AB%';
With the LIKE conditions, you can compare a value to a pattern rather than to a constant. The
pattern must appear after the LIKE keyword. For example, you can issue the following query to
find the salaries of all employees with names beginning with R:
SELECT salary
FROM employees
WHERE last_name LIKE 'R%'
ORDER BY salary;
The following query uses three ‘%’ characters to find the salaries of all employees with the
name containing in all positions 'R' preceeding 'X':
© 2014 Advanced Systems srl
Conditions
152
SELECT salary
FROM employees
WHERE last_name = '%R%X%'
ORDER BY salary;
The following query uses three ‘%’ characters to find the salaries of all employees with the
name containing '%':
SELECT salary
FROM employees
WHERE last_name = '%%%'
ORDER BY salary;
The following query uses the = operator, rather than the LIKE condition, to find the salaries of
all employees with the name 'R%':
SELECT salary
FROM employees
WHERE last_name = 'R%'
ORDER BY salary;
A text literal must be always on right part of condition, if other part (left) is not a text literal. If
you write the following query, Sadas will return an error.
SELECT salary
FROM employees
WHERE 'SM%' LIKE last_name
ORDER BY salary;
6.4.2
Case Sensitivity
Case is significant in all conditions comparing character expressions that use the LIKE
condition and the equality (=) operators.
6.4.3
Pattern Matching on Indexed Columns
In loading process, Sadas creates special indexes for LIKE operations.
When you use LIKE to search a like-indexed column for a pattern, Sadas can use the special
index to improve performance of a query.
© 2014 Advanced Systems srl
Conditions
6.4.4
153
LIKE Condition: General Examples
This condition is true for all last_name values beginning with Ma:
last_name LIKE 'Ma%'
All of these last_name values make the condition true:
Mallin, Markle, Marlow, Marvins, Marvis, Matos
Case is significant, so last_name values beginning with MA, ma, and mA make the condition
false.
Consider this condition:
last_name LIKE 'SMITH%'
This condition is true for these last_name values:
SMITH, SMITHE, SMITHY, SMITHS
6.5
Range Conditions
A range condition tests for inclusion in a range.
Following table describes the range conditions.
Ta ble - Ra nge Condit ions
Type
Operation
Example
[NOT] BETWEEN x AND
y
[Not] greater than or equal to x and less
employees
than or equal to y.
WHERE salary
SELECT * FROM
BETWEEN 2000 AND
3000;
Sadas tries to transform the two-collection conditions in between conditions.
Following table shows range types to manage these conditions.
© 2014 Advanced Systems srl
Conditions
154
Ta ble –Ra nge Ty pe s
6.6
Type
Operation
Example
CLOSED
Greater than or equal to x and less than or equal to y.
OPENED
Greater than x and less than y.
CLOSELEFT
Greater than or equal to x and less than to y.
A >= x and A < y
[x <= y]
CLOSERIGH
Greater than to x and less than or equal to y.
T
A > x and A <= y
[x <= y]
A >= x and A <= y
[x <= y]
A > x and A < y
[x <= y]
Null Conditions
In Sadas system the NULL values are as all other values.
The NULL conditions is only supported for SQL-99 compatibility, but it returns always TRUE
for IS NOT NULL condition and always FALSE for IS NULL condition.
Following tables shows NULL values for all datatypes.
Alphanumeric
Null Value: 0x00 ( for entire field length )
Date – Time – Timestamp - Code
Null Value : 0x00
Numeric
Bytes number
State
Hexa-decimal value
Value
1
unsigned
FF
255
1
signed
7F
127
2
unsigned
FF FF
65.535
2
signed
FF 7F
32.767
© 2014 Advanced Systems srl
Conditions
6.7
155
3
unsigned
FF FF FF
16.777.215
3
signed
FF FF 7F
8.388.607
4
unsigned
FF FF FF FF
4.294.967.295
4
signed
FF FF FF 7F
2.147.483.647
5
unsigned
FF FF FF FF FF
1.099.511.627.775
5
signed
FF FF FF FF 7F
549.755.813.887
6
unsigned
FF FF FF FF FF FF
281.474.976.710.655
6
signed
FF FF FF FF FF 7F
140.737.488.355.327
7
unsigned
FF FF FF FF FF FF FF
72.057.594.037.927.936
7
signed
FF FF FF FF FF FF 7F
36.028.797.018.963.967
8
unsigned
FF FF FF FF FF FF FF FF
18.446.744.073.709.551.616
8
signed
FF FF FF FF FF FF FF 7F
9.223.372.036.854.775.807
Compound Conditions
A compound condition specifies a combination of other conditions.
See also chapter “Logical Conditions” for more information about NOT, AND, and OR conditions
© 2014 Advanced Systems srl
Conditions
6.8
156
EXISTS Condition
EXISTS Condition
An EXISTS condition tests for existence of rows in a subquery.
Following table shows the EXISTS condition.
Ta ble - EX ISTS Condit ion
6.9
Type
Operation
Example
EXISTS
TRUE if a subquery returns at least one row.
SELECT department_id
FROM departments
WHERE EXISTS
(SELECT * FROM employees)
ORDER BY department_id;
IN Condition
An in_condition is a membership condition. It tests a value for membership in a list of values
or subquery
in_conditions::=
expression_list::=
© 2014 Advanced Systems srl
Conditions
157
Following table lists the form of IN condition.
Ta ble - IN Condit ions
Type
Operation
IN
Equal-to-any-member-of
=ANY.
Example
test.
Equivalent
to
SELECT * FROM employees
WHERE job_id IN
('PU_CLERK','SH_CLERK')
ORDER BY employee_id;
SELECT * FROM employees
WHERE salary IN
(SELECT dsalary
FROM departments
WHERE department_id =30)
ORDER BY employee_id;
NOT
IN
Equivalent to !=ALL. Evaluates to FALSE if any
member of the set is NULL. Sadas does not
support NOT IN with subquery
SELECT * FROM employees
WHERE job_id NOT IN
('PU_CLERK', 'SH_CLERK')
ORDER BY employee_id;
There are restrictions in WHERE Clauses: In a IN condition in a WHERE clause, if the righthand side of the condition is a subquery: you cannot use dynamic and related subqueries.
© 2014 Advanced Systems srl
Part
VII
SQL DDL Clauses (constraint)
7
159
SQL DDL Clauses (constraint)
Purpose
Use a constraint to define an integrity constraint that restricts the values in a database.
Sadas lets you create two types of constraints and lets you declare them in two ways:
A primary key constraint combines a NOT NULL constraint and a unique constraint in a
single declaration. It prohibits multiple rows from having the same value in the same
column and prohibits values from being null.
A foreign key constraint requires values in one table to match values in another table.
With virtual constraint Sadas creates a field-container for update operations.
A NOT NULL constraint prohibits a database value from being null. In this version of
Sadas this constraint has no effect, because the management of null values is not yet
complete.
You can define constraints syntactically in two ways:
As part of the definition of an individual column or attribute. This is called inline
specification.
As part of the table definition. This is called out-of-line specification.
Constraint clauses can appear in the following statements:
CREATE TABLE
ALTER TABLE
You can specify primary key, and foreign key constraints on views.
You cannot combine primary or foreign keys with virtual constraints.
Prerequisites
You must have the privileges necessary to issue the statement in which you are defining the
constraint.
To create a foreign key constraint, in addition, the parent table or view must be in your own
schema or you must have the privileges necessary on the table of the columns of the referenced
key in the parent table or view.
© 2014 Advanced Systems srl
SQL DDL Clauses (constraint)
Syntax example
inline spefication
CREATE TABLE REGION
(
R_REGIONKEY INTEGER (10) PRIMARY KEY,
R_NAME CHAR (25) NOT NULL,
R_COMMENT CHAR (152)
)
CREATE TABLE NATION
(
N_NATIONKEY INTEGER (10) PRIMARY KEY,
N_NAME CHAR (25),
N_REGIONKEY INTEGER (10) FOREIGN KEY REFERENCES REGION(R_REGIONKEY),
N_COMMENT CHAR (152)
)
CREATE TABLE REGION
(
R_REGIONKEY INTEGER (10) VIRTUAL,
R_NAME CHAR (25),
R_COMMENT CHAR (152)
)
out-of-line spefication
CREATE TABLE DEMO AS SELECT * FROM NATION
ALTER TABLE DEMO MODIFY (N_NATIONKEY INTEGER(2) PRIMARY KEY)
ALTER TABLE DEMO MODIFY (N_NATIONKEY INTEGER(2) VIRTUAL)
ALTER TABLE DEMO MODIFY (N_REGIONKEY INTEGER(10) FOREIGN KEY REFERENCES REGION
© 2014 Advanced Systems srl
160
SQL DDL Clauses (constraint)
161
(R_REGIONKEY))
display constraints
desc syskeys (primary keys)
desc sysforeignkeys (foreign keys)
7.1
Primary Key Constraints
Primary Key Constraints
A primary key constraint designates a column as the primary key of a table or view.
A composite primary key designates a combination of columns as the primary key. In Sadas you
cannot define a composite PRIMARY KEY, but you first must define a composite field and then
you can define a composite PRIMARY KEY. When you define a primary key constraint inline,
you need only the PRIMARY KEY keywords. When you define a primary key constraint out of
line, you must also specify one column.
A primary key constraint combines a NOT NULL and unique constraint in one declaration.
Therefore, to satisfy a primary key constraint:
No primary key value can appear in more than one row in the table.
No column that is part of the primary key can contain a null.
A table or view can have only one primary key. You can designate the same column or
combination of columns as both a primary key and a foreign key.
7.2
Foreign Key Constraints
A foreign key constraint (also called a referential integrity constraint) designates a column as
the foreign key and establishes a relationship between that foreign key and a specified primary
key, called the referenced key.
In Sadas you cannot define a composite FOREIGN KEY, but you first must define a composite
field and then you can define a composite FOREIGN KEY.
The table or view containing the foreign key is called the child object, and the table or view
containing the referenced key is called the parent object.
© 2014 Advanced Systems srl
SQL DDL Clauses (constraint)
162
You can define a foreign key constraint on a single key column either inline or out of line.
You can designate the same column or combination of columns as both a foreign key and a
primary key.
The referenced unique or primary key constraint on the parent table or view must already be
defined. The child and parent tables must be on the same database.
7.3
Virtual Constraints
Purpose
A virtual constraint defines a new column within the table to be used as a container, not
specifically related to input data fields.
Virtual columns can be specified at table definition time, or at a later moment when table has
already been loaded. When defining a virtual column, a default value can be specified.
Contents of virtual columns can be modified (through i.e. values of expressions) by using the
UPDATE script. Values assigned to virtual columns are lost (and reset to default) when a new
loading for the table occurs.
Example:
ALTER TABLE TT ADD (NET_PRICE decimal(13,2) VIRTUAL)
UPDATE TT SET NET_PRICE = (GROSS_PRICE-VAT_AMOUNT)
In this example a new column NET-PRICE is defined in the table. The column does not
correspond to any physical input field but is computed as a result of an expression on existing
fields.
© 2014 Advanced Systems srl
Part
VIII
SQL Queries and Subqueries
8
164
SQL Queries and Subqueries
This chapter describes SQL queries and subqueries.
This chapter contains these sections:
About Queries and Subqueries
Creating Simple Queries
The UNION [ALL], INTERSECT, MINUS Operators
Sorting Query Results
Joins
Using Subqueries
Unnesting of Nested Subqueries
Selecting from the DUAL Table
8.1
About Queries and Subqueries
A query is an operation that retrieves data from one or more tables or views. In this reference, a
top-level SELECT statement is called a query, and a query nested within another SQL statement
is called a subquery.
This section describes some types of queries and subqueries and how to use them. The top
level of the syntax is shown in this chapter. Refer to “SELECT” chapter for the full syntax of
all the clauses and the semantics of this statement.
subquery::=
© 2014 Advanced Systems srl
SQL Queries and Subqueries
165
query_block::=
group_by_clause
8.2
can be substituted by distribute_by_clause.
Creating Simple Queries
The list of expressions that appears after the SELECT keyword and before the FROM clause is
called the select list.
© 2014 Advanced Systems srl
SQL Queries and Subqueries
166
Within the select list, you specify one or more columns in the set of rows you want Sadas
Database to return from one or more tables, views, or materialized views. The number of
columns, as well as their datatype and length, are determined by the elements of the select list.
If two or more tables have some column names in common, then you must qualify column
names with names of tables. Otherwise, fully qualified column names are optional. However, it
is always a good idea to qualify table and column references explicitly. Sadas often does less
work with fully qualified table and column names.
You can use a column alias, c_alias, to label the immediately preceding expression in the
select list so that the column is displayed with a new heading. The alias effectively renames the
select list item for the duration of the query. The alias can be used in all clauses in the query.
8.3
The UNION [ALL], INTERSECT, MINUS Operators
You can combine multiple queries using the set operators UNION, UNION ALL, INTERSECT, and
MINUS.
All set operators have equal precedence. If a SQL statement contains multiple set operators,
then Sadas Database evaluates them from the left to right unless parentheses explicitly specify
another order.
The corresponding expressions in the select lists of the component queries of a compound
query must match in number and must be in the same datatype group (such as numeric or
character).
Sadas makes special controls for code and pseudo-code fields; in these cases the
corresponding decode tables must be identical. For numeric expressions or fields, all queries
must select INTEGER (with or without decimals) or FLOAT datatypes.
The order by clause on total set of rows retrieved is not currently supported in Sadas.
.
© 2014 Advanced Systems srl
SQL Queries and Subqueries
167
If component queries select character data, then the datatype of the return values are
determined as follows:
If both queries select values of datatype CHAR [VARCHAR] of equal length, then the
returned values have datatype CHAR [VARCHAR] of that length. If the queries select
values of CHAR [VARCHAR] with different lengths, then the returned value is CHAR
[VARCHAR]
with the length of the larger CHAR [VARCHAR] value.
UNION Example
The following statement combines the results of two queries with the UNION operator, which
eliminates duplicate selected rows. This statement shows that you must match datatype (using
the TO_CHAR function) when columns do not exist in one or the other table:
SELECT location_id, department_name as "Department",
‘ ‘ as "Warehouse" FROM departments
UNION
SELECT location_id, ‘ ‘ as "Department", warehouse_name
FROM warehouses;
LOCATION_ID
----------1400
1400
1500
1500
1600
1700
1700
1700
1700
1700
1700
...
Department
Warehouse
------------------------------ --------------------------IT
Southlake, Texas
Shipping
San Francisco
New Jersey
Accounting
Administration
Benefits
Construction
Contracting
Control And Credit
UNION ALL Example
The UNION operator returns only distinct rows that appear in either result, while the UNION ALL
operator returns all rows. The UNION ALL operator does not eliminate duplicate selected rows:
SELECT product_id FROM order_items
UNION
SELECT product_id FROM inventories
© 2014 Advanced Systems srl
SQL Queries and Subqueries
SELECT location_id
UNION ALL
SELECT location_id
168
FROM locations
FROM departments
A location_id value that appears multiple times in either or both queries (such as '1700') is
returned only once by the UNION operator, but multiple times by the UNION ALL operator.
INTERSECT Example
The following statement combines the results with the INTERSECT operator, which returns only
those rows returned by both queries:
SELECT product_id FROM inventories
INTERSECT
SELECT product_id FROM order_items
MINUS Example
The following statement combines results with the MINUS operator, which returns only unique
rows returned by the first query but not by the second:
SELECT product_id FROM inventories
MINUS
SELECT product_id FROM order_items
8.4
Sorting Query Results
Use the ORDER BY clause to order the rows selected by a query.
Sorting by position is useful to order by a lengthy select list expression, you can specify its
position in the ORDER BY clause rather than duplicate the entire expression.
Sadas can execute the physical sort in memory or using disk.
The Sadas basic alghoritm is Quick Sort Modified, on which Sadas applies several
optimizations.
© 2014 Advanced Systems srl
SQL Queries and Subqueries
169
The result of group by clause and distinct operations are always sorted ascending too.
8.5
Joins
Joins
A join is a query that combines rows from two or more tables or views.
Sadas performs a join whenever multiple tables appear in the FROM clause of the query. The
select list of the query can select any columns from any of these tables. If any two of these
tables have a column name in common, then you must qualify all references to these columns
throughout the query with table names to avoid ambiguity.
8.5.1
Join Conditions
Most join queries contain at least one join condition, either in the FROM clause or in the WHERE
clause.
The join condition compares two or more columns, each from a different table. To execute a
join, Sadas combines pairs of rows, each containing one row from each table, for which the join
condition evaluates to TRUE. The columns in the join conditions need not also appear in the
select list.
To execute a join of three or more tables, Sadas first joins two of the tables based on the join
conditions comparing their columns and then joins the result to another table based on join
conditions containing columns of the joined tables and the new table. Sadas continues this
process until all tables are joined into the result.
The optimizer determines the order in which Sadas joins tables based on the join conditions,
indexes on the tables, and, any available statistics for the tables. The join physical operators are
always binary.
The natural join schema for Sadas is the Star Schema or Snow Flake Schema. On this schema
you can specify join conditions in where clause (implicit), or you can use the explicit join
clause.
© 2014 Advanced Systems srl
SQL Queries and Subqueries
170
The following table contains the supported joins by Sadas.
Ta ble – Sa da s Joins
Standard Type
8.5.2
Supported Sadas Type
Clause Type
Equijoins
Yes
Equijoins
Implicit /
Explicit
Selfjoins
Yes
Selfjoins
Implicit /
Explicit
Cartesian
product
No
Cartesian
product
--
Inner Joins
Yes
Inner Joins
Implicit /
Explicit
Outer Joins
Yes
Outer Joins
Explicit
Semijoins
Yes
Star Join
Explicit
Antijoins
Yes
Not Star Join
Explicit
Equijoins
An equijoin is a join with a join condition containing an equality operator.
An equijoin combines rows that have equivalent values for the specified columns. Depending
on the internal algorithm the optimizer chooses to execute the join, the total size of the
columns in the equijoin condition in a single table may be limited to the size of a data block
minus some overhead. The size of a data block is specified by the setting parameter
LENGTH_BUFFER.
Example
SELECT L_QUANTITY, O_ORDERDATE FROM LINEITEM, ORDERS
WHERE L_ORDERKEY = O_ORDERKEY
8.5.3
Self Joins
A self join is a join of a table to itself.
© 2014 Advanced Systems srl
SQL Queries and Subqueries
171
This table appears twice in the FROM clause and is followed by table aliases that qualify column
names in the join condition. To perform a self join, Sadas combines and returns rows of the
table that satisfy the join condition.
Example
SELECT L_QUANTITY,L_SHIPDATE,L_PARTKEY,L_SUPPKEY
FROM LINEITEM A INNER JOIN LINEITEM B ON A.L_ORDERKEY = B.L_QUANTITY
8.5.4
Special notes
Let’s consider this query:
SELECT ANAGRAFICA.NOME, REGIONE.PAESE
FROM ANAGRAFICA LEFT OUTER JOIN REGIONE ON (ANAGRAFICA.CODPAE =
REGIONE.CODPAE)
We project from ANAGRAFICA the field NOME (all) and the name of the country only if it is
encoded in the REGIONE table.
In this way the result set will also include all the values for ANAGRAFICA.NOME for which
the field CODPAE is not encoded in the REGION table.
The result set will show:
NOME
PAESE
ROSSI
FRANCIA
BIANCHI
ITALIA
ESPOSITO
VERDI
GERMANIA
If a restriction in the right table in the ON clause appears in the SELECT statement:
SELECT ANAGRAFICA.NOME, REGIONE.PAESE
FROM ANAGRAFICA LEFT OUTER JOIN REGIONE ON (ANAGRAFICA.CODPAE =
REGIONE.CODPAE AND REGIONE.PAESE = ‘ITALIA’)
The number of rows in the result set will be the same but values for PAESE different from
‘ITALIA’ will not be shown:
© 2014 Advanced Systems srl
SQL Queries and Subqueries
NOME
172
PAESE
ROSSI
BIANCHI
ITALIA
ESPOSITO
VERDI
If the condition PAESE = ‘ITALIA’ is moved in the WHERE clause:
SELECT ANAGRAFICA.NOME, REGIONE.PAESE
FROM ANAGRAFICA LEFT OUTER JOIN REGIONE ON (ANAGRAFICA.CODPAE =
REGIONE.CODPAE ) WHERE REGIONE.PAESE = ‘ITALIA’
In this case the WHERE clause is applied only after the JOIN condition is processed: thus all
the rows not containing the value ‘ITALIA’ in the field PAESE are excluded from the result
set:
NOME
PAESE
BIANCHI
ITALIA
In this particular case the LEFT OUTER JOIN clause produces the same results of an INNER
JOIN clause.
In SADAS, conditions for restrictions on tables not included in the relationship of equality
between keys cannot be included in the ON clause, but only in the WHERE clause, because
the ON clause can only contain JOIN conditions (in order to use indexes).
This means that even if the statement includes a restriction in the WHERE clause, SADAS
includes the restriction in the JOIN processing and does not apply the restriction on the
projection stage.
Thus to obtain in SADAS a result set containing only the ‘ITALIA’ values for the PAESE
column, the equivalent INNER clause must be used in the query.
SELECT ANAGRAFICA.NOME, REGIONE.PAESE
FROM ANAGRAFICA INNER JOIN REGIONE ON (ANAGRAFICA.CODPAE =
REGIONE.CODPAE ) WHERE REGIONE.PAESE = ‘ITALIA’
The result set will be:
NOME
© 2014 Advanced Systems srl
PAESE
SQL Queries and Subqueries
BIANCHI
173
ITALIA
The same considerations can be applied to RIGHT OUTER and FULL OUTER joins.
8.5.5
Special outer joins
A SQL join clause combines records from two or more tables in a database.
The result of a left outer join (or simply left join) for table A and B always contains all records
of the "left" table (A), even if the join-condition does not find any matching record in the
"right" table (B). This means that if the ON clause matches 0 (zero) records in B (for a given
record in A), the join will still return a row in the result (for that record)—but with NULL in
each column from B. A left outer join returns all the values from an inner join plus all values in
the left table that do not match to the right table.
In Sadas a rightnull outer join returns only all values in the left table that do not match
to the right table.
A right outer join (or right join) closely resembles a left outer join, except with the treatment of
the tables reversed. Every row from the "right" table (B) will appear in the joined table at least
once. If no matching row from the "left" table (A) exists, NULL will appear in columns from A
for those records that have no match in B.
A right outer join returns all the values from the right table and matched values from the left
table (NULL in case of no matching join predicate).
In Sadas a lefttnull outer join returns only all values in the right table that do not match
to the left table.
8.6
Using Subqueries
A subquery answers multiple-part questions.
For example, to determine who works in Taylor's department, you can first use a subquery to
determine the department in which Taylor works. You can then answer the original question
with the parent SELECT statement.
A subquery in the FROM clause of a SELECT statement is also called an inline view.
© 2014 Advanced Systems srl
SQL Queries and Subqueries
174
A subquery in the WHERE clause of a SELECT statement is also called a nested subquery.
Sadas does not impose any limit on the number of subquery levels in the FROM clause and in
the WHERE clause of the top-level query. If columns in a subquery have the same name as
columns in the containing statement, then you must prefix any reference to the column of the
table from the containing statement with the table name or alias. To make your statements
easier to read, always qualify the columns in a subquery with the name or alias of the table,
view, or materialized view.
In the FROM clause can coexist objects (tables, views or synonyms) and subqueries.
Sadas does not perform correlated subqueries (when a nested subquery references a column
from a table referred to a parent statement any number of levels above the subquery).
Scalar subqueries, which return a single column value from a single row, are a valid form of
expression. You can use scalar subquery expressions in most of the places where expr is called
for in syntax.
8.7
Unnesting of Nested Subqueries
Subqueries are nested when they appear in the WHERE clause of the parent statement.
When Sadas evaluates a statement with a nested subquery, it must evaluate the subquery
portion multiple times and may overlook some efficient access paths or joins.
Subquery unnesting unnests and merges the body of the subquery into the body of the
statement that contains it, allowing the optimizer to consider them together when evaluating
access paths and joins. The optimizer can unnest most subqueries, with some exceptions.
Those exceptions include hierarchical subqueries, a nested aggregate function, or a correlated
reference to a query block that is not the immediate outer query block of the subquery.
Sadas supports all scalar sub-queries.
Sadas does not support correlated subqueries. Sadas resolves only the subqueries in the WHERE
clause that can be unnested.
© 2014 Advanced Systems srl
SQL Queries and Subqueries
8.8
175
Selecting from the DUAL Table
DUAL
is a table automatically created by Sadas along with the data dictionary. DUAL is in the
schema of the user SYSDBA but is accessible by the name DUAL to all users.
It has one column, DUMMY, defined to be VARCHAR2(1), and contains one row with a value X.
Selecting from the DUAL table is useful for computing a constant expression with the SELECT
statement. Because DUAL has only one row, the constant is returned only once.
Alternatively, you can select a constant or expression from any table, but the value will be
returned as many times as there are rows in the table. Refer to “About SQL Functions” chapter
for many examples of selecting a constant value from DUAL.
© 2014 Advanced Systems srl
Part
IX
SQL STATEMENTS
9
SQL STATEMENTS
9.1
Types of SQL Statements
177
The lists in the following sections provide a functional summary of SQL statements Most SQL
statements belong to these categories:
Data Definition Language (DDL) Statements
Data Manipulation Language (DML) Statements
9.2
Data Definition Language (DDL) Statements
Data definition language (DDL) statements let you to perform these tasks:
Create, alter, and drop schema objects
Grant and revoke privileges and roles
Analyze information on a table or index
Load table or entire database
The LOAD, CREATE, ALTER, and DROP commands require exclusive access to the specified
object. For example, an ALTER TABLE statement fails if another user has an open transaction on
the specified table.
The GRANT and REVOKE commands do not require exclusive access to the specified object.
The DDL statements are:
ALTER
CREATE
DROP
GRANT
LOAD / APPEND
REVOKE
TRUNCATE
© 2014 Advanced Systems srl
SQL STATEMENTS
9.3
178
Data Manipulation Language (DML) Statements
Data manipulation language (DML) statements access and manipulate data in existing schema
objects.
The data manipulation language statements are:
DELETE
SELECT
UPDATE
The SELECT statement is a limited form of DML statement in that it can only access data in the
database. It cannot manipulate data in the database, although it can operate on the accessed
data before returning the results of the query.
9.4
ALTER TABLE
Purpose
Use the ALTER TABLE statement to alter the definition of a table.
The table must be in your own schema/database, and you must have CATALOG privilege on the
table.
If you change structure of a loaded table, the changes to the table are not immediately
available, but
Sadas creates a copy of catalog structure of the table (shadow table); so you can query the table
with the old data (consistent with old table structure) and, on new loading process, the shadow
table will substitute the catalog structure of the table. If the structure of a table does not
change, the shadow table does not exist.
Syntax
<alter_table>
::=
ALTER TABLE table_name
ADD '(' <modify_list> ')'
| DROP COLUMN '(' <column (, column)*
© 2014 Advanced Systems srl
SQL STATEMENTS
179
| MODIFY '(' <modify_list> ')'
alter_table::=
Groups of ALTER TABLE syntax:
column_clauses::=
constraint_clauses::=
After each clause you will find links to its component sub-clauses.
column_clauses::=
add_column_clauses::=
© 2014 Advanced Systems srl
SQL STATEMENTS
column_definition::=
modify_column_clauses::=
modify_col_properties::=
drop_column_clause ::=
© 2014 Advanced Systems srl
180
SQL STATEMENTS
181
constraint_clauses::=
Semantics
Many clauses of the ALTER TABLE statement have the same functionality they have in a CREATE
TABLE
statement. For more information on such clauses, please see chapter “Create Table”.
schema
Specify the schema/database containing the table. If you omit schema, then Sadas assumes the
© 2014 Advanced Systems srl
SQL STATEMENTS
182
table is in current database.
table
Specify the name of the table to be altered.
column_clauses
Use these clauses to add, drop, or otherwise modify a column.
add_column_clause
The add_column_clause lets you add a column to a table.
inline_constraint
Use inline_constraint to add a constraint to the new column.
modify_column_clauses
Use the modify_column_clauses to modify the properties of an existing column or the
substitutability of an existing object type column.
modify_col_properties
Use this clause to modify the properties of the column. Any optional parts of the column
definition (datatype, default value, or constraint) that you omit from this clause remains
unchanged.
datatype
You can change the datatype of any column if all rows of the column contain nulls.
You can always increase the size of a character or the precision of a numeric column, whether
or not all the rows contain nulls. You can reduce the size of a datatype of a column.
All changes will be in effect only after load (rewrite) process.
inline_constraint
This clause lets you add a constraint to a column you are modifying. To change the state of
existing constraints on existing columns, use the constraint_clauses.
© 2014 Advanced Systems srl
SQL STATEMENTS
183
drop_column_clause
The drop_column_clause lets you drop columns you no longer need.
constraint_clauses
Use the constraint_clauses to add a new constraint using out-of-line declaration, modify
the state of an existing constraint, or drop a constraint.
Adding a Constraint
The ADD clause lets you add a new out-of-line constraint or out-of-line REF constraint to the
table.
Modifying a Constraint
The MODIFY CONSTRAINT clause lets you change the state of an existing constraint.
PRIMARY KEY
Specify PRIMARY KEY to drop the primary key constraint of table.
Examples
ALTER TABLE DEMO_TABLE ADD (NEW_FIELD INTEGER(2))
ALTER
TABLE
DEMO_TABLE
MODIFY
(N_NATIONKEY
(adding a new field)
INTEGER(2)
PRIMARY
KEY)
(modifying a field and adding a primary key)
ALTER
TABLE
DEMO_TABLE
MODIFY
REFERENCES REGION(R_REGIONKEY))
9.5
(N_REGIONKEY
INTEGER(10)
FOREIGN
KEY
(modifying a field and adding a foreing key)
ALTER USER
Purpose
Use the ALTER USER statement to modify the characteristics of the password of a database user.
With this statement you can specify the characteristics of the password: expired or life time
(days).
Prerequisites
You must have the SECURITY system privilege on database. Each database has own set of
© 2014 Advanced Systems srl
SQL STATEMENTS
184
users. To create a user on database, you must be connected to that database.
For add, edit and delete a privilege see the GRANT and REVOKE chapters.
Syntax
<alter_user>
::=
ALTER USER user_name
[ PASSWORD EXPIRE | PASSWORD_LIFE_TIME [ DEFAULT |
days | UNLIMITED ] ]
alter_user::=
ALTER
USER
user_name
PASSWORD
EXPIRE
DEFAULT
PASSWORD_LIFE_TIME
days
UNLIMITED
Semantics
user_name
Specify the name of the user to be altered. The name can be up to 128 bytes long and can
contain only ASCII characters. The user name is case insensitive and is stored in uppercase
ASCII characters. If you specify the user name as a quoted identifier, then the quotation marks
are silently ignored.
days
© 2014 Advanced Systems srl
SQL STATEMENTS
185
Specify the life time of the password in days.
Example
ALTER USER DEMO_USR PASSWORD EXPIRE
ALTER USER DEMO_USR PASSWORD_LIFE_TIME 365
9.6
ALTER VIEW
Purpose
Use the ALTER VIEW statement to alter the definition of a view.
The view must be in your own schema/database, and you must have CATALOG privilege on the
view.
The alter view can be used only to modify a field specification and to define constraints
(primary key, foreign key). The view is not recompiled after ALTER VIEW operations.
Syntax
<alter_view>
::=
ALTER VIEW view
MODIFY '(' <modify_list> ')'
alter_view::=
Semantics
schema
Specify the schema containing the view. If you omit schema, then Sadas assumes the view is in
your own schema.
view
Specify the name of the view to be altered.
MODIFY CONSTRAINT Clause
© 2014 Advanced Systems srl
SQL STATEMENTS
186
Use the MODIFY CONSTRAINT clause to change or add constraints (primary key, foreign key)
Examples
ALTER VIEW DEMO_VIEW MODIFY (N_NATIONKEY INTEGER(2) PRIMARY KEY)
(modifying
a field and adding a primary key)
ALTER VIEW DEMO_VIEW MODIFY (N_REGIONKEY INTEGER(10) FOREIGN KEY REFERENCES
REGION(R_REGIONKEY))
9.7
(modifying a field and adding a foreing key)
APPEND TABLE
Purpose
Use the APPEND TABLE statement to add records to a table from an input file or from a subquery.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the APPEND TABLE process. While executing this process, Sadas stops all others requests. You
must have LOAD privilege on table to activate this process.
You can specify a list of columns that represents the sort relation of table, to be maintained in
the APPEND TABLE process.
If you specify DIRECT clause, Sadas uses memory buffer of file name area as a single record to
append.
If you specify ONLY clause, Sadas append only n_rec records.
If you specify SKIP clause, Sadas skips first n_rec records.
In this case the loading type is always " APPEND" .
Syntax
<append_table1>
::=
APPEND TABLE table_name ['@' file_name]
[ DIRECT | ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
[ORDER BY <column_list>]
© 2014 Advanced Systems srl
SQL STATEMENTS
187
<append_table2>
::=
APPEND TABLE table_name FROM '('<SubQuery>')'
append_table1::=
append_table2::=
APPEND
TABLE
table_name
FROM
SubQuery
Semantics
table_name
Name of table on which Sadas will apply the APPEND TABLE process. The name can be up to
128 bytes long and can contain only ASCII characters. The table name is case insensitive and
is stored in uppercase ASCII characters. If you specify the table name as a quoted identifier,
then the quotation marks are silently ignored.
file_name
© 2014 Advanced Systems srl
SQL STATEMENTS
188
Name of file that contains records to append. If you omit this parameter, Sadas will read the
file name from the Control Table Loader file registered in the Catalog.
n_rec
Number of records to skip or to append.
column_list
List of attributes to use for ordering purposes.
subquery
Specify the data that Sadas loads. For each subquery Sadas creates a temporary table, which
will be deleted at the end of the query execution.
Examples
APPEND TABLE REGION ONLY 100;
APPEND TABLE REGION SKIP 30;
APPEND TABLE REGION SKIP 30 ONLY 100;
APPEND TABLE DEMO_TABLE@C:\DEMO_TABLE.TXT
APPEND TABLE DEMO_TABLE@C:\DEMO_TABLE.TXT ORDER BY ID_PRODUCT
APPEND
TABLE
REGION@"0|AFRICA|special
Tiresias
about
the
furiously
even
dolphins are furi|" DIRECT
APPEND TABLE REGION FROM (SELECT * FROM REGION2);
9.8
COMMENT ON COLUMN
Purpose
Use the COMMENT ON COLUMN statement to set a comment on a column of a table in the
Catalog.
To drop a comment from the database, set it to the empty (or with only spaces) string ' ': each
COMMENT ON COLUMN
statement rewrites the comment.
If you specify ALL clause instead of table_name, SADAS rewrites comment in any table that
© 2014 Advanced Systems srl
SQL STATEMENTS
189
contains named column.
Prerequisites
To set the COMMENT on a column of a table in the Catalog, you must have the CATALOG system
privilege on that table.
Syntax
<comment_on_column>
::=
COMMENT ON COLUMN
[ column_name OF [ ALL | table_name ]
| table_name.column_name ]
IS 'comment'
COMMENT
ON
COLUMN
schema
.
table_name
column_name
OF
ALL
schema
.
table_name
IS
comment
Semantics
ALL
Specify ALL if you want to modify specified column in all tables of the database..
column_name
© 2014 Advanced Systems srl
.
column_name
SQL STATEMENTS
190
Specify the name of the column to be modified. The name can be up to 128 bytes long and can
contain only ASCII characters. The table name is case insensitive and is stored in uppercase
ASCII characters. If you specify the column name as a quoted identifier, then the quotation
marks are silently ignored.
table_name
Specify the name of the table to be modified. The name can be up to 128 bytes long and can
contain only ASCII characters. The table name is case insensitive and is stored in uppercase
ASCII characters. If you specify the table name as a quoted identifier, then the quotation marks
are silently ignored.
comment
Specify the value of comment to set for the table. Comment is a constant character expression.
Use the text literal notation to specify value of comment.
Examples
COMMENT ON PRODUCT.NAMEPR IS 'PRODUCT NAME';
COMMENT ON NAMEPR OF PRODUCT IS 'PRODUCT NAME';
COMMENT ON NAMEPR OF ALL IS 'PRODUCT NAME';
9.9
COMMENT ON TABLE
Purpose
Use the COMMENT ON TABLE statement to set a comment on a table in the Catalog.
To drop a comment from the database, set it to the empty (or with only spaces) string ' '; each
COMMENT ON TABLE
statement rewrites the comment.
Prerequisites
To set the COMMENT on a table in the Catalog, you must have the CATALOG system privilege on
that table.
© 2014 Advanced Systems srl
SQL STATEMENTS
191
Syntax
<comment_on_table>
::=
COMMENT ON TABLE table_name IS 'comment'
schema
COMMENT
table_name
ON
.
TABLE
IS
comment
Semantics
table_name
Specify the name of the table to be modified. The name can be up to 128 bytes long and can
contain only ASCII characters. The table name is case insensitive and is stored in uppercase
ASCII characters. If you specify the table name as a quoted identifier, then the quotation marks
are silently ignored.
comment
Specify the value of comment to set for the table. Comment is a constant character expression.
Use the text literal notation to specify value of comment.
Examples
COMMENT ON PRODUCT IS 'PRODUCT LIST';
9.10
CONNECT
Purpose
Use the CONNECT command to connect to a database.
The connection is active until the user make requests, within time-out of server setting.
© 2014 Advanced Systems srl
SQL STATEMENTS
192
The Sadas master user is “SYSDBA” (reserved word).
Syntax
<connect>
::=
CONNECT user '/' password '@' database
| CONNECT SYSDBA '/' password [ '@' database ]
Connecting SYSDBA
connect::=
Connecting user
connect::=
Semantics
user
User connecting
password
Password of user connecting
db_name
Name of schema/database to connect. The name can be up to 128 bytes long and can contain
only ASCII characters. The database name is case insensitive and is stored in uppercase ASCII
characters. If you specify the database name as a quoted identifier, then the quotation marks
© 2014 Advanced Systems srl
SQL STATEMENTS
193
are silently ignored.
Examples
CONNECT SYSDBA;
CONNECT SMITH/SMITH@TPCH;
9.11
CREATE DATABASE
Purpose
Use the CREATE DATABASE statement to create a database, making it available for general use.
In Sadas "database" and "schema" have the same meaning. Sadas does not require specific
storage space and RAM area when creating a new database, so several databases can easily be
defined in installation steps (the effective space required will depend from cardinality of data
that will be loaded). Sadas does not use the "synonymous" concept, because each database has
its own set of users.
Prerequisites
Only SYSDBA user can create a database.
Syntax
<create_database>
::=
CREATE DATABASE db_name ['@' storage_path ]
create_database::=
Semantics
db_name
Specify the name of the database to be created. The name must match the value of the
DB_NAME
initialization parameter. The name can be up to 128 bytes long and can contain only
ASCII characters.
© 2014 Advanced Systems srl
SQL STATEMENTS
194
The database name is case insensitive and is stored in uppercase ASCII characters. If you
specify the database name as a quoted identifier, then the quotation marks are silently ignored.
storage_path
Specify the storage path of the database to be created. If the specified path does not exist,
Sadas will create it.
The storage path refers to the data files of the database, while the catalog files are written in
the System Catalog Path. The storage path can also be a shared network drive.
Examples
CREATE DATABASE DB_DEMO
CREATE DATABASE DB_DEMO@c:\path_db_demo
9.12
CREATE DBADMIN
Purpose
Use the CREATE DBADMIN statement to create a system database administrator (sysdba).
With this statement you can only create the sysdba; on creating Sadas grants all privileges to
this sysdba. The default administrator user is SYSDBA.
Prerequisites
Only SYSDBA user can create another system database administrator.
Each system database administrator has all privileges of default SADAS system database
administrator (SYSDBA).
Syntax
<create_dbadmin>
create_dbadmin::=
© 2014 Advanced Systems srl
::=
CREATE DBADMIN user
SQL STATEMENTS
CREATE
195
user
DBADMIN
Semantics
user
Specify the name of the user to be created. The name can be up to 128 bytes long and can
contain only ASCII characters. The user name is case insensitive and is stored in uppercase
ASCII characters. If you specify the user name as a quoted identifier, then the quotation marks
are silently ignored.
Example
CREATE DBADMIN DEMO_DBA
9.13
CREATE DOMAIN
Purpose
Use the CREATE DOMAIN statement to create a domain of users. With this statement you can
only create the domain, but not grant any privilege; so Sadas will initially create the domain
without privileges.
Prerequisites
Only SYSDBA user can create a domain of users. When you create a domain with the CREATE
DOMAIN
statement, the domain's privilege is empty. For add, edit and delete a privilege see the
and REVOKE chapters.
GRANT
Syntax
<create_domain>
::=
CREATE DOMAIN domain_name
create_domain::=
CREATE
Semantics
domain_name
© 2014 Advanced Systems srl
DOMAIN
domain_name
SQL STATEMENTS
196
Specify the name of the domain to be created. The name can be up to 128 bytes long and can
contain only ASCII characters. The domain name is case insensitive and is stored in uppercase
ASCII characters.
Example
CREATE DOMAIN DEMO_DOMAIN
9.14
CREATE EXPRESSION
Purpose
Use the CREATE EXPRESSION statement to define an expression in a table.
The expression created is a new field on the table, calculated using other fields of the same
table.
The table upon which an expression is based is called base table. You can create an expression
also on a table not loaded.
When the base table is modified through a load process all its expressions are recalculated.
Prerequisites
To create an expression on a table, you must have the CATALOG system privilege on the
database.
Syntax
<create_expression>
::=CREATE EXPRESSION expr_name ON TABLE table_name AS '(' <expr>
')'
create_expression::=
CREATE
© 2014 Advanced Systems srl
EXPRESSION
expr_name
SQL STATEMENTS
ON
197
TABLE
table_name
AS
(
expr
)
Semantics
expr_name
Specify the name of the expression. The name can be up to 128 bytes long and can contain only
ASCII characters. The expression name is case insensitive and is stored in uppercase ASCII
characters. If you specify the expression name as a quoted identifier, then the quotation marks
are silently ignored.
table_name
Name of table on which Sadas will create the expression. The name can be up to 128 bytes
long and can contain only ASCII characters. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
expr
Specify an expression representing the information you want to create.
Examples
CREATE EXPRESSION PROVA ON TABLE SUPPLIER AS (S_ACCTBAL/100)
CREATE EXPRESSION PROVA ON TABLE SUPPLIER AS (SUBSTR(S_COMMENT,1,2))
CREATE EXPRESSION PROVA ON TABLE SUPPLIER AS (S_NAME+'00')
CREATE EXPRESSION PROVA ON TABLE SUPPLIER AS (S_NATIONKEY * 1000)
CREATE EXPRESSION PROVA2 ON TABLE SUPPLIER AS (PROVA / 3 )
CREATE EXPRESSION PROVA ON TABLE ORDERS AS (DATEADD('DD',-100,O_ORDERDATE))
CREATE EXPRESSION PROVA ON TABLE SUPPLIER AS (S_NATIONKEY + S_ACCTBAL)
CREATE EXPRESSION PROVA ON TABLE SUPPLIER AS (S_NATIONKEY + S_ACCTBAL / (100))
© 2014 Advanced Systems srl
SQL STATEMENTS
9.15
198
CREATE INDEX
Purpose
Use the CREATE INDEX statement to create an index on a column in a table.
Prerequisites
To create an index on a column in a table, you must have the CATALOG system privilege on the
database.
Syntax
<create_index>
::= CREATE INDEX ON table_name.col_name
create_index::=
CREATE
INDEX
ON
table_name
.
col_name
Semantics
col_name
Specify the name of the column. The name can be up to 128 bytes long and can contain only
ASCII characters. The expression name is case insensitive and is stored in uppercase ASCII
characters. If you specify the expression name as a quoted identifier, then the quotation marks
are silently ignored.
table_name
Name of table on which Sadas will create the expression. The name can be up to 128 bytes
long and can contain only ASCII characters. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
CREATE INDEX ON PRODUCT.COLORPR
© 2014 Advanced Systems srl
SQL STATEMENTS
9.16
199
CREATE SYNONYM
Purpose
Use the CREATE SYNONYM statement to create a synonym, which is an alternative name for a
table of another schema. Synonyms provide both data independence and location transparency.
Synonyms permit applications to function without modification regardless of which user owns
the table and regardless of which database holds the table. You can refer to synonyms only in
the SELECT DML statements.
You cannot create a synonym of a table of the current database.
You cannot create a synonym of a view.
You cannot use a synonym creating a view.
You cannot create a synonym of a synonym.
Prerequisites
To create a synonym you must be a SYSDBA.
Syntax
<create_synonym>
schema.table_name
create_synonym::=
Semantics
OR REPLACE
© 2014 Advanced Systems srl
::=
CREATE
[OR
REPLACE]
[PUBLIC]
synonym_name
FOR
SQL STATEMENTS
200
Specify OR REPLACE to re-create the synonym if it already exists. You can use this clause to
change the definition of an existing synonym without first dropping it.
PUBLIC
Actually PUBLIC clause has not effect. All synonyms are publics.
synonym_name
Specify the name of the synonym to be created. The name can be up to 128 bytes long and can
contain only ASCII characters. The synonym name is case insensitive and is stored in uppercase
ASCII characters. If you specify the synonym name as a quoted identifier, then the quotation
marks are silently ignored.
schema
Specify the schema to contain the table. If you omit schema, then the Sadas creates the table in
current database. This specification is a redundancy, because in Sadas you can create table in a
database only if you are connected to that database. This redundancy is accepted for
compatibility with scripts of third parties.
table_name
Specify the name of the table to be created. The name can be up to 128 bytes long and can
contain only ASCII characters. The table name is case insensitive and is stored in uppercase
ASCII characters. If you specify the table name as a quoted identifier, then the quotation marks
are silently ignored.
Example
CREATE SYNONYM MY_LINEITEM FOR TPCH.LINEITEM
9.17
CREATE TABLE
Purpose
Use the CREATE TABLE statement to create a relational table, which is the basic structure to
hold user data.
© 2014 Advanced Systems srl
SQL STATEMENTS
201
Tables are created with no data (loaded with 0 records) unless a subquery is specified. You can
add rows to a table only with the LOAD processes.
After creating a table, you can define additional columns and integrity constraints with the ADD
clause of the ALTER TABLE statement. You can change the definition of an existing column or
partition with the MODIFY clause of the ALTER TABLE statement. These changes will be
effective only after e new LOAD process.
Prerequisites
To create a relational table in a database, you must have the CATALOG system privilege on that
database.
In order to create a primary or foreign key constraint, you must have the CATALOG privileges
necessary to create an index on the table.
Syntax
<create_table>
::=
CREATE
[GLOBAL
TEMPORARY]
TABLE
table_name
'('
<column_definition> ')'
<create_table>
::=
CREATE
[GLOBAL
TEMPORARY]
TABLE
table_name
AS
'('
<select_statement> ')'
create_table::=
GLOBAL
CREATE
© 2014 Advanced Systems srl
TEMPORARY
TABLE
SQL STATEMENTS
relational_table::=
relational_properties::=
column_definition::=
Semantics
© 2014 Advanced Systems srl
202
SQL STATEMENTS
203
relational_table
Specifications of the table.
GLOBAL TEMPORARY
Specify GLOBAL TEMPORARY to indicate that the table is temporary and that its definition is
visible to all sessions with appropriate privileges. When you first create a temporary table, its
table metadata is stored in the data dictionary, but no space is allocated for table data. Space is
allocated for the table segment at the time of the loading process for the table. The temporary
table definitions will be maintained in the same way as the definitions of regular tables until
when a drop operation is performed by the user.
schema
Specify the schema to contain the table. If you omit schema, then the Sadas creates the table in
current database. This specification is a redundancy, because in Sadas you can create table in a
database only if you are connected to that database. This redundancy is accepted for
compatibility with scripts of third parties.
table_name
Specify the name of the table to be created. The name can be up to 128 bytes long and can
contain only ASCII characters. The table name is case insensitive and is stored in uppercase
ASCII characters. If you specify the table name as a quoted identifier, then the quotation marks
are silently ignored.
relational_properties
The relational properties describe the components of a relational table.
column_definition
The column_definition lets you define the characteristics of the column.
column
Specify the name of a column of the table. The name can be up to 128 bytes long and can
contain only ASCII characters. The column name is case insensitive and is stored in uppercase
© 2014 Advanced Systems srl
SQL STATEMENTS
204
ASCII characters. If you specify the column name as a quoted identifier, then the quotation
marks are silently ignored.
If you also specify AS subquery, then you must omit column and datatype.
datatype
Specify the datatype of a column.
Examples
CREATE TABLE LINEITEM
(
L_ORDERKEY INTEGER (10) FOREIGN KEY REFERENCES ORDERS(O_ORDERKEY),
L_PARTKEY INTEGER (10) FOREIGN KEY REFERENCES PART(P_PARTKEY),
L_SUPPKEY INTEGER (10) FOREIGN KEY REFERENCES SUPPLIER(S_SUPPKEY),
L_LINENUMBER INTEGER (10),
L_QUANTITY INTEGER (12),
L_EXTENDEDPRICE DOUBLE PRECISION (12,2),
L_DISCOUNT DOUBLE PRECISION (12,2),
L_TAX DOUBLE PRECISION (12,2),
L_RETURNFLAG CHAR (1),
L_LINESTATUS CHAR (1),
L_SHIPDATE DATE ,
L_COMMITDATE DATE ,
L_RECEIPTDATE DATE ,
L_SHIPINSTRUCT CHAR (25),
L_SHIPMODE CHAR (10),
L_COMMENT CHAR (44),
L_PARTSUPPKEY CHAR (20) FOREIGN KEY REFERENCES PARTSUPP(PS_PARTSUPPKEY)
)
CREATE TABLE SMART_LINEITEM AS (SELECT * FROM LINEITEM WHERE L_QUANTITY = 50)
9.18
CREATE USER
Purpose
Use the CREATE USER statement to create a database user, which is an account through which
you can log in to the database, and to define the domain to which the user will be associated.
© 2014 Advanced Systems srl
SQL STATEMENTS
205
With this statement you can only create the user, but not grant any privileges; so Sadas will
initially create the user without privileges. The default administrator user is SYSDBA.
You can specify the characteristics of the password: expired or life time (days).
Prerequisites
You must have the SECURITY system privilege on database. Each database has own set of
users. To create a user on database, you must be connected to that database. When you create
a user with the CREATE USER statement, the user's privilege domain is empty. For add, edit and
delete a privilege see the GRANT and REVOKE chapters.
Syntax
<create_user>
::=
CREATE USER user_name
[ '@' domain_name ]
[ PASSWORD EXPIRE | PASSWORD_LIFE_TIME [ DEFAULT |
days | UNLIMITED ] ]
create_user::=
PASSWORD
EXPIRE
DEFAULT
PASSWORD_LIFE_TIME
days
UNLIMITED
© 2014 Advanced Systems srl
SQL STATEMENTS
206
Semantics
user_name
Specify the name of the user to be created. The name can be up to 128 bytes long and can
contain only ASCII characters. The user name is case insensitive and is stored in uppercase
ASCII characters. If you specify the user name as a quoted identifier, then the quotation marks
are silently ignored.
domain_name
Specify the name of the domain of user. The name can be up to 128 bytes long and can contain
only ASCII characters. The domain name is case insensitive and is stored in uppercase ASCII
characters.
days
Specify the life time of the password in days.
Example
CREATE USER DEMO_USR
CREATE USER DEMO_USR@ADVSYS
CREATE USER DEMO_USR PASSWORD EXPIRE
CREATE USER DEMO_USR PASSWORD_LIFE_TIME 365
9.19
CREATE VIEW
Purpose
Use the CREATE VIEW statement to define a view, which is a logical table based on one or more
tables or views.
The tables upon which a view is based are called base tables. In Sadas a view always contains
data itself, and when the base tables are modified through a load process all the views linked to
the reloaded tables are recalculated.
Prerequisites
© 2014 Advanced Systems srl
SQL STATEMENTS
207
To create a view in a database, you must have the CATALOG system privilege on the database.
Syntax
<create_view> ::=CREATE
[OR
REPLACE]
[MATERIALIZED]
VIEW
view_name
AS
'('
<select_statement> ')'
create_view::=
Semantics
OR REPLACE
Specify OR REPLACE to re-create the view if it already exists. You can use this clause to change
the definition of an existing view. The view is recalculated.
schema
Specify the schema to contain the view. If you omit schema, then Sadas will create the view in
current database. This specification is a redundancy, because in Sadas you can create a view in
a database only if you are connected to that database, but this redundancy is accepted for
compatibility with scripts of third parties.
view_name
Specify the name of the view.
Example
© 2014 Advanced Systems srl
SQL STATEMENTS
208
CREATE VIEW PROVA AS SELECT * FROM NATION
CREATE OR REPLACE MATERIALIZED VIEW PROVA AS SELECT * FROM NATION
9.20
DEACTIVATE DATABASE
Purpose
Use the DEACTIVATE DATABASE statement to empty an entire database/schema.
Sadas will erase data of all tables and set their status to " unloaded".
The tables in state " unloaded" are not operative for inquiry.
Prerequisites
Only SYSDBA user can use the DEACTIVATE DATABASE statement.
Syntax
<deactivate_database>
::=
DEACTIVATE DATABASE db_name
deactivate_database::=
DEACTIVATE
DATABASE
db_name
Semantics
db_name
Name of schema/database to be truncated. The name can be up to 128 bytes long and can
contain only ASCII characters.
The database name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
DEACTIVATE DATABASE TPCH;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.21
209
DEACTIVATE TABLE
Purpose
Use the DEACTIVATE TABLE statement to empty a table in current database/schema.
Sadas will erase data of table and will set its status to " loaded with 0 records".
The table in state " unloaded" is not operative for inquiry.
Prerequisites
You must have the LOAD privilege on a table in order to deactivate it.
Syntax
<deactivate_table>
::=
DEACTIVATE TABLE table_name
deactivate_table::=
DEACTIVATE
TABLE
table_name
Semantics
table_name
Name of table to be truncated. The name can be up to 128 bytes long and can contain only
ASCII characters.
The table name is case insensitive and is stored in uppercase ASCII
characters. If you specify the table name as a quoted identifier, then the quotation marks are
silently ignored.
Examples
DEACTIVATE TABLE LINEITEM;
9.22
DELETE STORED QUERIES
Purpose
In SADAS you can memorize the results of events (query or filter) that are accessing a database,
in order to improve processing for potential future requests using same parameters. Specifically,
© 2014 Advanced Systems srl
SQL STATEMENTS
210
you can memorize the results of a complete query or only of its where clause. These functions
can be activated through the Sadas start server parameters. The stored queries refer to database
level
.
Information saved by Sadas include:
the original query source;
the result (query or filter);
the number of times memorized results have been subsequently used;
the date of usage of query result.
.
Use the DELETE STORED QUERIES statement to remove
Unused results;
All results;
Unused results and related queries;
All results and related queries;
Prerequisites
The DELETE STORED QUERIES function requires the LOAD privilege on the database.
Syntax
<delete_stored_queries> ::=
DELETE STORED QUERIES [ALL]
[ '<' <times> | '<' <date> | '=' <hash>]
delete_stored_queries::=
=
hash
<
date
<
times
ALL
DELETE
© 2014 Advanced Systems srl
STORED
QUERIES
SQL STATEMENTS
211
Semantics
ALL
If you specify ALL, Sadas will delete base queries and results. If you do not specify ALL, Sadas
will delete only results
times
Specify the number of times that a single stored query result has been used. If you specify <
times, Sadas will delete results (and base queries if you have specified ALL) being used less
than specified number.
date
Specify the date that a single stored query result has been used. If you specify < date, Sadas
will delete results (and base queries if you have specified ALL) being used before than specified
date.
hash
Specify the hash code of a single stored query result. If you specify = hash, Sadas will delete
results (and base queries if you have specified ALL) of the query that have this hash code.
Examples
DELETE STORED QUERIES;
DELETE STORED QUERIES < 50;
DELETE STORED QUERIES = 507392927629;
9.23
DELETE TABLE
Purpose
Use the DELETE statement to remove rows from a table. If you specify the CASCADE clause,
Sadas delete records from all tables having a corresponding foreign key.
© 2014 Advanced Systems srl
SQL STATEMENTS
212
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the DELETE TABLE process. While executing this process, Sadas stops all others requests.
Prerequisites
This function requires that the table belongs to the schema/database currently connected and
that user has the LOAD privilege on the table.
Syntax
<delete_table>::= DELETE
[FROM]
table_name
[
WHERE
<conditions>
]
[ CASCADE ]
delete_table::=
Semantics
schema
Specify the schema/database containing the table. If you omit schema, then Sadas assumes the
table is in the schema/database currently connected.
table_name
Specify the name of a table from which the rows are to be deleted. The name can be up to 128
bytes long and can contain only ASCII characters. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
© 2014 Advanced Systems srl
SQL STATEMENTS
213
where_clause
Use the where_clause to delete only rows that satisfy the conditions. The conditions can
reference the table from which you are deleting and can contain a scalar subquery.
If you omit the where_clause, then Sadas deletes all rows of the table.
Examples
DELETE LINEITEM;
DELETE FROM LINEITEM WHERE L_QUANTITY=50;
9.24
DELETE KEYS
Purpose
Use the DELETE KEYS statement to remove rows from a table corresponding to a list of primary
keys. If you specify the CASCADE clause, Sadas delete records from all tables having a
corresponding foreign key. Sadas loads the list of primary keys from an input file. If you don’t
specify this file, Sadas loads it from catalog CTL. The format of keys must be specified on
catalog CTL.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the DELETE KEYS process. While executing this process, Sadas stops all others requests.
Prerequisites
This function requires that the table belongs to the schema/database currently connected and
that user has the LOAD privilege on the table.
Syntax
<delete_keys>::=
delete_keys::=
© 2014 Advanced Systems srl
DELETE KEYS FROM table_name
['@' file_name] [CASCADE]
SQL STATEMENTS
214
Semantics
schema
Specify the schema/database containing the table. If you omit schema, then Sadas assumes the
table is in the schema/database currently connected.
table_name
Specify the name of a table from which the rows are to be deleted. The name can be up to 128
bytes long and can contain only ASCII characters. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
file_name
Specify the name of the input file. The file name must be complete, with absolute path.
Examples
DELETE KEYS FROM LINEITEM;
DELETE KEYS FROM LINEITEM CASCADE;
DELETE KEYS FROM LINEITEM@C:\KeysList.txt;
DELETE KEYS FROM LINEITEM@C:\KeysList.txt CASCADE;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.25
215
DESCRIBE TABLE
Purpose
Use the DESCRIBE TABLE statement to obtain following table information:
Catalog structure of the table.
Statistics (if the table has been loaded with more than 0 records).
Shadow table.
The catalog structure of the table is the result of the CREATE TABLE statement.
The table statistics are automatically calculated by Sadas Loader.
When the structure of a loaded table is modified the changes to the table are not immediately
available, but
Sadas creates a copy of catalog structure of the table (shadow table) or view or synonym: this
allows to query the table with the old data (consistent with old table structure) and, on new
loading process, the shadow table will substitute the catalog structure of the table. If the
structure of a table does not change, the shadow table will not exist.
Prerequisites
To see the structure of a table, you must have the DESC privilege on that table.
Syntax
<describe>
::=
table_name)
describe_table::=
© 2014 Advanced Systems srl
DESC [ |
DESCR
|
DESCRIBE]
[SHADOW
|
INFO]
table_name
(,
SQL STATEMENTS
216
Semantics
SHADOW
Use SHADOW to see shadow table structure, if existing.
INFO
Use INFO to see the statistic information of a table, if table has been loaded (more than 0
records)
table_name
Specify the name of a table for which information is required. The name can be up to 128 bytes
long and can contain only ASCII characters. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
DESC ORDERS;
DESC SHADOW LINEITEM;
DESC LINEITEM,ORDERS;
For each field of each table selected Sadas displays:
[Table, Identifier, Name, Type, Length, Decimals, Key, External Key, External Key,
Prg, External Table, External Field, Modify Field, Virtual Field, Default Value,
Comment]
© 2014 Advanced Systems srl
SQL STATEMENTS
217
DESC INFO ORDERS;
DESC INFO LINEITEM,ORDERS;
For each field of each table selected Sadas displays:
[Table, ID Name, Name, Type, Length, Minimum, Maximum, Average, Min String, Max
String, Distinct values, Sum, Field State, Variance, Deviance, Error Log, Index,
Compressed]
9.26
DESCRIBE STORED QUERIES
Purpose
Use the DESCRIBE STORED QUERIES statement to obtain the list of query with memorized
result. This list will also provide statistics on the subsequent use of stored results for each
query.
Prerequisites
To see the list of query with memorized result, you must have the DESC privilege on schema/
database.
Syntax
<describe>
::=
DESC
[
|
DESCR
|
DESCRIBE]
STORED
QUERIES
['<'|'>'
<times>|<date>]
describe_stored_queries::=
<
date
<
times
>
date
>
times
DESC
DESCR
STORED
QUERIES
DESCRIBE
© 2014 Advanced Systems srl
SQL STATEMENTS
218
Semantics
times
Specify the number of times that a single stored query result has been used. If you specify <
times, Sadas will show queries used less than specified number.
date
Specify the date that a single stored query result has been used. If you specify < date, Sadas
will show queries used before than specified date.
Example
DESC STORED QUERIES;
Sadas displays:
[Hash, Runs, Max Elapsed, First Run, Last Run]
9.27
DESCRIBE SYSALLCOLUMNS
Purpose
Use the DESCRIBE SYSALLCOLUMNS statement to obtain the list of all columns of all tables
created in the current schema/database.
Prerequisites
This function requires the DESC privilege on schema/database.
Syntax
<describe>
::=
DESC [ | DESCR | DESCRIBE] SYSALLCOLUMNS
describe_sysalcolumns::=
© 2014 Advanced Systems srl
SQL STATEMENTS
219
DESC
DESCR
SYSALLCOLUMNS
DESCRIBE
Examples
DESC SYSALLCOLUMNS;
For each column, Sadas displays:
[Table, Identifier, Name, Type, Length, Decimals, Key, External Key, External Key Prg,
External Table, External Field, Modify Field, Virtual Field, Default Value, Comment]
9.28
DESCRIBE SYSDB
Purpose
Use the DESCRIBE SYSDB statement to obtain the details of creation and usage of each
database installed on a Sadas server.
Prerequisites
This function requires the access to the Sadas server through the SYSDBA userid.
Syntax
<describe>
::=
describe_sysdb::=
© 2014 Advanced Systems srl
DESC [ | DESCR | DESCRIBE] SYSDB
SQL STATEMENTS
220
Examples
DESC SYSDB;
For each installed database Sadas displays:
[Identifier, Name, Creation Date, Creation Time, Last User, Last Client, Connection,
Queries, Last Date, Last Time, First Date, First Time, File Path]
9.29
DESCRIBE SYSDOMAINS
Purpose
Use the DESCRIBE SYSDOMAINS statement to obtain the list of defined domains for a database
on a Sadas server.
Prerequisites
This function requires the access to the Sadas server through the SYSDBA userid.
Syntax
<describe>
::=
DESC [ | DESCR | DESCRIBE] SYSDOMAINS
describe_sysdomains::=
Examples
DESC SYSDOMAINS;
© 2014 Advanced Systems srl
SQL STATEMENTS
221
For each domain, Sadas displays:
[Domain, Id]
9.30
DESCRIBE SYSFOREIGNKEYS
Purpose
Use the DESCRIBE SYSFOREIGNKEYS statement to obtain the list of all defined foreign keys in
current schema/database.
Prerequisites
Syntax
<describe>
::=
DESC [ | DESCR | DESCRIBE] SYSFOREIGNKEYS
describe_sysforeingkeys::=
Examples
DESC SYSFOREIGNKEYS;
Sadas displays:
[Table, Field, Link Table, Foreign Key]
9.31
DESCRIBE SYSKEYS
Purpose
Use the DESCRIBE SYSKEYS statement to obtain the list of all defined primary keys in current
© 2014 Advanced Systems srl
SQL STATEMENTS
222
schema/database.
Prerequisites
This function requires the DESC privilege on schema/database.
Syntax
<describe>
::=
DESC [ | DESCR | DESCRIBE] SYSKEYS
describe_syskeys::=
Examples
DESC SYSKEYS;
Sadas displays:
[Table, Fieldnum, Key]
9.32
DESCRIBE SYSLOG
Purpose
Use the DESCRIBE SYSLOG statement to obtain the list of all queries that the Sadas server has
executed since initial start.
Prerequisites
© 2014 Advanced Systems srl
SQL STATEMENTS
223
This function requires the DESC privilege on schema/database.
Syntax
<describe>
::=
DESC [ | DESCR | DESCRIBE] SYSLOG
describe_syslog::=
Examples
DESC SYSLOG;
For each query executed, Sadas displays:
[Date, Time, IP Address, User, Database, Elapsed, Hash, SQL, Client]
9.33
DESCRIBE SYSOBJECTS
Purpose
Use the DESCRIBE SYSOBJECTS statement to obtain the list of all objects (tables and views)
created in the current schema/database.
Prerequisites
This function requires the DESC privilege on schema/database.
Syntax
<describe>
© 2014 Advanced Systems srl
::=
DESC [ | DESCR | DESCRIBE] SYSOBJECTS
SQL STATEMENTS
224
describe_sysobjects::=
Examples
DESC SYSOBJECTS;
For each object, Sadas displays:
[Identifier, Name, State, Creation Date, Change Date, Flag Shadow, Id Shadow, Loading
Date, Loading Time, Author, Records, Loading Elapsed Time, Input Type, Loading Type,
Source File, Alias, Record Length, Delimiter, Input File Date, Input File Time,
Errors, Records not read, Duplicate Keys, Last Loading Type, Temporary, From Select,
View, Materialized, Processed Records, File Path, Text Qualifier, Comment, Compatible
Server, Synonym, Synonym DataBase Source, Synonym Table Source]
9.34
DESCRIBE SYSSYNONYMS
Purpose
Use the DESCRIBE SYSSYNONYMS statement to obtain the list of all synonyms created in the
current schema/database.
Prerequisites
This function requires the DESC privilege on schema/database.
Syntax
<describe>
© 2014 Advanced Systems srl
::=
DESC [ | DESCR | DESCRIBE] SYSSYNONYMS
SQL STATEMENTS
225
describe_syssynonyms::=
DESC
DESCR
SYSSYNONYMS
DESCRIBE
Examples
DESC SYSSYNONYMS;
For each synonym, Sadas displays:
[Identifier, Name, State, Creation Date, Change Date, Flag Shadow, Id Shadow, Loading
Date, Loading Time, Author, Records, Loading Elapsed Time, Input Type, Loading Type,
Source File, Alias, Record Length, Delimiter, Input File Date, Input File Time,
Errors, Records not read, Duplicate Keys, Last Loading Type, Temporary, From Select,
View, Materialized, Processed Records, File Path, Text Qualifier, Comment, Compatible
Server, Synonym, Synonym DataBase Source, Synonym Table Source]
9.35
DESCRIBE SYSTABLES
Purpose
Use the DESCRIBE SYSTABLES statement to obtain the list of all tables created in the current
schema/database.
Prerequisites
This function requires the DESC privilege on schema/database.
Syntax
<describe>
::=
DESC [ | DESCR | DESCRIBE] SYSTABLES
describe_systables::=
© 2014 Advanced Systems srl
SQL STATEMENTS
226
Examples
DESC SYSTABLES;
For each table, Sadas displays:
[Identifier, Name, State, Creation Date, Change Date, Flag Shadow, Id Shadow, Loading
Date, Loading Time, Author, Records, Loading Elapsed Time, Input Type, Loading Type,
Source File, Alias, Record Length, Delimiter, Input File Date, Input File Time,
Errors, Records not read, Duplicate Keys, Last Loading Type, Temporary, From Select,
View, Materialized, Processed Records, File Path, Text Qualifier, Comment, Compatible
Server, Synonym, Synonym DataBase Source, Synonym Table Source]
9.36
DESCRIBE SYSUSERS
Purpose
Use the DESCRIBE SYSUSERS statement to obtain the list of all users created in the current
schema/database. If you specify the domain_name, you obtain the list of users belonging to the
specified domain.
Prerequisites
This function requires the DESC privilege on schema/database.
Syntax
<describe>
© 2014 Advanced Systems srl
::=
DESC [ | DESCR | DESCRIBE] SYSUSERS [ @ domain_name]
SQL STATEMENTS
227
describe_sysusers::=
Semantics
domain_name
Specify the name of the domain.
Examples
DESC SYSUSERS;
For each user, Sadas displays:
[Name, Description, Role, Creation Date, Change Date, Expiration Date, Pwd Expiration
Date, Pwd Life Time]
9.37
DESCRIBE SYSVIEWS
Purpose
Use the DESCRIBE SYSVIEWS statement to obtain the list of all views created in the current
schema/database.
Prerequisites
This function requires the DESC privilege on schema/database.
Syntax
<describe>
::=
DESC [ | DESCR | DESCRIBE] SYSVIEWS
describe_sysviews::=
© 2014 Advanced Systems srl
SQL STATEMENTS
228
Examples
DESC SYSVIEWS;
For each view, Sadas displays:
[Identifier, Name, State, Creation Date, Change Date, Flag Shadow, Id Shadow, Loading
Date, Loading Time, Author, Records, Loading Elapsed Time, Input Type, Loading Type,
Source File, Alias, Record Length, Delimiter, Input File Date, Input File Time,
Errors, Records not read, Duplicate Keys, Last Loading Type, Temporary, From Select,
View, Materialized, Processed Records, File Path, Text Qualifier, Comment, Compatible
Server, Synonym, Synonym DataBase Source, Synonym Table Source]
9.38
DESCRIBE USER
Purpose
Use the DESCRIBE USER statement to obtain the details of the user’s privileges for each table
of current schema/database.
Prerequisites
This function requires the DESC privilege on schema/database.
Syntax
<describe>
::=
describe_user::=
© 2014 Advanced Systems srl
DESC [ | DESCR | DESCRIBE] USER user_name
SQL STATEMENTS
229
Semantics
user_name
Specify the name of the user..
Examples
DESC USER smith;
Sadas displays:
[Name, Table, Rule, Creation Date, Change Date, Expiration Date, Conditions]
9.39
DISABLE INDEXGBY
Purpose
Sadas uses two base algorithms for grouping queries: static hash group by (with use of indexes)
and sort group by. Use the DISABLE INDEXGBY statement to disable use of indexes in group by
queries. This is a functionality for performance tests. The Sadas server will usually start all
databases with indexes enabled by default.
Prerequisites
The DISABLE INDEXGBY statement is allowed only to SYSDBA user.
Syntax
<disable_index>
© 2014 Advanced Systems srl
::=
DISABLE INDEXGBY
SQL STATEMENTS
230
disable_indexgby::=
Examples
DISABLE INDEXGBY;
9.40
DISCONNECT
Purpose
Use the DISCONNECT command to end the current session and to disconnect from the current
database.
Syntax
<disconnect>
::=
DISCONNECT | DISC
disconnect::=
Examples
DISCONNECT;
9.41
DROP DATABASE
Purpose
Use the DROP DATABASE statement to drop a database (in Sadas database and schema have the
same meaning). When dropping a database, you definitively eliminate all data loaded and all
© 2014 Advanced Systems srl
SQL STATEMENTS
231
catalog informations. This statement is useful when you want to drop a test database or drop an
old database after successful migration to a new host.
Prerequisites
Only SYSDBA user can drop a database.
Syntax
<drop_database>
::=
DROP DATABASE db_name
drop_database::=
Semantics
db_name
Specify the name of the database to drop. The database name is case insensitive and is stored
in uppercase ASCII characters. If you specify the database name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
DROP DATABASE DB_DEMO;
9.42
DROP DOMAIN
Purpose
Use the DROP DOMAIN statement to remove a domain of users.
Prerequisites
Only SYSDBA user can drop a domain of users.
Syntax
<drop_domain>
© 2014 Advanced Systems srl
::=
DROP USER domain_name
SQL STATEMENTS
232
drop_domain::=
DROP
DOMAIN
domain_name
Semantics
domain_name
Specify the name of the domain. The domain name is case insensitive and is stored in
uppercase ASCII characters.
Examples
DROP DOMAIN DEMO_DOMAIN;
9.43
DROP EXPRESSION
Purpose
Use the DROP EXPRESSION statement to drop an expression in a table or in all tables of
database.
Prerequisites
To drop an expression on a table, you must have the CATALOG system privilege on the
database.
Syntax
<drop_expression>
::=DROP EXPRESSION expr_name ON [ TABLE table_name | ALL ]
drop_expression::=
table_name
TABLE
DROP
EXPRESSION
expr_name
ON
ALL
Semantics
© 2014 Advanced Systems srl
SQL STATEMENTS
233
expr_name
Specify the name of the expression. The name can be up to 128 bytes long and can contain only
ASCII characters. The expression name is case insensitive and is stored in uppercase ASCII
characters. If you specify the expression name as a quoted identifier, then the quotation marks
are silently ignored.
table_name
Name of table on which Sadas will create the expression. The name can be up to 128 bytes
long and can contain only ASCII characters. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
ALL
Specify ALL if you want to drop expr_name in all tables of current database.
Example
DROP EXPRESSION MYEXPR ON TABLE SUPPLIER
DROP EXPRESSION MYEXPR ON ALL
9.44
DROP EXPRESSIONS
Purpose
Use the DROP EXPRESSIONS statement to drop all expressions in a table or in a database.
Prerequisites
To drop expressions on a table or on a database, you must have the CATALOG system privilege
on the database.
Syntax
<drop_expressions>
drop_expressions::=
© 2014 Advanced Systems srl
::=DROP EXPRESSIONS ON [ TABLE table_name | ALL ]
SQL STATEMENTS
234
table_name
TABLE
DROP
EXPRESSIONS
ON
ALL
Semantics
table_name
Name of table on which Sadas will create the expression. The name can be up to 128 bytes
long and can contain only ASCII characters. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
ALL
Specify ALL if you want to drop expr_name in all tables of current database.
Example
DROP EXPRESSIONS ON TABLE SUPPLIER
DROP EXPRESSIONS ON ALL
9.45
DROP GENERATED COLUMNS
Purpose
Use the DROP GENERATED COLUMNS statement to drop fields generated automatically by Sadas.
Sadas generates automatically fields fo:
- multiple join, when join-keys are composed by more than one field;
- join with expression, when join-keys are composed by expressions.
Prerequisites
To drop generated columns on a table or on a database, you must have the CATALOG system
privilege on the database.
Syntax
© 2014 Advanced Systems srl
SQL STATEMENTS
235
<drop_generated_columns>
::=DROP GENERATED COLUMNS ON [ TABLE table_name | ALL ]
drop_generated_columns::=
table_name
TABLE
DROP
GENERATED
COLUMNS
ON
ALL
Semantics
table_name
Name of table on which Sadas will create the expression. The name can be up to 128 bytes
long and can contain only ASCII characters. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
ALL
Specify ALL if you want to drop expr_name in all tables of current database.
Example
DROP GENERATED COLUMNS ON TABLE SUPPLIER
DROP GENERATED COLUMNS ON ALL
9.46
DROP INDEX
Purpose
Use the DROP INDEX statement to drop an index on a column of a table.
Prerequisites
To drop an index on a column of a table, you must have the CATALOG system privilege on the
database.
Syntax
© 2014 Advanced Systems srl
SQL STATEMENTS
<drop_index>
236
::= DROP INDEX table_name.col_name
drop_index::=
DROP
table_name
INDEX
.
col_name
Semantics
col_name
Specify the name of the column. The name can be up to 128 bytes long and can contain only
ASCII characters. The expression name is case insensitive and is stored in uppercase ASCII
characters. If you specify the expression name as a quoted identifier, then the quotation marks
are silently ignored.
table_name
Name of table on which Sadas will create the expression. The name can be up to 128 bytes
long and can contain only ASCII characters. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
DROP INDEX PRODUCT.COLORPR
9.47
DROP SYNONYM
Purpose
Use the DROP SYNONYM statement to remove a synonym from the database or to change the
definition of a synonym by dropping and re-creating it.
Prerequisites
To drop a synonym you must be a SYSDBA.
Syntax
<drop_synonym>
© 2014 Advanced Systems srl
::=
DROP SYNONYM synonym
SQL STATEMENTS
237
drop_synonym::=
Semantics
synonym
Specify the name of the synonym to drop. The synonym name is case insensitive and is stored
in uppercase ASCII characters. If you specify the synonym name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
DROP SYNONYM SYNONYM_DEMO;
9.48
DROP TABLE
Purpose
Use the DROP TABLE statement to definitively remove the table and all its data from the
database .
Prerequisites
The table must be in current schema/database and you must have the CATALOG system
privilege.
Syntax
<drop_table>
drop_table::=
© 2014 Advanced Systems srl
::=
DROP TABLE table
SQL STATEMENTS
238
Semantics
table
Specify the name of the table to drop. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
DROP TABLE TABLE_DEMO;
9.49
DROP USER
Purpose
Use the DROP USER statement to remove a database user.
Prerequisites
The user must be in current schema/database and you must have the SECURITY system
privilege.
Syntax
<drop_user>
::=
DROP USER user
drop_user::=
Semantics
user
Specify the name of the user. The user name is case insensitive and is stored in uppercase
ASCII characters. If you specify the user name as a quoted identifier, then the quotation marks
© 2014 Advanced Systems srl
SQL STATEMENTS
239
are silently ignored.
Examples
DROP USER SMITH;
9.50
DROP VIEW
Purpose
Use the DROP VIEW statement to definitively remove a view and all its data from the database .
In Sadas a view always has its own data.
Prerequisites
The view must be in current schema/database and you must have the CATALOG system
privilege.
Syntax
<drop_view>
::=
DROP VIEW view
drop_view::=
Semantics
view
Specify the name of the view. The view name is case insensitive and is stored in uppercase
ASCII characters. If you specify the view name as a quoted identifier, then the quotation marks
are silently ignored.
Examples
DROP VIEW VIEW_DEMO;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.51
240
DUPLICATE DATABASE
Purpose
Use the DUPLICATE DATABASE statement to duplicate an entire database structure, without
reloading existing data.
For the new database you can specify the database storage path, i.e. the path of database data.
For the new database you can also specify the internal db_ID, which is an internal parameter
used by Sadas as:
unique key which identify the database on a Sadas server;
sub-path name of catalog information in the system catalog path;
sub-path name of data information in the database storage path.
Prerequisites
Only SYSDBA user can duplicate a database.
Syntax
<duplicate_database>::=DUPLICATE DATABASE db_name TO new_db_name [':' new_db_Id] ['@'
storage_path ]
duplicate_database::=
Semantics
db_name
Specify the name of the database to be duplicated. The database name is case insensitive and is
stored in uppercase ASCII characters. If you specify the database name as a quoted identifier,
then the quotation marks are silently ignored.
new_db_name
© 2014 Advanced Systems srl
SQL STATEMENTS
241
Specify the name of the new database to be created. The new database name is case insensitive
and is stored in uppercase ASCII characters. If you specify the database name as a quoted
identifier, then the quotation marks are silently ignored.
new_db_Id
Specify the internal db_Id of the new database duplicated. The internal db_Id must have fixed
length of 10 bytes. The db_Id is case insensitive and is stored in uppercase ASCII characters. If
you specify the database id as a quoted identifier, then the quotation marks are silently ignored.
storage_path
Specify the storage path of the new database duplicated. If the specified path does not exist,
Sadas will create it. The storage path refers to the data files of the database, while the catalog
files are written in the System Catalog Path. The storage path can be also a shared network
drive.
Examples
DUPLICATE DATABASE DBSAMPLE TO DBSAMPLE2;
DUPLICATE DATABASE DBSAMPLE TO DBSAMPLE2:DBSAMPLE00;
DUPLICATE DATABASE DBSAMPLE TO DBSAMPLE2@C:\_TEMP;
DUPLICATE DATABASE DBSAMPLE TO DBSAMPLE2:DBSAMPLE00@C:\_TEMP;
9.52
DUPLICATE TABLE
Purpose
Use the DUPLICATE TABLE statement to duplicate a table structure without reloading existing
data.
Prerequisites
The table must be in current schema/database and you must have the CATALOG system
privilege.
Syntax
<duplicate_table>
© 2014 Advanced Systems srl
::=
DUPLICATE TABLE table_name TO new_table_name
SQL STATEMENTS
242
['@' storage_path ]
duplicate_table::=
@
storage_path
Semantics
table_name
Specify the name of the table to be duplicated. The table name is case insensitive and is stored
in uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
new_table_name
Specify the name of the new table to be created. The new table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
storage_path
Specify the storage path of the new table duplicated. If the specified path does not exist, Sadas
will create it. The storage path refers to the data files of the table, while the catalog files are
written in the System Catalog Path. The storage path can be also a shared network drive.
Examples
DUPLICATE TABLE TBLDEMO TO NEWTBLDEMO;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.53
243
DUPLICATE USER
Purpose
Use the DUPLICATE USER statement to duplicate a user.
The new duplicated user inherits all privileges from parent user.
Prerequisites
You must have the SECURITY system privilege to duplicate a user.
Syntax
<duplicate_user>
::=
DUPLICATE USER user_name TO new_user_name
duplicate_user::=
Semantics
user_name
Specify the name of the user to be duplicated. The user name is case insensitive and is stored in
uppercase ASCII characters. If you specify the user name as a quoted identifier, then the
quotation marks are silently ignored.
new_user_name
Specify the name of the new user to be created. The user name is case insensitive and is stored
in uppercase ASCII characters. If you specify the user name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
DUPLICATE USER SMITH TO SMITHIE;
9.54
ENABLE INDEXGBY
Purpose
Sadas uses two base algorithms for grouping queries: static hash group by (with use of indexes)
and sort group by. Use the ENABLE INDEXGBY statement to enable use of indexes in group by
© 2014 Advanced Systems srl
SQL STATEMENTS
244
queries if they had been previously disabled. This is a functionality for performance tests. The
Sadas server will usually start all databases with indexes enabled by default.
Prerequisites
The ENABLE INDEXGBY statement is allowed only to SYSDBA user.
Syntax
<enable_index>
::=
ENABLE INDEXGBY
enable_indexgby::=
Examples
ENABLE INDEXGBY;
9.55
EXECUTE STORED QUERIES
Purpose
Use the EXECUTE STORED QUERIES statement to re-execute the queries with memorized result.
Sadas does not automatically recalculate these results, but you must use explicitly this
command.
In order to process only most frequently used or last queries, a minimum number of subsequent
executions ro a date can optionally be defined for filtering the queries.
Prerequisites
To recalculate the queries with memorized result, you must have the LOAD privilege on
schema/database.
Syntax
<execute>
© 2014 Advanced Systems srl
::=
EXEC | EXECUTE STORED QUERIES [ '>' <times>|
SQL STATEMENTS
245
<date> ]
execute_stored_queries::=
>
times
>
date
EXEC
STORED
QUERIES
EXECUTE
Examples
EXECUTE STORED QUERIES;
EXECUTE STORED QUERIES > 100;
Sadas displays:
[Refreshed requests, Elapsed time, Errors]
9.56
GRANT
Purpose
Use the GRANT statement to grant system and object privileges to users.
You can specify ALL to grant all privileges on table to a user or to grant privileges on all tables
of current schema/database to a user.
Prerequisites
To grant privileges to users you must have the SECURITY privilege on schema/database.
Syntax
<grant> ::= GRANT ALL | <privileges_list>
ON ( table_name | ALL ) TO ( user_name | domain_name )
grant::=
© 2014 Advanced Systems srl
SQL STATEMENTS
246
ALL
domain_name
TO
ON
table_name
user_name
<privileges_list> ::= PR_SELECT | PR_DESCRIBE | PR_CATALOG | PR_LOAD | PR_SECURITY
(','
PR_SELECT
|
PR_DESCRIBE
|
PR_CATALOG
|
PR_LOAD
|
PR_SECURITY )
privileges_list::=
Semantics
table_name
Specify the name of the table for grant operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
user_name
Specify the name of the user for grant operation. The user name is case insensitive and is stored
in uppercase ASCII characters. If you specify the user name as a quoted identifier, then the
quotation marks are silently ignored.
privileges_list
Specify the list of privileges to grant on the table (or entire database) to the user.
© 2014 Advanced Systems srl
SQL STATEMENTS
247
privilege
Specify the privilege to grant on the table (or entire database) to the user.
The list of privileges defined in Sadas is:
[PR_SELECT, PR_DESCRIBE, PR_CATALOG, PR_LOAD, PR_SECURITY]
Examples
GRANT PR_SECURITY ON LINEITEM TO SMITH;
GRANT PR_SECURITY ON ALL TO SMITH;
GRANT ALL ON LINEITEM TO SMITH;
GRANT ALL ON ALL TO SMITH;
9.57
INSERT
Purpose
Use the INSERT statement to insert records in a table in current database/schema using
VALUES
clause.
You can send multiple INSERT commands, but you cannot see the inserted records until
COMMIT
statement; after COMMIT statement SADAS really insert records on all tables used by
INSERT
statement. If you don't want to insert records, you can use ROLLBACK statement:
SADAS cancels all INSERT commands.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the INSERT TABLE process. While executing this process, Sadas stops all others requests.
Sadas uses the APPEND loading type.
If you don't specify column list, SADAS assumes list of columns of table as column list.
Prerequisites
To use the INSERT statement, you must have the LOAD privilege on schema/database.
Syntax
© 2014 Advanced Systems srl
SQL STATEMENTS
248
<insert>
::=
INSERT INTO table_name ['(' column_list ')'] VALUES '('
values_list ')'
insert::=
(
INSERT
VALUES
INTO
table_name
(
values_list
column_list
)
Semantics
table_name
Specify the name of the table for load operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
column_list
The column_list lets you define the list columns interested by insert command.
values_list
The values_list lets you define the list of values to insert.
Examples
insert into ttime values (99,99,99,99,99)
insert into ttime (timeidpk,year,month,week,day) values (99,99,99,99,99)
9.58
INSERT TABLE
Purpose
Use the INSERT TABLE statement to insert records in a table in current database/schema from
an input file or from a sub-query.
© 2014 Advanced Systems srl
)
SQL STATEMENTS
249
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the INSERT TABLE process. While executing this process, Sadas stops all others requests.
The input file structure must be consistent with CTL (Control Table Loader) specifics.
If input file name is not specified Sadas will use the file specified in the CTL.
If you specify DIRECT clause, Sadas will use memory buffer of file name area as a single
record to load.
If you specify ONLY clause, Sadas will load only n_rec records.
If you specify SKIP clause, Sadas will skip first n_rec records.
Sadas uses the APPEND loading type.
Prerequisites
To use the INSERT TABLE statement, you must have the LOAD privilege on schema/database.
Syntax
<insert_table1>
::=
INSERT TABLE table_name ['@' file_name]
[ DIRECT | ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
<insert_table2>
::=
INSERT TABLE table_name FROM '('<SubQuery>')'
insert_table1::=
@
INSERT
© 2014 Advanced Systems srl
TABLE
table_name
file_name
SQL STATEMENTS
250
insert_table2::=
INSERT
TABLE
table_name
FROM
SubQuery
Semantics
table_name
Specify the name of the table for load operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
file_name
Specify the name of the input file. The file name must be complete, with absolute path.
n_rec
Number of records to skip or to append.
subquery
Specify the data that Sadas loads. For each subquery Sadas creates a temporary table, which
will be deleted at the end of the query execution.
Examples
INSERT TABLE REGION;
© 2014 Advanced Systems srl
SQL STATEMENTS
251
INSERT TABLE REGION ONLY 100;
INSERT TABLE REGION SKIP 30;
INSERT TABLE REGION SKIP 30 ONLY 100;
INSERT TABLE REGION @ REGION.TBL;
INSERT TABLE REGION @ "0|AFRICA|special Tiresias about the furiously even
dolphins are furi|" DIRECT;
INSERT TABLE REGION FROM (SELECT * FROM REGION2);
9.59
INTERSECT
Purpose
Use the INTERSECT statement to intersect results of several queries.
There are limits on fields on the select statements (sub-query):
all corresponding fields must be of the same type;
also numeric fields must be of the same type: if you have an INTEGER [FLOAT] field, all
corresponding fields must be INTEGER [FLOAT];
if you have a code [pseudo-code] field, all corresponding fields must be of code
[pseudo-code] type, with the same decode table.
Prerequisites
To use the INTERSECT statement, you must have the SELECT privilege on schema/database.
Syntax
<intersect>::=(<select_statement> | <parenthesis>) (INTERSECT (<select_statement > |
<parenthesis>))
intersect::=
© 2014 Advanced Systems srl
SQL STATEMENTS
< parenthesis >
252
::=
select_statement> ->
‘(’ | ‘)’
see ‘SELECT’ chapter
Semantics
select_statement
Specify one of the statements for INTERSECT operation. For more details see the “SELECT”
chapter.
parenthesis
The select statements can be optionally in parenthesis.
Example
SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY > 10
INTERSECT
SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY < 15
N_NATIONKEY N_NAME N_REGIONKEY
-------------------------------11
IRAQ
4
12
JAPAN
2
13
JORDAN 4
14
KENYA
0
© 2014 Advanced Systems srl
SQL STATEMENTS
253
(SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY > 10)
INTERSECT
(SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY < 15)
9.60
LOAD COLUMNS
Purpose
Use the LOAD COLUMNS statement to reload only some columns of a table in current database/
schema from an input file.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the LOAD COLUMNS process. While executing this process, Sadas stops all others requests.
To use this statement the base table must be already loaded. To reload a column in a table, you
must have an input file according with CTL (Control Table Loader) specifics; if the input file
name is not specified in the statement Sadas will use the file specified in the CTL.
Prerequisites
To use the LOAD COLUMNS statement, you must have the LOAD privilege on schema/database.
Syntax
<load_columns>::= LOAD COLUMN <column_list> ON table_name [ '@' file_name ]
load_columns::=
column_list::=
© 2014 Advanced Systems srl
SQL STATEMENTS
254
Semantics
columns_list
Specify the list of columns for reload operation.
table_name
Specify the name of the table for reload operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
file_name
Specify the name of the input file. The file name must be complete, with absolute path.
Examples
LOAD COLUMN R_NAME ON REGION;
LOAD COLUMN R_NAME, R_COMMENT ON REGION @ REGION.TBL;
9.61
LOAD DATABASE
Purpose
Use the LOAD DATABASE statement to load an entire database/schema.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the LOAD DATABASE process. While executing this process, Sadas stops all others requests.
© 2014 Advanced Systems srl
SQL STATEMENTS
255
Sadas uses the CTL (Control Table Loader) file of each table for this operation so correct
specifications must have been previously defined into all CTL files. .
Prerequisites
Only SYSDBA user can use the LOAD DATABASE statement.
Syntax
<load_database>
::=
LOAD DATABASE db_name
load_database::=
Semantics
db_name
Name of schema/database to load. The name can be up to 128 bytes long and can contain only
ASCII characters. The database name is case insensitive and is stored in uppercase ASCII
characters. If you specify the database name as a quoted identifier, then the quotation marks
are silently ignored.
Examples
LOAD DATABASE TPCH;
9.62
LOAD TABLE
Purpose
Use the LOAD TABLE statement to load a table in current database/schema from an input file
or from a sub-query.
© 2014 Advanced Systems srl
SQL STATEMENTS
256
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the LOAD TABLE process. While executing this process, Sadas stops all others requests.
The input file structure must be consistent with CTL (Control Table Loader) specifics.
If input file name is not specified Sadas will use the file specified in the CTL.
If you specify DIRECT clause, Sadas will use memory buffer of file name area as a single
record to load.
If you specify ONLY clause, Sadas will load only n_rec records.
If you specify SKIP clause, Sadas will skip first n_rec records.
Sadas uses the loading type specified in the CTL:
- REWRITE
- APPEND
- UPDATE
Prerequisites
To use the LOAD TABLE statement, you must have the LOAD privilege on schema/database.
Syntax
<load_table1>
::=
LOAD TABLE table_name ['@' file_name]
[ DIRECT | ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
<load_table2>
load_table1::=
© 2014 Advanced Systems srl
::=
LOAD TABLE table_name FROM '('<SubQuery>')'
SQL STATEMENTS
257
load_table2::=
LOAD
TABLE
table_name
FROM
SubQuery
Semantics
table_name
Specify the name of the table for load operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
file_name
Specify the name of the input file. The file name must be complete, with absolute path.
n_rec
Number of records to skip or to append.
subquery
Specify the data that Sadas loads. For each subquery Sadas creates a temporary table, which
will be deleted at the end of the query execution.
Examples
LOAD TABLE REGION;
© 2014 Advanced Systems srl
SQL STATEMENTS
258
LOAD TABLE REGION ONLY 100;
LOAD TABLE REGION SKIP 30;
LOAD TABLE REGION SKIP 30 ONLY 100;
LOAD TABLE REGION @ REGION.TBL;
LOAD TABLE REGION @ "0|AFRICA|special Tiresias about the furiously even
dolphins are furi|" DIRECT;
LOAD TABLE REGION FROM (SELECT * FROM REGION2);
9.63
LOCK TABLE
Purpose
Use the LOCK TABLE statement to lock a table of the current database. Table locked cannot
read/write by other users.
Prerequisites
Only a SYSDBA can lock a table.
Syntax
<lock_table>
::=
LOCK TABLE table_name
lock_table::=
LOCK
TABLE
table_name
Semantics
table_name
Specify the name of the table for load operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
© 2014 Advanced Systems srl
SQL STATEMENTS
259
Examples
LOCK TABLE CUSTOMER;
9.64
LOCK USER
Purpose
Use the LOCK USER statement to lock a database user. User locked cannot login to the current
database.
Prerequisites
The user must be in current schema/database and you must have the SECURITY system
privilege.
Syntax
<lock_user>
::=
LOCK USER user
lock_user::=
Semantics
user
Specify the name of the user. The user name is case insensitive and is stored in uppercase
ASCII characters. If you specify the user name as a quoted identifier, then the quotation marks
are silently ignored.
Examples
LOCK USER SMITH;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.65
260
MINUS
Purpose
Use the MINUS statement to subtract the result of a query from another query result. If you have
several queries the subtract operation is done from right to left.
There are limits on fields of the select statements (sub-query):
all corresponding fields must be of the same type;
also numeric fields must be of the same type: if you have an INTEGER [FLOAT] field, all
corresponding fields must be INTEGER [FLOAT];
if you have a code [pseudo-code] field, all corresponding fields must be of code
[pseudo-code] type, with the same decode table.
Prerequisites
To use the MINUS statement, you must have the SELECT privilege on schema/database.
Syntax
<minus>::=(<select_statement>
|
<parenthesis>)
<parenthesis>))
minus::=
< parenthesis >
© 2014 Advanced Systems srl
::=
‘(’ | ‘)’
(MINUS
(<select_statement
>
|
SQL STATEMENTS
select_statement> ->
261
see ‘SELECT’ chapter
Semantics
select_statement
Specify one of the statements for INTERSECT operation. For more details see the “SELECT”
chapter.
parenthesis
The select statements can be optionally in parenthesis.
Example
SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY <= 15
MINUS
SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY <= 10
N_NATIONKEY N_NAME N_REGIONKEY
-------------------------------11
IRAQ
4
12
JAPAN
2
13
JORDAN 4
14
KENYA
0
(SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY > 10)
MINUS
(SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY < 15)
9.66
RENAME COLUMN
Purpose
© 2014 Advanced Systems srl
SQL STATEMENTS
262
Use the RENAME COLUMN statement to rename a column in a table.
Prerequisites
The table containing the column must be in current schema/database and you must have the
CATALOG
system privilege.
Syntax
<rename_column>
::=
RENAME
COLUMN
col_name
TO
new_col_name
ON
table_name
rename_column::=
RENAME
col_name
COLUMN
ON
TO
new_col_name
table_name
Semantics
col_name
Specify the name of the column to rename. The column name is case insensitive and is stored
in uppercase ASCII characters. If you specify the column name as a quoted identifier, then the
quotation marks are silently ignored.
new_col_name
Specify the new name of the column to rename. The column name is case insensitive and is
stored in uppercase ASCII characters. If you specify the column name as a quoted identifier,
then the quotation marks are silently ignored.
table_name
Specify the name of the table that contains the column to rename. The table name is case
insensitive and is stored in uppercase ASCII characters. If you specify the table name as a
quoted identifier, then the quotation marks are silently ignored.
© 2014 Advanced Systems srl
SQL STATEMENTS
263
Examples
RENAME COLUMN COLORPR TO COLOR ON PRODUCT;
9.67
RENAME DATABASE
Purpose
Use the RENAME DATABASE statement to rename a database.
For the new database you can also specify the internal db_ID, which is an internal parameter
used by Sadas as:
unique key which identify the database on a Sadas server;
sub-path name of catalog information in the system catalog path;
sub-path name of data information in the database storage path.
Prerequisites
Only SYSDBA user can rename a database.
Syntax
<rename_database> ::=
RENAME
DATABASE
db_name
TO
new_db_name
[':'
new_db_Id]
rename_database::=
Semantics
db_name
Specify the name of the database to rename. The database name is case insensitive and is
stored in uppercase ASCII characters. If you specify the database name as a quoted identifier,
© 2014 Advanced Systems srl
SQL STATEMENTS
264
then the quotation marks are silently ignored.
new_db_name
Specify the new name of the renamed database. The new database name is case insensitive and
is stored in uppercase ASCII characters. If you specify the database name as a quoted identifier,
then the quotation marks are silently ignored.
new_db_Id
Specify the internal db_Id of the new renamed database. The internal db_Id must have fixed
length of 10 bytes. The db_Id is case insensitive and is stored in uppercase ASCII characters. If
you specify the database name as a quoted identifier, then the quotation marks are silently
ignored.
Examples
RENAME DATABASE DBSAMPLE TO DBSAMPLE2;
RENAME DATABASE DBSAMPLE TO DBSAMPLE2:DBSAMPLE00;
9.68
RENAME DOMAIN
Purpose
Use the RENAME DOMAIN statement to rename a domain.
Prerequisites
Only SYSDBA user can rename a domain.
Syntax
<rename_domain>
::=
RENAME DOMAIN domain_name TO new_domain_name
rename_domain::=
RENAME
© 2014 Advanced Systems srl
DOMAIN
domain_name
TO
new_domain_name
SQL STATEMENTS
265
Semantics
domain_name
Specify the name of the domain to rename. The domain name is case insensitive and is stored
in uppercase ASCII characters.
new_domain_name
Specify the new name of the domain renamed. The new domain name is case insensitive and is
stored in uppercase ASCII characters.
Examples
RENAME DOMAIN GRUPPOAS TO ADVSYS;
9.69
RENAME TABLE
Purpose
Use the RENAME TABLE statement to rename a table.
Prerequisites
The table must be in current schema/database and you must have the CATALOG system
privilege.
Syntax
<rename_table>
::=
RENAME TABLE table_name TO new_table_name
rename_table::=
Semantics
table_name
Specify the name of the table to rename. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
© 2014 Advanced Systems srl
SQL STATEMENTS
266
new_table_name
Specify the new name of the table renamed. The new table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
Examples
RENAME TABLE TBLDEMO TO NEWTBLDEMO;
9.70
RENAME VIEW
Purpose
Use the RENAME VIEW statement to rename a view.
Prerequisites
The view must be in current schema/database and you must have the CATALOG system
privilege.
Syntax
<rename_view>
::=
RENAME VIEW view_name TO new_view_name
rename_view::=
RENAME
VIEW
view_name
TO
new_view_name
Semantics
view_name
Specify the name of the view to rename. The view name is case insensitive and is stored in
uppercase ASCII characters. If you specify the view name as a quoted identifier, then the
quotation marks are silently ignored.
new_view_name
Specify the new name of the view renamed. The new view name is case insensitive and is
stored in uppercase ASCII characters. If you specify the view name as a quoted identifier, then
the quotation marks are silently ignored.
© 2014 Advanced Systems srl
SQL STATEMENTS
267
Examples
RENAME view VIEWDEMO TO NEWVIEWDEMO;
9.71
REPLICATE DATABASE
Purpose
Use the REPLICATE DATABASE statement to replicate an entire database , reloading existing
data.
For the new database you can specify the database storage path, i.e. the path of database data.
For the new database you can also specify the internal db_ID, which is an internal parameter
used by Sadas as:
unique key which identify the database on a Sadas server;
sub-path name of catalog information in the system catalog path;
sub-path name of data information in the database storage path.
Prerequisites
Only SYSDBA user can replicate a database.
Syntax
<replicate_database>::=REPLICATE DATABASE db_name TO new_db_name [':' new_db_Id] ['@'
storage_path ]
replicate_database::=
Semantics
db_name
Specify the name of the database to replicate. The database name is case insensitive and is
stored in uppercase ASCII characters. If you specify the database name as a quoted identifier,
© 2014 Advanced Systems srl
SQL STATEMENTS
268
then the quotation marks are silently ignored.
new_db_name
Specify the name of the new replicated database. The new database name is case insensitive
and is stored in uppercase ASCII characters. If you specify the database name as a quoted
identifier, then the quotation marks are silently ignored.
new_db_Id
Specify the internal db_Id of the new replicated database. The internal db_Id must have fixed
length of 10 bytes. The db_Id is case insensitive and is stored in uppercase ASCII characters. If
you specify the database name as a quoted identifier, then the quotation marks are silently
ignored.
storage_path
Specify the storage path of the new database replicated. If the specified path does not exist,
Sadas will create it. The storage path refers to the data files of the database, while the catalog
files are written in the System Catalog Path. The storage path can be also a shared network
drive.
Examples
REPLICATE DATABASE DBSAMPLE TO DBSAMPLE2;
REPLICATE DATABASE DBSAMPLE TO DBSAMPLE2:DBSAMPLE00;
REPLICATE DATABASE DBSAMPLE TO DBSAMPLE2@C:\_TEMP;
REPLICATE DATABASE DBSAMPLE TO DBSAMPLE2:DBSAMPLE00@C:\_TEMP;
9.72
REPLICATE TABLE
Purpose
Use the REPLICATE TABLE statement to replicate an entire table, reloading existing data.
Prerequisites
The table must be in current schema/database and you must have the CATALOG system
privilege.
© 2014 Advanced Systems srl
SQL STATEMENTS
269
Syntax
<replicate_table>
::=
REPLICATE TABLE table_name TO new_table_name
['@' storage_path ]
replicate_table::=
@
storage_path
Semantics
table_name
Specify the name of the table to be replicated. The table name is case insensitive and is stored
in uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
new_table_name
Specify the name of the new table to be created. The new table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
storage_path
Specify the storage path of the new table duplicated. If the specified path does not exist, Sadas
will create it. The storage path refers to the data files of the table, while the catalog files are
written in the System Catalog Path. The storage path can be also a shared network drive.
Examples
REPLICATE TABLE TBLDEMO TO NEWTBLDEMO;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.73
270
REVOKE
Purpose
Use the REVOKE statement to revoke system and object privileges from users.
You can specify ALL to revoke all privileges on table from user or to revoke privileges on all
tables of current schema/database from user.
Prerequisites
To revoke privileges to users you must have the SECURITY privilege on schema/database.
Syntax
<revoke> ::= REVOKE ALL | <privileges_list>
ON ( table_name | ALL ) FROM ( user_name | domain_name )
ALL
domain_name
FROM
ON
table_name
user_name
<privileges_list> ::= PR_SELECT | PR_DESCRIBE | PR_CATALOG | PR_LOAD | PR_SECURITY
(','
PR_SECURITY )
© 2014 Advanced Systems srl
PR_SELECT
|
PR_DESCRIBE
|
PR_CATALOG
|
PR_LOAD
|
SQL STATEMENTS
271
Semantics
table_name
Specify the name of the table for revoke operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
user_name
Specify the name of the user for revoke operation. The user name is case insensitive and is
stored in uppercase ASCII characters. If you specify the user name as a quoted identifier, then
the quotation marks are silently ignored.
privileges_list
Specify the list of privileges to revoke on table (or entire database) from user.
privilege
Specify the privilege to revoke on table (or entire database) from user.
This is the list of privileges defined in Sadas:
[PR_SELECT, PR_DESCRIBE, PR_CATALOG, PR_LOAD, PR_SECURITY]
Examples
REVOKE PR_SECURITY ON LINEITEM FROM SMITH;
REVOKE PR_SECURITY ON ALL FROM SMITH;
REVOKE ALL ON LINEITEM FROM SMITH;
REVOKE ALL ON ALL FROM SMITH;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.74
272
REWRITE DATABASE
Purpose
Use the REWRITE DATABASE statement to rewrite data of an entire database/schema.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the REWRITE DATABASE process. While executing this process, Sadas stops all others requests.
Sadas uses the CTL (Control Table Loader) file of each table for this operation so correct
specifications (except for LOADING TYPE) must have been previously defined into all CTL
files.
In this case the loading type is always " REWRITE" .
Prerequisites
Only SYSDBA user can use the REWRITE DATABASE statement.
Syntax
<rewrite_database>
::=
REWRITE DATABASE db_name
rewrite_database::=
REWRITE
DATABASE
db_name
Semantics
db_name
Name of schema/database to load. The name can be up to 128 bytes long and can contain only
ASCII characters. The database name is case insensitive and is stored in uppercase ASCII
characters. If you specify the database name as a quoted identifier, then the quotation marks
are silently ignored.
© 2014 Advanced Systems srl
SQL STATEMENTS
273
Examples
REWRITE DATABASE TPCH;
9.75
REWRITE TABLE
Purpose
Use the REWRITE TABLE statement to rewrite a table in current database/schema from an input
file or from a sub-query.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the REWRITE TABLE process. While executing this process, Sadas stops all others requests.
The input file structure must be consistent with CTL (Control Table Loader) specifics; if input
file name is not specified Sadas will use the file specified in the CTL.
If you specify DIRECT clause, Sadas will use memory buffer of file name area as a single
record to load.
If you specify ONLY clause, Sadas will load only n_rec records.
If you specify SKIP clause, Sadas will skip first n_rec records.
In this case the loading type is always "REWRITE" .
Prerequisites
To use the REWRITE TABLE statement, you must have the LOAD privilege on schema/
database.
Syntax
<rewrite_table1>
::=
REWRITE TABLE table_name ['@' file_name]
[ DIRECT | ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
<rewrite_table2>
© 2014 Advanced Systems srl
::=
REWRITE TABLE table_name FROM '('<SubQuery>')'
SQL STATEMENTS
274
rewrite_table1::=
@
REWRITE
TABLE
file_name
table_name
rewrite_table2::=
REWRITE
TABLE
table_name
FROM
SubQuery
Semantics
table_name
Specify the name of the table for load operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
file_name
Specify the name of the input file. The file name must be complete, with absolute path.
n_rec
Number of records to skip or to append.
subquery
Specify the data that Sadas loads. For each subquery Sadas creates a temporary table, which
© 2014 Advanced Systems srl
SQL STATEMENTS
275
will be deleted at the end of the query execution.
Examples
REWRITE TABLE REGION;
REWRITE TABLE REGION ONLY 100;
REWRITE TABLE REGION SKIP 30;
REWRITE TABLE REGION SKIP 30 ONLY 100;
REWRITE TABLE REGION @ REGION.TBL;
REWRITE TABLE REGION @ "0|AFRICA|special Tiresias about the furiously even
dolphins are furi|" DIRECT;
REWRITE TABLE REGION FROM (SELECT * FROM REGION2);
9.76
SELECT
Purpose
Use a SELECT statement or subquery to retrieve data from one or more tables and materialized
views.
Prerequisites
The table or materialized view must be in your own database/schema and you must have the
SELECT
privilege on the table or materialized view.
Syntax
<select> ::= SELECT [ALL | DISTINCT] <select_list> | *
FROM <table_list> | table_name <join_clause> table_name ON <join_condition> |
<SubQuery>
[ WHERE < conditions > ]
[ GROUP BY [ CUBE | ROLLUP ] <group_by_list> | DISTRIBUTE [BY] <columns_list> ON
'('<parameters_list>')
[ HAVING < conditions > ] ]
[ ORDER BY <order_by_list> ]
© 2014 Advanced Systems srl
SQL STATEMENTS
select::=
subquery::=
query_block::=
© 2014 Advanced Systems srl
276
SQL STATEMENTS
select_list::=
table_reference::=
© 2014 Advanced Systems srl
277
SQL STATEMENTS
join_clause::=
inner_join_clause::=
star_join_clause::=
© 2014 Advanced Systems srl
278
SQL STATEMENTS
279
star_join_type::=
outer_join_clause::=
outer_join_type::=
FULL
LEFT
RIGHT
LEFTNULL
RIGHTNULL
© 2014 Advanced Systems srl
OUTER
SQL STATEMENTS
where_clause::=
group_by_clause::=
rollup_cube_clause::=
grouping_expression_list::=
expression_list::=
© 2014 Advanced Systems srl
280
SQL STATEMENTS
distribute_by_clause::=
distribute_parameters::=
order_by_clause::=
© 2014 Advanced Systems srl
281
SQL STATEMENTS
282
Semantics
DISTINCT
Specify DISTINCT if you want the database to return only one copy of each set of duplicate
rows selected. Duplicate rows are those with matching values for each expression in the select
list.
ALL
Specify ALL if you want the database to return all rows selected, including all copies of
duplicates. The default is ALL.
* (asterisk)
Specify the asterisk to select all columns from all tables or materialized views listed in the FROM
clause. The columns are returned in the order indicated by CREATE TABLE or CREATE VIEW
statement.
select_list
The select_list lets you specify the columns you want to retrieve from the database.
table.* | view.* | materialized view.*
Specify the object name followed by a period and the asterisk to select all columns from the
specified table, view, or materialized view. Sadas returns a set of columns in the order in which
the columns were specified when the object was created. A query that selects rows from two or
more tables, views, or materialized views is a join.
You can use the schema qualifier to select from a table, view, or materialized view. In any case
the database assumes the table, view, or materialized view is in current database/schema, but
this syntax is allowed only for compatibility with SQL standards.
expr
Specify an expression representing the information you want to select. A column name in this
list can be qualified with schema only if the table, view, or materialized view containing the
column is qualified with schema in the FROM clause.
© 2014 Advanced Systems srl
SQL STATEMENTS
283
c_alias
Specify an alias for the column expression. Sadas will use this alias in the column heading of
the result set. The AS keyword is optional. The alias effectively renames the select list item for
the duration of the query. The alias can be used in the order_by_clause, group_by_clause,
distribute_clause
and having_clause.
Restrictions on the Select List
The select list is subject to the following restrictions:
If you also specify a group_by_clause in this statement, then this select list can contain only
the following types of expressions:
Constants
Aggregate functions and the functions SYSDATE,
SYSTIME,
SYSTIMESTAMP,
CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, TODAY.
Expressions identical to those in the group_by_clause. Each columns or expression
in group_by_clause must be also in the select list, otherwise Sadas returns error.
If you also specify a distribute_clause in this statement, then this select list can contain
only the following types of expressions:
Only numeric and date columns (not expression and contants) as dimension of
distribute operation.
Aggregate functions: MAX, MIN, SUM, AVG, COUNT.
Columns identical to those in the distribute_clause.
group_by_clause
Each columns in
must be also in the select list, otherwise Sadas returns error.
If you also specify a order_by_clause in this statement, then this select list can contain only
the following types of expressions:
Constants
All defined functions.
Expressions identical to those in the order_by_clause. Each columns or expression
in order_by_clause must be also in the select list, otherwise Sadas returns error.
© 2014 Advanced Systems srl
SQL STATEMENTS
284
FROM Clause
The FROM clause lets you specify the objects from which data is selected.
table | view | materialized view
Specify the name of a table, view, or materialized view from which data is selected.
subquery
Specify the data on which Sadas run the query at the top level. For each subquery Sadas
creates a temporary table, which will be deleted at the end of the query execution.
t_alias
Specify a correlation name, which is alias for the table, view or materialized view for evaluating
the query. Other references to the table, view, or materialized view throughout the query must
refer to this alias.
join_clause
Use the appropriate join_clause syntax to identify tables that are part of a join from which
data must be selected. The inner_join_clause lets you specify an inner join. The
star_join_clause
lets you specify an anti join or a semi join. The outer_join_clause lets
you specify an outer join. When you write a join query with the only JOIN keyword, Sadas
performs an inner join.
Inner Joins
Inner joins return only those rows that satisfy the join condition.
INNER
Specify INNER to explicitly specify an inner join.
JOIN
The JOIN keyword explicitly states that a join is being performed. You can use only this syntax
to do an inner join.
© 2014 Advanced Systems srl
SQL STATEMENTS
285
ON condition
Use the ON clause to specify a join condition. Doing so lets you specify join conditions
independently from any search or filter conditions in the WHERE clause.
Star Joins
Star joins resolve antijoins (with NOT keyword) and semijoins (with or without KEY keyword).
An antijoin returns rows from the left side of the predicate for which there are no
corresponding rows on the right side of the predicate. A semijoin returns rows that match an
EXISTS
subquery without duplicating rows from the left side of the predicate when multiple
rows on the right side satisfy the criteria of the subquery.
STAR
Specify STAR to explicitly specify a semi join .
KEY
Specify KEY STAR to explicitly specify a semi join.
NOT
Specify NOT to explicitly specify an anti join.
JOIN
The JOIN keyword explicitly states that a join is being performed. You can use only this syntax
to do an anti join or a semi join.
ON condition
Use the ON clause to specify a join condition. Doing so lets you specify join conditions
idependently from any search or filter conditions in the WHERE clause.
Outer Joins
© 2014 Advanced Systems srl
SQL STATEMENTS
286
Outer joins return all rows that satisfy the join condition and also returns some or all of those
rows from one table for which no rows from the other satisfy the join condition.
outer_join_type
The outer_join_type indicates the kind of outer join being performed:
Specify RIGHT to indicate a right outer join.
Specify LEFT to indicate a left outer join.
Specify FULL to indicate a full or two-sided outer join. In addition to the inner join,
rows from both tables that have not been returned in the result of the inner join will be
preserved and extended with nulls.
You can specify the optional OUTER keyword following RIGHT, LEFT, or FULL to
explicitly clarify that an outer join is being performed.
ON condition
Use the ON clause to specify a join condition. Doing so lets you specify join conditions
independently from any search or filter conditions in the WHERE clause.
Therefore:
A left outer join returns all the common column values from the left table in the FROM
clause.
A right outer join returns all the common column values from the right table in the
FROM
clause.
A full outer join returns all the common column values from both joined tables.
where_clause
The WHERE condition lets you restrict the rows selected to those that satisfy one or more
conditions. For condition, specify any valid SQL condition.
If you omit this clause, then the database returns all rows from the tables, views, or
materialized views in the FROM clause.
© 2014 Advanced Systems srl
SQL STATEMENTS
287
group_by_clause
Specify the GROUP BY clause if you want the database to group the selected rows based on the
value of expr(s) for each row and return a single row of summary information for each group.
Expressions in the GROUP BY clause can contain any columns or combinations of columns, of
the tables views, or materialized views in the FROM clause: the columns must appear also in the
select list.
The GROUP BY clause groups rows and guarantees the order of the result set.
distribute_clause
Specify the DISTRIBUTE clause if you want the database to group the selected rows based on
ranges of values of expr(s) for each row and return a single row of summary information for
each group. Expressions in the DISTRIBUTE clause can contain only columns of the tables,
views, or materialized views in the FROM clause: the columns must appear also in the select list.
DISTRIBUTE
can be only of one dimensional level.
The DISTRIBUTE clause groups rows and guarantees the order of the result set.
HAVING Clause
Use the HAVING clause to restrict the groups of returned rows to those groups for which the
specified condition is TRUE. If you omit this clause, then the database returns summary rows
for all groups.
Specify GROUP BY [DISTRIBUTE] and HAVING after the where_clause. If you specify both
GROUP BY [DISTRIBUTE]
and HAVING, then they can appear in either order. In HAVING clause
you can specify only a linear sequence of conditions in AND or a linear sequence of conditions
in OR.
Set Operators: UNION, UNION ALL, INTERSECT, MINUS
The set operators combine the rows returned by two SELECT statements into a single result.
© 2014 Advanced Systems srl
SQL STATEMENTS
288
The number and datatypes of the columns selected by each component query must be the
same, but the column lengths can be different. The names of the columns in the result set are
the names of the expressions in the select list preceding the set operator.
If you combine more than two queries with set operators, then the database evaluates adjacent
queries from left to right. The parenthesis around the subquery are optional. You can use them
to specify a different order of evaluation.
order_by_clause
Use the ORDER BY clause to order rows returned by the statement. Without an
order_by_clause,
no guarantee exists that the same query executed more than once will
retrieve rows in the same order.
expr
expr
orders rows based on their value for expr. The expression is based on columns in the
select list or columns in the tables, views, or materialized views in the FROM clause.
position
Specify position to order rows based on their value for the expression in this position of the
select list. The position value must be an integer.
ASC | DESC
Specify whether the ordering sequence is ascending or descending. ASC is the default.
Examples
The following statement selects rows from the employees table with the department number
of 30:
SELECT *
FROM employees
WHERE department_id = 30
ORDER BY last_name;
The following statement selects the name, job, salary and department number of all employees
except purchasing clerks from department number 30:
© 2014 Advanced Systems srl
SQL STATEMENTS
289
SELECT last_name, job_id, salary, department_id
FROM employees
WHERE NOT (job_id = 'PU_CLERK' AND department_id = 30)
ORDER BY last_name;
The following example selects rows from the oe.orders table for orders earlier than a
specified date:
SELECT * FROM orders
WHERE order_date < '15/06/2000';
To return the minimum and maximum salaries for each department in the employees table,
issue the following statement:
SELECT department_id, MIN(salary), MAX (salary)
FROM employees
GROUP BY department_id
ORDER BY department_id;
To return the minimum and maximum salaries for the clerks in each department, issue the
following statement:
SELECT department_id, MIN(salary), MAX (salary)
FROM employees
WHERE job_id = 'PU_CLERK'
GROUP BY department_id
ORDER BY department_id;
To return the minimum and maximum salaries for the employees in each department whose
lowest salary is less than $5,000, issue the next statement:
SELECT department_id, MIN(salary), MAX (salary)
FROM employees
GROUP BY department_id
HAVING MIN(salary) < 5000
ORDER BY department_id;
DEPARTMENT_ID MIN(SALARY) MAX(SALARY)
------------- ----------- ----------10
4400
4400
30
2500
11000
50
2100
8200
60
4200
9000
To select all purchasing clerk records from employees and order the results by salary in
descending order, issues the following statement:
SELECT *
© 2014 Advanced Systems srl
SQL STATEMENTS
290
FROM employees
WHERE job_id = 'PU_CLERK'
ORDER BY salary DESC;
To select information from employees ordered first by ascending department number and then
by descending salary, issue the following statement:
SELECT last_name, department_id, salary
FROM employees
ORDER BY department_id ASC, salary DESC, last_name;
To select the same information as the previous SELECT and use the positional ORDER BY
notation, issue the following statement, which orders by ascending department_id, then
descending salary, and finally alphabetically by last_name:
SELECT last_name, department_id, salary
FROM employees
ORDER BY 2 ASC, 3 DESC, 1;
The following example shows how a partitioned outer join fills data gaps in rows to facilitate
analytic function specification and reliable report formatting. The example first creates a small
data table to be used in the join:
SELECT d.department_id, e.last_name
FROM departments d LEFT OUTER JOIN employees e
ON d.department_id = e.department_id
ORDER BY d.department_id, e.last_name;
The left outer join returns all departments, including those without any employees. The same
statement with a right outer join returns all employees, including those not yet assigned to a
department:
The following example selects a list of employees who are not in a particular set of
departments:
SELECT last_name, department_id
FROM employees e NOT STAR JOIN departments d
ON e.department_id = d.department_id
WHERE location_id = 1700
In the following example, only one row needs to be returned from the departments table, even
though many rows in the employees table might match the subquery. If no index has been
defined on the salary column in employees, then a semijoin can be used to improve query
performance.
© 2014 Advanced Systems srl
SQL STATEMENTS
291
SELECT * FROM departments d [KEY] STAR JOIN employees e
ON d.department_id = e.department_id
WHERE employees.salary > 2500
ORDER BY department_name;
The following statement returns the current date:
SELECT SYSDATE FROM DUAL;
You could select SYSDATE from the employees table, but the database would return 14 rows of
the same SYSDATE, one for every row of the employees table. Selecting from DUAL is more
convenient.
Distribute examples
Numeric columns
If A is a numeric field of T table, some DISTRIBUTE examples follows:
Linear ranges
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A ON (10,100,1000) WHERE
[…] ;
If you specify three parameters, you distribute the numeric field (A) starting from value
10
(base value), for 100 ranges (range number) of width 1000 (range width).
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A ON (150) WHERE[…] ;
If you specify one parameter, you distribute the numeric field (A) starting from minimum
value of field (base value), for 150 ranges (range number) of width equal to (max–
min)/150
(range width).
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A WHERE[…] ;
If you don’t specify any parameter, you distribute the numeric field (A) starting from
minimum value of field (base value), for 10 ranges (range number) of width equal to (max–
min)/10
(range width).
Manual ranges
© 2014 Advanced Systems srl
SQL STATEMENTS
292
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A ON (10,20,21,30) WHERE
[…] ;
In this case the number of parameters must be an even integer; the parameters indicate
gradually the start and the end of each range.
Date columns
If A is a date field of T table, some DISTRIBUTE examples follows:
Linear ranges
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A ON
(‘01/01/2000’,100,10,day) WHERE[…] ;
If you specify these four parameters, you distribute the date field (A) starting from
‘01/01/2000’
value of field (base value), for 100 ranges (range number) of 10 width (range
width) in days (range type).
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A ON (‘01/01/2000’,52,1,
week) WHERE[…];
If you specify these four parameters, you distribute the date field (A) starting from
‘01/01/2000’
value of field (base value), for 52 ranges (range number) of 1 width (range
width) in weeks (range type).
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A ON (‘01/01/2000’,48,3,
month) WHERE[…];
If you specify these four parameters, you distribute the date field (A) starting from
‘01/01/2000’
value of field (base value), for 48 ranges (range number) of 3 width (range
width) in months (range type).
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A ON (‘01/01/2000’,5,1,
year) WHERE[…];
If you specify these four parameters, you distribute the date field (A) starting from
‘01/01/2000’
value of field (base value), for 5 ranges (range number) of 1 width (range
width) in years (range type).
© 2014 Advanced Systems srl
SQL STATEMENTS
293
Select A, count(*), sum(B) from T distribute A on (150) where … ;
If you specify one parameter, you distribute the date field (A) starting from minimum
value of field (base value), for 150 ranges (range number) of (max–min)/150 width (range
width) in days (range type).
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A WHERE[…] ;
If you don’t specify any parameters, you distribute the date field (A) starting from
minimum value of field (base value), for 10 ranges (range number) of (max–min)/10
width (range width) in days (range type).
Manual ranges
SELECT A, count(*), sum(B) FROM T DISTRIBUTE A ON
(‘01/01/2000’,‘01/02/2000’,‘01/04/2000’,‘01/06/2000’) WHERE[…] ;
In this case the number of parameters must be an even integer; the parameters indicate
gradually the start and the end of each range.
9.77
SET LANGUAGE
Purpose
Use a SET LANGUAGE statement to change language of SADAS error messages.
You can set following values:
0 Italian
1 Romanian
2 English
Syntax
<set_language> ::=
set_language::=
© 2014 Advanced Systems srl
SET LANGUAGE <value>
SQL STATEMENTS
294
SET
LANGUAGE
value
Semantics
value
Value of language that you are setting.
Examples
SET LANGUAGE 0;
9.78
SET VARIABLE
Purpose
Use a SET VARIABLE statement to set a variable value in the current session.
Syntax
<set_variable> ::=
SET VARIABLE <variable_name> <value>
set_variable::=
SET
VARIABLE
variable name
Semantics
variable_name
Value for the name of variable that you are setting.
value
Value for variable that you are setting.
Example
If the current connected user has the following hidden condition:
date_ope >= $DAT_INI$
© 2014 Advanced Systems srl
value
SQL STATEMENTS
295
he can set the parameter DAT_INI as follow:
set variable DAT_INI = '01/01/2012'
so the hidden condition will be:
date_ope >= '01/01/2012'
9.79
TRUNCATE DATABASE
Purpose
Use the TRUNCATE DATABASE statement to empty an entire database/schema. Sadas will erase
data of all tables and set their status to " loaded with 0 records".
Prerequisites
Only SYSDBA user can use the TRUNCATE DATABASE statement.
Syntax
<truncate_database>
::=
TRUNCATE DATABASE db_name
truncate_database::=
Semantics
db_name
Name of schema/database to be truncated. The name can be up to 128 bytes long and can
contain only ASCII characters.
The database name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
TRUNCATE DATABASE TPCH;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.80
296
TRUNCATE TABLE
Purpose
Use the TRUNCATE TABLE statement to empty a table in current database/schema. Sadas will
erase data of table and will set its status to " loaded with 0 records".
Prerequisites
You must have the LOAD privilege on a table in order to truncate it.
Syntax
<truncate_table>
::=
TRUNCATE TABLE table_name
truncate_table::=
Semantics
table_name
Name of table to be truncated. The name can be up to 128 bytes long and can contain only
ASCII characters.
The table name is case insensitive and is stored in uppercase ASCII
characters. If you specify the table name as a quoted identifier, then the quotation marks are
silently ignored.
Examples
TRUNCATE TABLE LINEITEM;
9.81
UNION
Purpose
Use the UNION statement to merge the result of a query with another query result.
© 2014 Advanced Systems srl
SQL STATEMENTS
297
There are limits on fields on the select statements (sub-query):
all corresponding fields must be of the same type;
also numeric fields must be of the same type: if you have an INTEGER [FLOAT] field, all
corresponding fields must be INTEGER [FLOAT];
if you have a code [pseudo-code] field, all corresponding fields must be of code
[pseudo-code] type, with the same decode table.
If you specify ALL keyword, you will get full results of base queries.
If you omit ALL keyword, Sadas will eliminate duplicate rows.
Prerequisites
To use the UNION statement, you must have the SELECT privilege on schema/database.
Syntax
<union>::=(<select_statement>
|
<parenthesis>)
<parenthesis>))
union::=
< parenthesis >
© 2014 Advanced Systems srl
::=
‘(’ | ‘)’
(UNION
[ALL]
(<select_statement
>
|
SQL STATEMENTS
select_statement> ->
298
see ‘SELECT’ chapter
Semantics
select_statement
Specify one of the statements for UNION operation. For more details see the “SELECT” chapter.
parenthesis
The select statements can be optionally in parenthesis.
Examples
SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY > 22
UNION
SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY < 3
N_NATIONKEY N_NAME
N_REGIONKEY
---------------------------------------0
ALGERIA
0
1
ARGENTINA
1
2
BRAZIL
1
23
UNITED KINGDOM 3
24
UNITED STATES
1
SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY > 22
UNION ALL
SELECT N_NATIONKEY,N_NAME,N_REGIONKEY FROM NATION WHERE N_NATIONKEY < 3
N_NATIONKEY N_NAME
N_REGIONKEY
---------------------------------------23
UNITED KINGDOM 3
24
UNITED STATES
1
0
ALGERIA
0
1
ARGENTINA
1
2
BRAZIL
1
9.82
UNLOAD DATABASE
Purpose
Use the UNLOAD DATABASE statement to unload an entire database/schema.
This operation will re-create input data files for all tables of database. Sadas will use the CTL
(Control Table Loader) file of each table for this operation, so all the CTL files must contain
© 2014 Advanced Systems srl
SQL STATEMENTS
299
correct specifications.
Prerequisites
Only SYSDBA user can use the UNLOAD DATABASE statement.
Syntax
<unload_database>
::=
UNLOAD DATABASE db_name
unload_database::=
Semantics
db_name
Name of schema/database to be unloaded. The name can be up to 128 bytes long and can
contain only ASCII characters.
The database name is case insensitive and is stored in
uppercase ASCII characters. If you specify the database name as a quoted identifier, then the
quotation marks are silently ignored.
Examples
UNLOAD DATABASE TPCH;
9.83
UNLOAD TABLE
Purpose
Use the UNLOAD TABLE statement to unload a table in current database/schema and to recreate its original input data file.
The input data file will be created accordingly with CTL (Control Table Loader) specifications;
© 2014 Advanced Systems srl
SQL STATEMENTS
300
if the input filename is not specified in the statement Sadas will use the file name defined in the
CTL.
If ONLY clause is specified, Sadas will unload only n_rec records.
If SKIP clause is specified, Sadas will skip first n_rec records.
Prerequisites
To use the UNLOAD TABLE statement, you must have the LOAD privilege on schema/database.
Syntax
<unload_table>
::=
UNLOAD TABLE table_name ['@' file_name]
[ ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
unload_table::=
Semantics
table_name
Specify the name of the table for unload operation. The table name is case insensitive and is
© 2014 Advanced Systems srl
SQL STATEMENTS
301
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
file_name
Specify the name of the input file. The file name must be complete, with absolute path.
n_rec
Number of records to skip or to unload.
Examples
UNLOAD TABLE REGION;
UNLOAD TABLE REGION ONLY 100;
UNLOAD TABLE REGION SKIP 30;
UNLOAD TABLE REGION SKIP 30 ONLY 100;
UNLOAD TABLE REGION @ REGION.TBL;
9.84
UNLOCK USER
Purpose
Use the UNLOCK USER statement to unlock a database user. User unlocked can login to the
current database.
All users are unlocked by default.
Prerequisites
The user must be in current schema/database and you must have the SECURITY system
privilege.
Syntax
<unlock_user>
unlock_user::=
© 2014 Advanced Systems srl
::=
UNLOCK USER user
SQL STATEMENTS
302
Semantics
user
Specify the name of the user. The user name is case insensitive and is stored in uppercase
ASCII characters. If you specify the user name as a quoted identifier, then the quotation marks
are silently ignored.
Examples
UNLOCK USER SMITH;
9.85
UNLOCK TABLE
Purpose
Use the UNLOCK TABLE statement to unlock a table of the current database.
Prerequisites
Only a SYSDBA can unlock a table.
Syntax
<unlock_table>
::=
UNLOCK TABLE table_name
unlock_table::=
UNLOCK
TABLE
table_name
Semantics
table_name
Specify the name of the table for load operation. The table name is case insensitive and is
© 2014 Advanced Systems srl
SQL STATEMENTS
303
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
Examples
UNLOCK TABLE CUSTOMER;
9.86
UPDATE
Purpose
Use the UPDATE statement to update rows in a table. To use this statement the base table must
be already loaded. You can specify up to 256 elements in update list.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the UPDATE process. While executing this process, Sadas stops all others requests.
In this case the loading type is always "UPDATE" .
Prerequisites
The table must be contained in the current schema/database and you must have the LOAD
privilege on the table.
Syntax
<update>
::=
<conditions> ]
update_table::=
© 2014 Advanced Systems srl
UPDATE
table_name
SET
<update_list>
[
WHERE
SQL STATEMENTS
304
update_set_clause::=
Semantics
schema
Specify the schema/database containing the table. If you omit schema, then Sadas assumes the
table is in current schema/database connected.
table_name
Specify the name of the table which rows must be updated. The name can be up to 128 bytes
long and can contain only ASCII characters. The table name is case insensitive and is stored in
uppercase ASCII characters. If you specify the table name as a quoted identifier, then the
quotation marks are silently ignored.
expr
The expression is based on columns in the select list or columns in the tables in the FROM
clause.
where_clause
Use the where_clause to update only rows that satisfy the conditions. The conditions can
reference the table which you are updating and can contain a scalar subquery.
© 2014 Advanced Systems srl
SQL STATEMENTS
305
Examples
UPDATE LINEITEM SET L_QUANTITY = 50;
UPDATE LINEITEM SET L_QUANTITY = L_QUANTITY*10
WHERE L_SHIPDATE >
‘01/01/1998’;
9.87
UPDATE COLUMNS
Purpose
Use the UPDATE COLUMNS statement to update only some columns of a table in current
database/schema.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the UPDATE COLUMNS process. While executing this process, Sadas stops all others requests.
To use this statement the base table must be already loaded and must have a primary key. To
update a column in a table, you must have an input file with explicit keys to update, according
with CTL (Control Table Loader) specifics; if the input file name is not specified in the
statement, Sadas will use the file specified in the CTL.
Prerequisites
To use the UPDATE COLUMNS statement, you must have the LOAD privilege on schema/
database.
Syntax
<update_columns>
file_name ]
update_columns::=
© 2014 Advanced Systems srl
::=
UPDATE
COLUMN
<column_list>
ON
table_name
[
'@'
SQL STATEMENTS
306
column_list::=
Semantics
columns_list
Specify the list of columns for update operation.
table_name
Specify the name of the table for update operation. The table name is case insensitive and is
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
file_name
Specify the name of the input file. The file name must be complete, with absolute path.
Examples
UPDATE R_NAME ON REGION;
UPDATE R_NAME, R_COMMENT ON REGION @ REGION.TBL;
© 2014 Advanced Systems srl
SQL STATEMENTS
9.88
307
UPDATE TABLE
Purpose
Use the UPDATE TABLE statement to update a table in the current database/schema from an
input file.
Since this is a load process, Sadas will wait for the end of all queries running and then will start
the UPDATE TABLE process. While executing this process, Sadas stops all others requests.
To use this statement the base table must be already loaded and must have a primary key. An
input file with explicit keys to update is required, according with CTL (Control Table Loader)
specifications; if the input file name is not specified in the statement Sadas will use the file
specified in the CTL.
In this case the loading type is always "UPDATE" .
Prerequisites
To use the UPDATE TABLE statement, you must have the LOAD privilege on schema/database.
If you specify the ALL clause, Sadas appends the records of file that have not the
corresponding primary key in destination table.
Syntax
<update_table>
::=
UPDATE
TABLE
table_name
[
'@'
file_name
]
[ALL]
update_table::=
@
UPDATE
TABLE
file_name
table_name
Semantics
table_name
Specify the name of the table for update operation. The table name is case insensitive and is
© 2014 Advanced Systems srl
AL
SQL STATEMENTS
308
stored in uppercase ASCII characters. If you specify the table name as a quoted identifier, then
the quotation marks are silently ignored.
file_name
Specify the name of the input file. The file name must be complete, with absolute path.
Examples
UPDATE TABLE REGION;
UPDATE TABLE REGION @ REGION.TBL;
9.89
UNSET VARIABLE
Purpose
Use a UNSET VARIABLE statement to unset a variable value in the current session.
Syntax
<unset_variable> ::= UNSET VARIABLE <variable_name>
unset_variable::=
UNSET
VARIABLE
variable name
Semantics
variable_name
Value for the name of variable that you are setting.
value
Value for variable that you are setting.
Examples
UNSET VARIABLE NATION;
© 2014 Advanced Systems srl
SQL STATEMENTS
© 2014 Advanced Systems srl
309
Part
X
Compendium of Sadas SQL Syntax
10
311
Compendium of Sadas SQL Syntax
Select:
<describe>
::=
DESC [ | DESCR | DESCRIBE ]
SYSDB |
SYSTABLES |
SYSVIEWS |
SYSSYNONYMS |
SYSOBJECTS |
SYSALLCOLUMNS |
SYSUSERS [ @ domain_name ] |
SYSDOMAINS |
SYSLOG |
SYSKEYS |
SYSFOREIGNKEYS |
STORED QUERIES |
USER user_name |
[SHADOW | INFO] table_name (,table_name)*
<select>
::=
SELECT [ALL | DISTINCT] <select_list> | *
FROM <table_list>
| table_name <join_clause > table_name ON
<join_condition>
| <subquery>
[ WHERE < conditions > ]
[ GROUP BY [ CUBE | ROLLUP ] <groupby_list> | DISTRIBUTE [BY]
<columns_list>
ON '(' <parameters_list> ')
[ HAVING < conditions > ] ]
[ ORDER BY <orderby_list> ]
<union>
::=
(<select_statement> | <parenthesis>)
( UNION [ALL] (<select_statement > | <parenthesis>) )*
<intersect>
::=
(<select> | <parenthesis>)
( INTERSECT (<select> | <parenthesis>) )*
© 2014 Advanced Systems srl
Compendium of Sadas SQL Syntax
<minus>
312
::=
(<select_statement> | <parenthesis>)
( MINUS (<select_statement > | <parenthesis>) )*
Catalog management:
<alter_table>
::=
ALTER TABLE table_name
ADD '(' <modify_list> ')'
| DROP COLUMN '(' <column (, column)*
| MODIFY '(' <modify_list> ')'
<alter_view>
::=
ALTER VIEW view MODIFY '(' <modify_list> ')'
<append_table1>
::=
APPEND TABLE table_name ['@' file_name]
[ DIRECT | ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
[ ORDER BY <column_list> ]
<append_table2>
::=
APPEND TABLE table_name FROM '('<SubQuery>')'
<comment_on_column>
::=
COMMENT ON COLUMN
[ column_name OF [ ALL | table_name ] |
table_name.column_name ]
IS 'comment'
<comment_on_table>
::=
COMMENT ON TABLE table_name IS 'comment'
<create_database>
::=
CREATE DATABASE db_name ['@' storage_path ]
<create_expression>
::=
CREATE
<create_index>
::=
CREATE INDEX ON table_name.col_name
<create_synonym>
::=
CREATE
::=
CREATE
EXPRESSION
expr_name
ON
TABLE
table_name
AS
'('
<expr> ')'
[OR
REPLACE]
[PUBLIC]
synonym_name
FOR
schema.table_name
<create_table>
'('<column_definition>')'
© 2014 Advanced Systems srl
[GLOBAL
TEMPORARY]
TABLE
table_name
Compendium of Sadas SQL Syntax
<create_table>
313
::=
CREATE [GLOBAL TEMPORARY] TABLE table_name
AS '('<select_statement>')'
<create_view>
::=
CREATE [OR REPLACE] [MATERIALIZED] VIEW view_name AS
'('<select>')'
<deactivate_database>::=
DEACTIVATE DATABASE db_name
<deactivate_table>
::=
DEACTIVATE TABLE table_name
<delete_table>
::=
DELETE [FROM] table_name [ WHERE <conditions> ]
<delete_keys>
::=
DELETE KEYS FROM table_name
<drop_database>
::=
DROP DATABASE db_name
<drop_expression>
::=
DROP EXPRESSION expr_name ON [ TABLE table_name | ALL ]
<drop_expressions>
::=
DROP EXPRESSIONS ON [ TABLE table_name | ALL ]
<drop_index>
::=
DROP INDEX table_name.col_name
[ '@' file_name ]
<drop_generated_columns>
::=
DROP GENERATED COLUMNS ON [ TABLE table_name | ALL ]
<drop_synonym>
::=
DROP SYNONYM synonym_name
<drop_table>
::=
DROP TABLE table_name
<drop_view>
::=
DROP VIEW view
<duplicate_database> ::=
DUPLICATE DATABASE db_name
TO new_db_name [':' new_db_Id] ['@' storage_path ]
<duplicate_table>
storage_path ]
© 2014 Advanced Systems srl
::=
DUPLICATE TABLE table_name TO new_table_name ['@'
Compendium of Sadas SQL Syntax
<insert>
314
::=
INSERT INTO table_name
['('
column_list
::=
INSERT TABLE table_name ['@' file_name]
')']
VALUES
'('
values_list ')'
<insert_table1>
[ DIRECT | ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
<insert_table2>
::=
INSERT TABLE table_name FROM '('<SubQuery>')'
<load_columns>
::=
LOAD COLUMN <column_list> ON table_name [ '@' file_name ]
<load_database>
::=
LOAD DATABASE db_name
<load_table1>
::=
LOAD TABLE table_name ['@' file_name]
[ DIRECT | ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
<load_table2>
::=
LOAD TABLE table_name FROM '('<SubQuery>')'
<lock_table>
::=
LOCK TABLE table_name
<rename_database>
::=
RENAME DATABASE db_name TO new_db_name [':' new_db_Id]
<rename_table>
::=
RENAME TABLE table_name TO new_table_name
<rename_view>
::=
RENAME VIEW view_name TO new_view_name
<rename_column>
::=
RENAME COLUMN col_name TO new_col_name ON table_name
<replicate_database> ::=
REPLICATE DATABASE db_name
TO new_db_name [':' new_db_Id] ['@' storage_path ]
<replicate_table>
::=
REPLICATE TABLE table_name TO new_table_name ['@'
<rewrite_database>
::=
REWRITE DATABASE db_name
<rewrite_table1>
::=
REWRITE TABLE table_name ['@' file_name]
storage_path ]
[ DIRECT | ONLY n_rec | SKIP n_rec [ONLY n_rec] ]
© 2014 Advanced Systems srl
Compendium of Sadas SQL Syntax
315
<rewrite_table2>
::=
REWRITE TABLE table_name FROM '('<SubQuery>')'
<truncate_database>
::=
TRUNCATE DATABASE db_name
<truncate_table>
::=
TRUNCATE TABLE table_name
<unlock_table>
::=
UNLOCK TABLE table_name
<update>
::=
UPDATE table_name SET <update_list> [ WHERE <conditions> ]
<update_columns>
::=
UPDATE COLUMN <column_list> ON table_name [ '@'
::=
UPDATE TABLE table_name ['@' file_name ]
file_name ] [ ALL ]
<update_table>
Security management:
<alter_user>
::=
ALTER USER user_name
[ PASSWORD EXPIRE | PASSWORD_LIFE_TIME [ DEFAULT | days |
UNLIMITED ] ]
<create_user>
::=
CREATE USER user
[ '@' domain_name ]
[ PASSWORD EXPIRE | PASSWORD_LIFE_TIME [ DEFAULT | days |
UNLIMITED ] ]
<drop_user>
::=
DROP USER user_name
<duplicate_user>
::=
DUPLICATE USER user_name TO new_user_name
<lock_user>
::=
LOCK USER user_name
<unlock_user>
::=
UNLOCK USER user_name
<create_domain>
::=
CREATE DOMAIN domain_name
<drop_domain>
::=
DROP DOMAIN domain_name
© 2014 Advanced Systems srl
Compendium of Sadas SQL Syntax
316
<rename_domain>
::=
RENAME DOMAIN domain_name TO new_domain_name
<grant>
::=
GRANT ALL | <privileges_list> ON ( table_name | ALL ) TO
::=
REVOKE ALL | <privileges_list> ON ( table_name | ALL )
user_name
<revoke>
FROM user_name
<privileges_list>
::=
PR_SELECT | PR_DESCRIBE | PR_CATALOG | PR_LOAD |
PR_SECURITY
(',' PR_SELECT | PR_DESCRIBE | PR_CATALOG | PR_LOAD |
PR_SECURITY )*
Other:
<connect>
::=
CONNECT user '/' password '@' database
|
CONNECT SYSDBA '/' password [ '@' database ]
<delete_stored_queries>
::=
DELETE STORED QUERIES [ALL] [ '<' <times> | '<' <date> |
'=' <hash>]
<describe>
::=
DESC [ | DESCR | DESCRIBE ] STORED QUERIES ['<'|'>'
<disable_index>
::=
DISABLE INDEXGBY
<disconnect>
::=
DISCONNECT | DISC
<enable_index>
::=
ENABLE INDEXBGY
<execute>
::=
EXEC | EXECUTE STORED QUERIES [ '>' <times> | <date> ]
<parenthesis>
::=
'(' <union> | <intersect> | <minus> ')'
<set_language>
::=
SET LANGUAGE <value>
<set_variable>
::=
SET VARIABLE <variable_name> <value>
<times>|<date>]
© 2014 Advanced Systems srl
Compendium of Sadas SQL Syntax
<unset_variable>
© 2014 Advanced Systems srl
317
::=
UNSET VARIABLE <variable_name>
Part
XI
Sadas Database Reserved Words
11
319
Sadas Database Reserved Words
This chapter lists Sadas SQL reserved words. The list also includes the words that are ANSI
reserved words and the words not yet used by Sadas, but that cannot be used as identifiers.
Word
Used
ADD
*
ALL
*
ALTER
*
AND
*
ANY
-
APPEND
*
AS
*
ASC
*
ASCENDING
*
BETWEEN
*
BY
*
CASCADE
*
CASE
*
CHAR
*
CHARACTER
*
CODE
*
COLUMN
COLUMNS
*
COMMENT
*
COMMIT
*
CONNECT
*
CONSTRAINT
*
CONTROL
-
CREATE
*
CUBE
*
DATABASE
*
DATE
*
DBADMIN
*
DEACTIVATE
*
© 2014 Advanced Systems srl
Sadas Database Reserved Words
320
DEC
*
DECIMAL
*
DEFAULT
*
DELETE
*
DESC
*
DESCENDING
*
DESCR
*
DESCRIBE
*
DIRECT
*
DISABLE
*
DISC
*
DISCONNECT
*
DISTINCT
*
DISTRIBUTE
*
DOMAIN
*
DOUBLE
*
DROP
*
DUAL
*
DUPLICATE
*
ELSE
*
ENABLE
*
END
*
EXEC
*
EXECUTE
*
EXISTS
*
EXPIRE
*
EXPRESSION
*
EXPRESSIONS
*
FALSE
*
FIELDS
*
FIX
*
FLOAT
*
FOR
*
FOREIGN
*
FROM
*
© 2014 Advanced Systems srl
Sadas Database Reserved Words
321
FULL
*
GENERATED
*
GLOBAL
*
GRANT
*
GROUP
*
HAVING
*
IN
*
INDEX
*
INDEXGBY
*
INFO
*
INNER
*
INSERT
-
INT
*
INTEGER
*
INTERSECT
*
INTO
*
IS
*
JOIN
*
KEY
*
KEYS
*
LANGUAGE
*
LEFT
*
LIKE
*
LOCK
*
LOAD
*
MATERIALIZED
*
MINUS
*
MODIFY
*
NATURAL
-
NOT
*
NULL
*
NUMBER
*
NUMERIC
*
OF
*
ON
*
© 2014 Advanced Systems srl
Sadas Database Reserved Words
322
ONLY
*
OR
*
ORDER
*
OUTER
*
PASSWORD
*
PASSWORD_LIFE_TIME
*
PRECISION
*
PRIMARY
*
PR_CATALOG
*
PR_DESCRIBE
*
PR_LOAD
*
PR_SECURITY
*
PR_SELECT
*
PUBLIC
*
QUERIES
*
REAL
*
REFERENCES
*
RENAME
*
REPLACE
*
REPLICATE
*
REVOKE
*
REWRITE
*
RIGHT
*
ROLLBACK
*
ROLLUP
*
ROWID
*
ROWNUM
*
SELECT
*
SET
*
SHADOW
*
SKIP
*
SMALLINT
*
SOME
-
STAR
*
STORED
*
© 2014 Advanced Systems srl
Sadas Database Reserved Words
323
SYNONYM
*
SYSALLCOLUMNS
*
SYSDB
*
SYSDBA
*
SYSDOMAINS
*
SYSFOREIGNKEYS
*
SYSKEYS
*
SYSLOG
*
SYSOBJECTS
*
SYSSYNONYMS
*
SYSTABLES
*
SYSUSERS
*
SYSVIEWS
*
TABLE
*
TEMPORARY
*
THEN
*
TIME
*
TIMESTAMP
*
TO
*
TRUE
*
TRUNCATE
*
UNION
*
UNLIMITED
*
UNLOAD
*
UNSET
*
UPDATE
*
USER
*
VALUES
*
VARCHAR
*
VARIABLE
*
VIEW
*
VIRTUAL
*
WHEN
*
WHERE
*
© 2014 Advanced Systems srl
Sadas Database Reserved Words
© 2014 Advanced Systems srl
324
Part
XII
Sadas Database SQL Errors
12
326
Sadas Database SQL Errors
This chapter lists all SADAS SQL errors.
12.1
SDS-0000 "No error"
Error Code
0000
Error Description
“No error”
SQL types
All
Reasons why
-
Notes
Usually this message is not returned by Sadas, but if Sadas returns it a critical error occurred
during parsing of SQL script (see also error 0033).
12.2
SDS-0001 "Null SQL script"
Error Code
0001
Error Description
“Null SQL script”
SQL types
All
Reasons why
-
Notes
You have tried to execute a NULL SQL script.
12.3
SDS-0002 "Encountered end of file in comments"
Error Code
0002
Error Description
“Encountered end of file in comments”
SQL types
All
Reasons why
You don’t have closed comments correctly.
Sadas parser has encountered end of file in comments.
Notes
Sadas SQL comments must have a start symbol (‘{‘ or ‘/*’) and a corresponding end symbol (‘}’
or ‘*/’): for example, the comments that start with ‘{‘ must end with ‘}’ (it’s the same for ‘/*’
and ‘*/’). Sadas closes automatically comments that start with ‘--‘, at the end of a line (when
Sadas encounters Line Feed and/or Carriage Return chars).
© 2014 Advanced Systems srl
Sadas Database SQL Errors
327
Example of error
SELECT * FROM T /* This is a select
12.4
Comments not closed
SDS-0003 "Non terminated text literal"
Error Code
0003
Error Description
“Non terminated text literal”
SQL types
All
Reasons why
SADAS parser has not encountered the end of a text literal.
Notes
Text, character, and string literals must be always surrounded by single
quotation marks.
Examples
a. SELECT * FROM T WHERE city = 'Naples
^ - Text literal not terminated
b. SELECT * FROM T WHERE company = 'Advanced
^ - Text literal not terminated
Systems'
12.5
SDS-0004 "Text literal too long"
Error Code
0004
Error Description
“Text literal too long”
SQL types
All
Reasons why
SADAS parser has encountered a text literal too long (limit 128).
Notes
SADAS parser limits text, character, and string literals to 128 bytes.
Example of error
SELECT * FROM T WHERE comment = 'A.......XYZ'
^ - Text literal too long
© 2014 Advanced Systems srl
Sadas Database SQL Errors
12.6
328
SDS-0005 "Unknown character"
Error Code
0005
Error Description
“Unknown character”
SQL types
All
Reasons why
Sadas parser has encountered a unknown char for SQL environment or
in a numeric literal.
Notes
In a SQL script Sadas parser accepts only these characters:
- 'A'..'Z' , 'a'..'z'
- '0'..'9'
- '@', '(', ')', '.', ',', ';', '*', '=', '+', '-', ''', '"', '/', '>', '<', '!', '^',
'|', '_'
A
numeric literal is made only with these characters:
- '0'..'9'
- '+', '-', 'e', 'E', '.'
Sadas returns this error if it encounters a unknown character or a illegal text numeric.
Examples of error
a. [...] WHERE & [...]
^ - Unknown character (&)
b. [...] A > 574G [...]
^ - Illegal numeric text (574G)
12.7
SDS-0006 "Identifier name too long"
Error Code
0006
Error Description
“Identifier name too long”
SQL types
All
Reasons why
Sadas parser has encountered a name referred to identifier too long (limit
128).
Notes
The name of identifiers must have always length less than Sadas parser limit (128 bytes).
© 2014 Advanced Systems srl
Sadas Database SQL Errors
329
Example of error
SELECT * FROM T WHERE A...XYZ > 5
^ - Identifier name too long
12.8
SDS-0007 "Illegal identifier"
Error Code
0007
Error Description
“Illegal identifier”
SQL types
All
Reasons why
Sadas parser has encountered a bad identifier name.
Notes
The name of identifiers can be of two types:
1. traditional: it can contain only following characters
'A'..'Z', 'a'..'z', '0'..'9' and '_';
the first character cannot be '0'..'9' and '_'.
2. extended: it can contain only following characters
'A'..'Z', 'a'..'z', '0'..'9', '_', ' '
(blank), ''', '-' and '.';
delimited by double quotes; an extended identifier name cannot contain in double
quotes all blank characters or empty string.
Sadas error message indicates the part of illegal identifier name preceding invalid character.
Examples of error
SELECT "Comp & Ltd" [...]
^ - Illegal identifier (COMP )
12.9
SDS-0008 "Illegal numeric literal"
Error Code
0008
Error Description
“Illegal number”
SQL types
All
Reasons why
Sadas parser has encountered a bad or too long numeric literal.
Notes
© 2014 Advanced Systems srl
Sadas Database SQL Errors
330
In numeric literals Sadas accepts integer and real numbers; the decimal separator must be the
point character; you cannot write the thousands separator; you can use scientific notation,
using characters 'E' or 'e' for exponential part. A numeric literal must have always length less
than Sadas parser limit (128 bytes). Sadas error message indicates the illegal numeric literal.
Examples of error
a. [...] 123.4.5 [...]
^ - Illegal numeric literal (123.4.5)
b. [...] 123E4.5 [...]
^ - Illegal numeric literal (123E4.5)
c. [...] 1234E. [...]
^ -
Illegal numeric literal (12345E.)
12.10 SDS-0009 "Syntax error"
Error Code
0009
Error Description
“Syntax error”
SQL types
All
Reason
Sadas SQL grammar is not satisfied.
Notes
This is a generic error, that can have several reasons. Some main reasons are given as follows:
bad written keywords,
missing keyword,
too many keywords,
missing characters spelling (comma, point, …),
bad order of clauses,
bad use of keyword or identifier,
bad arithmetic expression,
bad logic expression,
bad SQL constructs,
unknown datatype.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
331
12.11 SDS-0010 "Expected relational operator"
Error Code
0010
Error Description
“Expected relational operator”
SQL types
SELECT
Reasons why
Missing or bad relational operator in a condition.
Notes
In conditions Sadas uses following relational operators:
<, <=, =, >=, >, !=, <>, ^=
Sadas returns this error when relational operator is missing or is not one of those used by Sadas.
Examples of error
a. [...] WHERE A ( 5
^ - Expected relational operator
b. [...] WHERE A
^ - Expected relational operator
12.12 SDS-0011 "Expected logical operator"
Error Code
0011
Error Description
“Expected logical operator”
SQL types
SELECT
Reasons why
Missing logical operator in a conditions.
Notes
Sample conditions (predicates) must be concatenated using logical operators: [AND , OR].
Sadas returns this error when logical operator is missing between two predicates.
Examples of error
a. [...] WHERE A > 5
B < 4
^ - Expected logical operator
b. [...] WHERE A > 5 NOT B < 4
^ - Expected logical operator
© 2014 Advanced Systems srl
Sadas Database SQL Errors
332
12.13 SDS-0012 "Expected arithmetic operator"
Error Code
0012
Error Description
“Expected arithmetic operator”
SQL types
SELECT
Reasons why
Missing arithmetic operator in an expression.
Notes
An arithmetic expression must be written using operands (columns, functions and constant
values) and arithmetic operators (+, -, *, /).
Examples of error
a. SELECT A 5, [...]
^ - Expected arithmetic operator
b. [...] WHERE B 8 < C
^ - Expected arithmetic operator
12.14 SDS-0013 "Expected identifier after point"
Error Code
0013
Error Description
“Expected identifier after point”
SQL types
SELECT
Reasons why
Missing identifier after point character.
Notes
The complete notation for a column is:
<table_name>. <column_name>
If you use this notation, you must specify always an identifier after point character.
Examples of error
a. SELECT T.7 [...]
^ - Expected identifier after point
b. [...] WHERE T. + 5 > T.B
© 2014 Advanced Systems srl
Sadas Database SQL Errors
333
^ - Expected identifier after point
12.15 SDS-0014 "Expected identifier or constant value"
Error Code
0014
Error Description
“Expected identifier or constant value”
SQL types
SELECT
Reasons why
Missing identifier or constant value in an expression after an arithmetic
operator.
Notes
In an arithmetic expression, after an operand (column, function or constant value) and an
arithmetic operator, Sadas parser must encounter another sub-expression (delimited by
parenthesis) or another operand, and so an identifier or a constant value. If these things are
missing, Sadas returns this error.
Examples of error
a. [...] WHERE A + > B
^ - Expected identifier or constant value
b. SELECT A * , B [...]
^ - Expected identifier or constant value
12.16 SDS-0015 "Unknown table/view name"
Error Code
0015
Error Description
“Unknown table/view name”
SQL types
SELECT, DESCRIBE, CREATE, ALTER, DROP, LOAD, APPEND,
UPDATE, TRUNCATE, DELETE.
Reasons why
Sadas does not find in the catalog of current database/schema, a table/
view specified in SQL script.
Notes
This error refers to all parts of an SQL script in which you can specify a table/view name.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
334
Examples of error
In following examples A is an undefined table/view.
a. SELECT A.Col [...]
^ - Unknown table/view name (A)
b. [...] FROM A, [...]
^ - Unknown table/view name (A)
c. [...] WHERE A.Col > 0
^ - Unknown table/view name (A)
12.17 SDS-0016 "Unknown column name"
Error Code
0016
Error Description
“Unknown column name”
SQL types
SELECT, DESCRIBE, CREATE, ALTER, DROP, LOAD, APPEND,
UPDATE, DELETE.
Reasons why
Specified column does not exist in specified table/view.
Notes
Sadas returns this error when the column name specified does not exist in one or all table of
SQL script. You can specify a column name in two ways:
1.
simple identifier:
<column_name>
2.
complete identifier:
<table_name>. <column_name>
If you have specified a column with simple identifier, Sadas returns this error if it does not find
column in all table of FROM clause.
If you have specified a column with complete identifier, Sadas returns this error if it does not
find column in table preceding point character.
Examples of error
a. SELECT A FROM T1, T2 [...]
© 2014 Advanced Systems srl
Sadas Database SQL Errors
335
^ - Unknown column name (A)
[A does not exist in T1 and in T2]
b. SELECT T1.A FROM [...]
^ - Unknown column name (A)
[A does not exist in T1]
c. [...] WHERE T1.A > 0 [...]
^ - Unknown column name (A)
[A does not exist in T1]
d. [...] FROM T1, T2, T3 WHERE A > T2.B
^ - Unknown column name (A)
[A does not exist in T1 and in T2]
12.18 SDS-0017 "Wrong use of function TO_DATE"
Error Code
0017
Error Description
“Wrong use of function TO_DATE”
SQL types
SELECT
Reasons why
Sadas cannot convert to valid date the input string.
Notes
TO_DATE
converts char, character, varchar, date or timestamp to a value of DATE
datatype.
If string is not a DATE, Sadas returns error. The input string must have the default date format
of Sadas: ‘DD/MM/YYYY’
Examples of error
a. SELECT TO_DATE('01/XX/2000') FROM DUAL
^ - Wrong use of function TO_DATE
b. SELECT TO_DATE('01-10-2000') FROM DUAL
© 2014 Advanced Systems srl
Sadas Database SQL Errors
336
^ - Wrong use of function TO_DATE
12.19 SDS-0018 "Operands of different datatypes"
Error Code
0018
Error Description
“Operands of different datatypes”
SQL types
SELECT
Reasons why
Two operands of different datatypes are used in an expression or in a
condition.
Notes
An expression or a condition uses operands (columns, functions or constant values) only of the
same datatype. You must verify the datatypes of operands in expression or in a condition. In
the error message Sadas returns also the different datatypes and if the error is occurred in right
member of a condition.
Examples of error
In these examples A is of string datatype and B is of integer datatype.
a. SELECT A + B FROM [...]
^ - Operands of different datatypes («string» <-> «integer»)
b. [...] WHERE A + B > 0 [...]
^ - Operands of different datatypes («string» <->
«integer»)
c. [...] WHERE A > B [...]
^ - Operands of different datatypes
(«string»
<->
«integer» in right member of condition)
12.20 SDS-0019 "Exceeded the limit of the number precision"
Error Code
0019
Error Description
“Exceeded the limit of the number precision”
SQL types
CREATE, ALTER.
Reasons why
A precision number too large (limit 18) has been specified in the
definition of a column.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
337
Notes
When you specify a fixed-point number using the following form:
[type](p,s)
p
is the precision (maximum number of significant decimal digits) and s is the scale (number of
digits from the decimal point to the least significant digit). The precision can range from 1 to
18.
Example of error
CREATE TABLE T (F1 DECIMAL (20,10))
^ - Exceeded the limit of the number of
decimals
12.21 SDS-0020 "Alias name already used"
Error Code
0020
Error Description
“Alias name already used”
SQL types
SELECT
Reasons why
You have used an alias name more than once.
Notes
You can link an alias name to one identifier; if you use the same alias name for multiple
identifiers, Sadas returns this error. From this point of view, there is no difference between an
alias name used for a column and an alias name used for a table, or for others identifier types.
In the error message Sadas returns also the alias name used incorrectly.
Examples of error
a. SELECT C1 AS A, C2 AS A [...]
^ - Alias name already used (A)
b. SELECT C1 AS A FROM T AS A [...]
^ - Alias name already used (A)
c. SELECT * FROM T1 AS A, T2 AS A
^ - Alias name already used (A)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
338
12.22 SDS-0021 "Wrong use of function TO_TIMESTAMP"
Error Code
0021
Error Description
“Wrong use of function TO_TIMESTAMP”
SQL types
SELECT
Reasons why
Sadas cannot convert to valid timestamp the input string.
Notes
TO_TIMESTAMP
TIMESTAMP
converts char, character, varchar or timestamp to a value of
datatype. If string is not a TIMESTAMP, Sadas returns this error. The input string
must have the default TIMESTAMP format of Sadas: ‘DD/MM/YYYY-HH:MI:SS:MS’
Examples of error
a. SELECT TO_TIMESTAMP('01/XX/2000-12:12:03.000') FROM DUAL
^ - Wrong use of function TO_ TIMESTAMP
b. SELECT TO_TIMESTAMP('01/01-2000-12:12:03.000') FROM DUAL
^ - Wrong use of function TO_ TIMESTAMP
12.23 SDS-0022 "Illegal GROUP BY clause"
Error Code
0022
Error Description
“Illegal GROUP BY clause”
SQL types
SELECT
Reasons why
GROUP BY
clause does not satisfy Sadas grammar.
Notes
A group by clause must satisfy Sadas grammar; follow some main rules:
You can use only aggregate functions:
[COUNT, MIN, MAX, SUM, AVG, STDDEV, VARIANCE]
Each operand in SELECT clause, which is not an aggregation, must be also in GROUP BY
clause.
Each operand in GROUP BY clause must be also in SELECT clause.
Examples of error
a. SELECT A, B FROM T GROUP BY A
© 2014 Advanced Systems srl
Sadas Database SQL Errors
339
^ - Illegal GROUP BY clause
b. SELECT A FROM T GROUP BY A, B
^ - Illegal GROUP BY clause
c. SELECT A FROM T GROUP BY B
^ - Illegal GROUP BY clause
12.24 SDS-0023 "Alias name is already a column name"
Error Code
0023
Error Description
“Alias name is already a column name”
SQL types
SELECT
Reasons why
You have used an alias name, already used for a column name.
Notes
Sadas returns this error when an alias name is already present in the catalog as a column name.
In SQL script context, an alias is a new identifier; therefore it cannot be an identifier name
already present in the context. For example, alias name can be a column name of a table not
used in current SQL script. After parsing, Sadas can assign any alias name to identifiers, to
simplify the query.
Examples of error
a. SELECT A,B,C FROM T AS C
^ - Alias name is already a column name (C)
b. SELECT A,B,C as A FROM T
^ - Alias name is already a column name (A)
12.25 SDS-0024 "Illegal operation on operands"
Error Code
0024
Error Description
“Illegal operation on operands”
SQL types
SELECT
Reasons why
You have used an operator inconsistent with operands.
Notes
The arithmetic operators (*, +, /, -) are consistent only with numeric operands; the plus
© 2014 Advanced Systems srl
Sadas Database SQL Errors
340
operator (+) can be used with string. No arithmetic operators can be used with date , time or
timestamp.
In this error message Sadas returns also wrong operator and wrong datatype.
Example of error
If A and B are string columns:
SELECT A - B FROM [...]
^ - Illegal operation on operands (- <-> string)
12.26 SDS-0025 "Wrong number of parameters"
Error Code
0025
Error Description
“Wrong number of parameters”
SQL types
SELECT
Reasons why
You have used a function with wrong number of parameters.
Notes
Each function accepted by Sadas has a defined number of input parameters. If you specify a
different number of parameters, Sadas returns this error.
In this error message Sadas returns also the function name.
Examples of error
a. SELECT SUM(A,B) FROM [...]
^ - Wrong number of parameters (SUM)
b. SELECT MOD(A) FROM [...]
^ - Wrong number of parameters (MOD)
12.27 SDS-0026 "Illegal function in the context"
Error Code
0026
Error Description
“Illegal function in the context”
SQL types
SELECT
© 2014 Advanced Systems srl
Sadas Database SQL Errors
Reasons why
341
You have used an aggregate function in WHERE clause or in GROUP BY
clause.
Notes
The aggregate functions [COUNT, MAX, MIN, SUM, AVG, STDDEV, VARIANCE] cannot be used in
WHERE
clause and in GROUP BY clause.
In this error message Sadas returns also the name of the function used incorrectly.
Examples of error
a. [...] WHERE Sum(A) > 0 [...]
^ - Illegal function in the context (SUM)
b. [...] GROUP BY Count(*) [...]
^ - Illegal function in the context (COUNT)
12.28 SDS-0027 "Improper use of alias name"
Error Code
0027
Error Description
“Improper use of alias name”
SQL types
SELECT
Reasons why
You have used an alias name, already used for an operand, in FROM
clause.
Notes
The aliases are defined in SELECT and FROM clauses, so you can use these only in other clauses
of the script SQL. You can use the table aliases also as prefix of column in SELECT clause.
In this error message Sadas returns also the alias name used incorrectly.
Example of error
SELECT C AS A FROM A
^ - Improper use of alias name (A)
12.29 SDS-0028 "Unloaded table"
Error Code
© 2014 Advanced Systems srl
0028
Sadas Database SQL Errors
342
Error Description
“Unloaded table”
SQL types
SELECT
Reasons why
Specified table is not loaded and so it is not usable.
Notes
In a Sadas schema/database you cannot query a table with zero records, although this table is
defined in current schema/database. You can query the only loaded tables. This is not an error
in query structure, but it refers to the table status in current schema/database.
In this error message Sadas returns also the unloaded table name.
Example of error
In this example, T is an unloaded table.
SELECT * FROM T
^ - Unloaded table (T)
12.30 SDS-0029 "Unsupported function/operation"
Error Code
0029
Error Description
“Unsupported function/operation”
SQL types
SELECT
Reasons why
You are trying to execute a SQL script not supported by Sadas.
Notes
In SQL language of Sadas there are some limits; main limits of actual release of Sadas are:
Cyclic (b. example) or not complete (a. example) join graphs are not supported.
In join queries with explicit join clauses, involving more than two tables, the graph must
be star schema or snow flake schema (c. example).
Only equi-join is supported (d. example).
In join queries without explicit join clauses (implicit join), you must have relations
between tables only of type Foreign Key
Primary Key (e. example).
You cannot use nested queries with NOT IN clause. You can use nested queries with
IN
clause, if sub-queries are not correlated. IN and NOT IN clauses can be used with
list of constant values (g. example).
© 2014 Advanced Systems srl
Sadas Database SQL Errors
343
The form T.* is not supported in SELECT clause (h. example).
Multiple use of COUNT(*) is not allowed (i. example).
In HAVING clause you can specify only a linear sequence of conditions in AND or a linear
sequence of conditions in OR (l. example).
Sadas does not support correlated sub-queries, scalar sub-query with more than one
operand, having clause in sub-query (o. example).
Examples of error
a. SELECT * FROM T1 INNER JOIN T2 ON T1.C1 = T2.C2,
T2 INNER JOIN T1 ON T2.C2 = T1.C1
Unsupported function/operation (error in join (graph not supported))
This join generate a cyclic graph T1 -> T2 -> T1; the error occurs also in implicit join.
b. SELECT * FROM T1 INNER JOIN T2 ON T1.C1 = T2.C2,
T3 INNER JOIN T4 ON T3.C3 = T4.C4
Unsupported function/operation (error in join (graph not supported))
This join generate a not complete graph T1 -> T2--T3 -> T4; the error occurs also in implicit
join.
c. SELECT * FROM T1 INNER JOIN T2 ON T1.C1 = T2.C2,
T2 INNER JOIN T3 ON T2.C2 = T3.C3,
T2 INNER JOIN T4 ON T2.C2 = T4.C4
Unsupported function/operation (error in join (graph not supported))
This join generate a not resolvable graph: T1 -> T2 -> T3 ("snow flake")
T2 -> T4 ("star schema" with T3)
d. SELECT * FROM T1, T2 WHERE T1.C1 <> T2.C2
Unsupported function/operation (T1."C1" != T2."C2")
e. SELECT * FROM T WHERE C NOT IN (SELECT A FROM T1)
Unsupported function/operation (T NOT IN)
f. SELECT T.* FROM T [...]
© 2014 Advanced Systems srl
Sadas Database SQL Errors
344
Unsupported function/operation (T.*)
g. SELECT COUNT(*), C, [...], COUNT(*) FROM T GROUP BY C
Unsupported function/operation (COUNT(*) ... COUNT(*))
h. SELECT C,Count(*) GROUP BY C HAVING Count(*)>0 AND Count(*)<10 OR Count
(*)<>5
Unsupported function/operation (((COUNT(*) > 0) AND (COUNT(*) < 10)) OR
(COUNT(*) != 5))
i. SELECT * FROM T WHERE C IN (SELECT T.A FROM T1)
Unsupported function/operation (correlated (dynamic) sub-query)
l. SELECT * FROM T WHERE C IN (SELECT A, B, C FROM T1)
Unsupported function/operation (too many expressions in SELECT clause or
FROM clause)
m. SELECT * FROM T WHERE C IN (SELECT A FROM T1 ... HAVING ...)
Unsupported function/operation (HAVING clause in sub-query)
12.31 SDS-0030 "Wrong use of function TO_TIME"
Error Code
0030
Error Description
“Wrong use of function TO_TIME”
SQL types
SELECT
Reasons why
Sadas cannot convert to valid time the input string.
Notes
TO_TIME
converts char, character, varchar or timestamp to a value of TIME datatype.
If string is not a TIME, Sadas returns this error. The input string must have the default TIMES
format of Sadas: ‘HH:MI:SS:MS’
Examples of error
a. SELECT TO_TIME('12-12:03.000') FROM DUAL
^ - Wrong use of function TO_ TIME
© 2014 Advanced Systems srl
Sadas Database SQL Errors
345
b. SELECT TO_TIME('01/01-2000-xx:12:03.000') FROM DUAL
^ - Wrong use of function TO_ TIMESTAMP
12.32 SDS-0031 "Illegal ORDER BY clause"
Error Code
0031
Error Description
“Illegal ORDER BY clause”
SQL types
SELECT
Reasons why
ORDER BY
clause does not satisfy Sadas grammar.
Notes
An order by clause must satisfy Sadas grammar; following this main rule:
Each operand in ORDER BY clause must be also in SELECT clause.
Examples of error
SELECT A FROM T ORDER BY B
^ - Illegal ORDER BY clause
12.33 SDS-0032 "Improper use of DISTINCT clause"
Error Code
0032
Error Description
“Improper use of DISTINCT clause”
SQL types
SELECT
Reasons why
You have done an improper use of DISTINCT clause in an aggregate
function.
Notes
In an aggregate functions, DISTINCT clause can be used only in COUNT function.
In this error message Sadas returns also the function name used incorrectly.
Example of error
SELECT SUM(DISTINCT A) FROM T
^ - Improper use of DISTINCT clause (SUM)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
346
12.34 SDS-0033 "Internal error; analyze the context!"
Error Code
0033
Error Description
“Internal error; analyze the context!”
SQL types
All
Reasons why
Serious error in Parser SQL or in Optimizer of Sadas.
Notes
Sadas has encountered a unexpected situation during parsing, analyze or create access plan of a
query. You must analyze the context: script SQL, Catalog configuration, Sadas Server settings,
HW/SW system. It isn’t a query error, but a Sadas error.
12.35 SDS-0034 "GROUP BY clause required in this case"
Error Code
0034
Error Description
“GROUP BY clause required in this case”
SQL types
SELECT
Reasons why
SELECT
clause requires a GROUP BY clause.
Notes
A SQL script can have in SELECT clause column, expression, function and aggregate function.
If there are simultaneously aggregate functions and column/expression/other functions, then
GROUP BY
clause is required.
Example of error
SELECT A, Count(*) FROM T
^ - GROUP BY clause required in this case
12.36 SDS-0035 "Expected a constant positive expression in column
definition"
Error Code
0035
Error Description
“Expected a constant positive expression in column definition”
© 2014 Advanced Systems srl
Sadas Database SQL Errors
347
SQL types
CREATE, ALTER
Reasons why
Definition column parameters must be integer positive numbers.
Notes
The main definition column parameters are size, precision and scale. These parameters can be also
expressions, but must be always positive integer.
Examples of error
a. CREATE TABLE T (C CHAR (0))
^ - Expected a constant positive expression in
column definition
b. CREATE TABLE T (C CHAR (1 - 2))
^ - Expected a constant positive expression in
column definition
12.37 SDS-0036 "Invalid column description"
Error Code
0036
Error Description
“Invalid column description”
SQL types
CREATE, ALTER
Reasons why
Column description is wrong.
Notes
Column description follows these main rules:
String datatypes (CHAR, CHARACTER, VARCHAR) must not have decimals (a. example).
Integer datatypes (INT, INTEGER, SMALLINT) must not have decimals (b. example).
Numeric datatypes (NUMBER, FLOAT, REAL, FLOAT, DOUBLE PRECISION, DEC, DECIMAL,
NUMERIC)
must have number of decimals (scale) less than total size (precision) (c.
example).
CODE, DATE, TIME, TIMESTAMP
datatypes have not size and scale (d. example).
The use of a unknown datatype generates syntax error (SDS-0009) (e. example).
Examples of error
© 2014 Advanced Systems srl
Sadas Database SQL Errors
348
a. CREATE TABLE T(C CHAR(5,1))
^ - Invalid column description
b. CREATE TABLE T(I INT(5,1))
^ - Invalid column description
c. CREATE TABLE T(D DEC(5,5))
^ - Invalid column description
d. CREATE TABLE T(I CODE(5))
^ - Invalid column description
e. CREATE TABLE T (C UnTipo (5))
^ - Syntax error
12.38 SDS-0037 "Table/view already exists"
Error Code
0037
Error Description
“Table/view/synonyn already exists”
SQL types
CREATE, DUPLICATE
Reasons why
Sadas catalog cannot have two objects (table/view/synonym) with the
same name.
Notes
You are trying to create or duplicate a Sadas object (table or view) that already exists in the
catalog.
In this error message Sadas returns also the object name that already exists.
Example of error
In this example T is a table already defined.
CREATE TABLE T ([...])
^ - Table/view/synonym already exists (T)
12.39 SDS-0038 "Table/view does not exist"
Error Code
0038
Error Description
“Table/view/synonym does not exist”
© 2014 Advanced Systems srl
Sadas Database SQL Errors
SQL types
349
ALTER, DROP, LOAD, GRANT, REVOKE, DUPLICATE,
APPEND TABLE, UPDATE, TRUNCATE.
Reasons why
Sadas tries to manipulate a table/view/synonym that does not exist in
the catalog.
Notes
You are trying to manipulate a Sadas object (table or view) that does not exist in the catalog.
In this error message Sadas returns also the object name that does not exist.
Examples of error
In this example T does not exist in the catalog.
a. ALTER TABLE T ([...])
^ - Table/view/synonym does not exist (T)
b. GRANT PR_SELECT ON T TO User
^ - Table/view/synonym does not exist (T)
12.40 SDS-0039 "Invalid constraint"
Error Code
0039
Error Description
“Invalid constraint”
SQL types
CREATE, ALTER.
Reasons why
The defined constraint is not valid.
Notes
In Sadas the supported constraints are PRIMARY KEY and FOREIGN KEY. You are trying to
create a constraint that use an undefined column. You can define constraints syntactically in
two ways:
As part of the definition of an individual column or attribute. This is called inline
specification.
As part of the table definition. This is called out-of-line specification.
This error refers only to out-of-line specification.
In this error message Sadas returns also the undefined column that you are trying to use for
constraint.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
350
Examples of error
In this example A is a undefined column.
CREATE TABLE T (PRIMARY KEY (A), [...])
^ - Invalid constraint (A)
12.41 SDS-0040 "Primary key is not unique"
Error Code
0040
Error Description
“Primary key is not unique”
SQL types
CREATE, ALTER.
Reasons why
Sadas has encountered multiple primary keys in a table/view.
Notes
Sadas does not support constraints on multiple columns. This error refer to the case of multiple
columns defined as primary key.
In this error message Sadas returns also the column name for invalid primary key.
Example of error
CREATE TABLE T (A CHAR(32), PRIMARY KEY (A),
B CHAR (10) PRIMARY KEY)
^ - Primary key is not unique (B)
12.42 SDS-0041 "Table/view auto-reference through FOREIGN KEY"
Error Code
0041
Error Description
“Table/view auto-reference through FOREIGN KEY”
SQL types
CREATE, ALTER.
Reasons why
Sadas has encountered a foreign key defined on the same table.
Notes
SADAS does not support self join, so you cannot define a foreign key that references the same
table.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
351
In this error message Sadas returns also the auto-referenced table name.
Example of error
CREATE TABLE T (A CHAR (32) FOREIGN KEY REFERENCES T(A), [...]
^ - Table/view auto-reference thru FOREIGN KEY (T)
12.43 SDS-0042 "Duplicated FOREIGN KEY"
Error Code
0042
Error Description
“Duplicated FOREIGN KEY”
SQL types
CREATE, ALTER.
Reasons why
SADAS has encountered two identical foreign keys in this table.
Notes
You may define multiple foreign keys on a single column; these foreign keys must reference
different tables and different columns.
In this error message SADAS returns also the specifics of the foreign key: base column, external
table referenced, external column referenced.
Example of error
CREATE TABLE T
(A CHAR (16) FOREIGN KEY REFERENCES T1(C1)
FOREIGN KEY REFERENCES T1(C1))
^ - Duplicate FOREIGN KEY (A -> T1 / "C1")
12.44 SDS-0043 "Column isn’t a PRIMARY KEY"
Error Code
0043
Error Description
“Column isn’t a PRIMARY KEY”
SQL types
CREATE, ALTER.
Reasons why
Sadas has encountered a not primary key column referenced by a foreign
key.
Notes
© 2014 Advanced Systems srl
Sadas Database SQL Errors
352
The foreign key definition requires that the external column must be primary key in the external
table.
In this error message Sadas returns also the external table referenced and the external column
referenced.
Example of error
CREATE TABLE T
(A CHAR (16) FOREIGN KEY REFERENCES T1(C1) [...]
^ - Column isn’t a PRIMARY KEY (T1 /
"C1")
12.45 SDS-0044 "Column already exists"
Error Code
0044
Error Description
“Column already exists”
SQL types
CREATE, ALTER.
Reasons why
You are trying to create an already existing column.
Notes
This error can occur in two situations:
1. CREATE: the column already exists in preceding definitions in the same SQL create
script (a. example).
2. ALTER : the column already exists in preceding modifies in the same SQL alter script or
in modified table/view (b. example).
In this error message Sadas returns also the already existing column name.
Examples of error
a. CREATE TABLE T (A CHAR (16), B CHAR (15), A CODE)
^ - Column already exists (A)
b. ALTER TABLE T ADD(A CHAR(10) [...]
^ - Column already exists (A)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
353
12.46 SDS-0045 "Type mismatch for FOREIGN KEY"
Error Code
0045
Error Description
“Type mismatch for FOREIGN KEY”
SQL types
CREATE, ALTER.
Reasons why
The column of a foreign key, is of a different datatype of external
column.
Notes
The columns involved in a link [FOREIGN KEY
PRIMARY KEY]
must be of the same
datatype.
In this error message Sadas returns also the external table referenced and the external column
referenced.
Example of error
CREATE TABLE T
(E CHAR (1) FOREIGN KEY REFERENCES TE(CP))
^ - Type mismatch for FOREIGN KEY (TE /
"CP")
12.47 SDS-0046 "Invalid NOT STAR JOIN: SELECT clause cannot
contain fields of right table"
Error Code
0046
Error Description
“Invalid NOT STAR JOIN: SELECT clause cannot contain fields of
right table”
SQL types
SELECT.
Reasons why
The context of NOT STAR JOIN is invalid.
Notes
Sadas does not need (and does not support) the EXIST and NOT IN clause for anti-join type,
but it has an explicit special clause: NOT STAR JOIN. When you specify a NOT STAR JOIN
clause you cannot select fields from right table, because with this join type you want rows from
the left side of the predicate for which there are no corresponding rows on the right side of the
© 2014 Advanced Systems srl
Sadas Database SQL Errors
354
predicate. In error message Sadas returns also the name of roght table.
Example of error
SELECT T1.C1, T2.C2 FROM T1 NOT STAR JOIN T2 ON T1.Cj1 = T2.Cj2
^ - Invalid NOT STAR JOIN: SELECT clause cannot contain
fields of right table (T2)
12.48 SDS-0047 "The comparison value for the coded field is too
long"
Error Code
0047
Error Description
“The comparison value for the coded field is too long”
SQL types
SELECT.
Reasons why
The comparison value for the coded field is too long.
Notes
You can use CODE fields in conditions using the value of the BASE. The length of the BASE for
a CODE field is fixed and accessible in the catalog.
Example of error
In this example the BASE length for CODE field C is 2.
SELECT * FROM T WHERE C > 'ABC'
^ - The comparison value for the coded field is too long (3 > 2)
12.49 SDS-0048 "Database already exists"
Error Code
0048
Error Description
“Database already exists”
SQL types
CREATE, DUPLICATE
Reasons why
Sadas catalog cannot have two schema/databases with the same name.
Notes
You are trying to create or duplicate a Sadas schema/database that already exists in the catalog.
In this error message Sadas returns also the schema/database name that already exists.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
355
Examples of error
In this example D is a schema/database already defined.
a. CREATE DATABASE D
^ - Database already exists (D)
b. DUPLICATE DATABASE O TO D
^ - Database already exists (D)
12.50 SDS-0049 "Database does not exist"
Error Code
0049
Error Description
“Database does not exist”
SQL types
DROP, LOAD, CONNECT, TRUNCATE.
Reasons why
Sadas tries to manipulate a schema/database that does not exist in the
catalog.
Notes
You are trying to manipulate a Sadas schema/database that does not exist in the catalog.
In this error message Sadas returns also the schema/database name that does not exist.
Examples of error
In this example D does not exist in the catalog.
a. DROP DATABASE D
^ - Database does not exist (D)
b. CONNECT Utente Password @ D
^ - Database does not exist (D)
12.51 SDS-0050 "Illegal DISTINCT clause"
Error Code
0050
Error Description
“Illegal DISTINCT clause”
SQL types
SELECT.
Reasons why
Sadas has encountered an illegal DISTINCT clause on columns,
© 2014 Advanced Systems srl
Sadas Database SQL Errors
356
expressions or functions in SELECT clause.
Notes
You cannot use DISTINCT clause in main following cases:
On functions not of aggregations.
On single column or expression.
This error refers DISTINCT clause used for a operand of SELECT clause; it does not refer
general DISTINCT clause.
This error message contains a note about bad form of DISTINCT clause.
Examples of error
a. SELECT C1, DISTINCT ABS(C2) FROM T
^ - Illegal DISTINCT clause (ABS([?.]"C2"))
b. SELECT C1, DISTINCT C2 FROM T
^ - Illegal DISTINCT clause ("[?.]C2")
12.52 SDS-0051 "Too many DISTINCT clauses"
Error Code
0051
Error Description
“Too many DISTINCT clauses”
SQL types
SELECT.
Reasons why
Sadas has encountered too many DISTINCT clauses in SELECT clause.
Notes
You cannot use multiple DISTINCT clauses in SELECT clause, although these clauses are
formally correct.
Example of error
SELECT C1, DISTINCT SUM(C2), DISTINCT AVG(C3) FROM T
^ - Too many DISTINCT clauses (not unique
DISTINCT)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
357
12.53 SDS-0052 "Non executable SQL"
Error Code
0052
Error Description
“Non executable SQL”
SQL types
SELECT.
Reasons why
Sadas has encountered a SQL not yet supported.
Notes
This message reports that, in the current Sadas release, it’s not possible to execute the input
SQL script. For example, the SQL scripts needing cartesian product are not executables. These
queries are syntactically corrects, but not executable by Sadas.
Examples of error
In following query there is a cartesian product.
a. SELECT * FROM T1, T2
^ - Non executable SQL
The following query is not an implicit join for OR condition.
b. SELECT * FROM T1, T2 WHERE T1.Fk = T2.Pk AND T1.C1 > 0 OR T2.C2 > 0
^ - Non executable SQL
The following query is not an implicit join because there are too many tables in FROM clause
c. SELECT * FROM T1, T2, T1 WHERE T1.Fk = T2.Pk
^ - Non executable SQL
12.54 SDS-0053 "Illegal UNION [ALL]/INTERSECT/MINUS"
Error Code
0053
Error Description
“Illegal UNION [ALL]/INTERSECT/MINUS”
SQL types
SELECT.
Reasons why
Sadas has encountered a bad collect of SELECT queries.
Notes
You can collect multiple SELECT queries through the set operators [UNION [ALL],
INTERSECT, MINUS];
© 2014 Advanced Systems srl
the set operators must satisfy following main rules:
Sadas Database SQL Errors
358
SELECT clause and GROUP BY clause must have the same number of operands.
The corresponding operands must be of the same datatype.
You need use of parenthesis using MINUS and INTERSECT consecutively.
Examples of error
a. SELECT * FROM T1 UNION SELECT * FROM T2
^ - Illegal UNION [ALL]/INTERSECT/MINUS (different number of operands in
SELECT)
In this query C1 and C2 are not compatibles.
b.
select l_tax, l_quantity from lineitem
union all
select l_tax, l_comment from lineitem
^ - Illegal UNION [ALL]/INTERSECT/MINUS (different type in select
operands;
operand
no.
2
INTEGER
(LINEITEM.L_QUANITY)
<->
STRING
(LINEITEM.L_COMMENT))
In this query there is a single GROUP BY clause
c.
select l_tax, l_quantity from lineitem where l_quantity < 10 group by l_tax,
l_quantity
union all
select l_tax, l_quantity from lineitem where l_quantity > 10
^ - Illegal UNION [ALL]/INTERSECT/MINUS (each query must contain the
group by clause)
In this query there are MINUS and INTERSECT used consecutively
d.
select l_quantity from lineitem
minus
select l_quantity from lineitem
intersect
select l_quantity from lineitem
^ - Illegal UNION [ALL]/INTERSECT/MINUS (unable to establish priority
in
the
© 2014 Advanced Systems srl
application
of
such
opertors;
use
of
parenthesis
is
Sadas Database SQL Errors
359
compulsary)
12.55 SDS-0054 "User has no rights to execute this command"
Error Code
0054
Error Description
“User has no rights to execute this command”
SQL types
All.
Reasons why
The user connected has not proper privileges to execute the current
command.
Notes
In Sadas security there are five privilege types:
1. PR_CATALOG : CREATE TABLE, CREATE VIEW, CREATE DATABASE, ALTER,
DROP TABLE, DROP VIEW, DROP DATABASE, DUPLICATE DATABASE,
DUPLICATE TABLE.
2. PR_DESCRIBE: DESCRIBE.
3. PR_LOAD
: LOAD, APPEND, UPDATE, DELETE, EXEC STORED QUERIES.
4. PR_SECURITY: CREATE USER, DROP USER, GRANT, REVOKE.
5. PR_SELECT
SYSDBA
: SELECT.
is the Sadas system user who has all privileges.
This error refers the defined privileges for the current user.
Example of error
In this situation, the current user has not PR_SELECT privilege.
SELECT [...]
^ - User has no rights to execute this command
12.56 SDS-0055 "Wrong hidden condition"
Error Code
0055
Error Description
“Wrong hidden condition”
SQL types
SELECT.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
Reasons why
360
An hidden condition is incorrect.
Notes
Sadas allows to define hidden conditions on a table for a user, to reduce the visible data to the
user. Sadas adds these conditions in AND to user conditions, so you can find errors in hidden
conditions too. It is not possible to manage hidden conditions through SQL scripts, so, in case
of this error, you must contact the system administrator.
Example of error
In this situation there is the a wrong hidden condition (C > 0) on table T.
SELECT [...] FROM T [...]
^ - Wrong hidden condition (Unknown column name - C)
12.57 SDS-0056 "The user does not exist"
Error Code
0056
Error Description
“The user does not exist”
SQL types
CONNECT, GRANT, REVOKE, DROP USER, DESCRIBE USER,
DUPLICATE USER.
Reasons why
The specified user does not exist..
Notes
You are trying to manage a not existing user.
This error message contains also the user name not existing.
Example of error
DROP USER U
^ - The user does not exist (U)
12.58 SDS-0057 "User already exists"
Error Code
0057
Error Description
“User already exists”
© 2014 Advanced Systems srl
Sadas Database SQL Errors
361
SQL types
CREATE USER, DUPLICATE USER.
Reasons why
The specified user already exists.
Notes
You are trying to create or duplicate an user already defined in SADAS: this error message
contains also the user name already existing.
Example of error
CREATE USER U
^ - The user already exist (U)
12.59 SDS-0058 "No database available"
Error Code
0058
Error Description
“No database available”
SQL types
SELECT, CREATE TABLE, CREATE VIEW, CREATE USER,
ALTER, DROP TABLE, DROP VIEW, DROP USER, LOAD
TABLE, APPEND, UPDATE, GRANT, REVOKE, TRUNCATE,
EXECUTE STORED QUERIES, DESCRIBE.
Reasons why
The database/schema catalog is not opened for command requested.
Notes
To execute most SQL commands, you must be connected to a database/schema.
12.60 SDS-0059 "No user connected"
Error Code
0059
Error Description
“No user connected”
SQL types
All (except CONNECT).
Reasons why
The user is not connected to database/schema
Notes
To execute all commands, you must be connected to database/schema.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
362
12.61 SDS-0060 "Cannot DROP current database"
Error Code
0060
Error Description
“Cannot DROP current database”
SQL types
DROP DATABASE.
Reasons why
The user is trying to drop current database/schema.
Notes
You cannot drop the database to which you are currently connected.
This error message contains also the current database/schema name.
Example of error
In this query D is the current database/schema.
DROP DATABASE D
^ - Cannot DROP current database (D)
12.62 SDS-0061 "Division by zero"
Error Code
0061
Error Description
“Division by zero”
SQL types
SELECT.
Reasons why
Sadas has encountered a division by zero.
Notes
Sadas has encountered a division by zero during execution of query or during simplifying query;
there are two main cases:
1. A visible division by zero in SQL script (a. example).
2. A division by zero by executing a query expression (b. example).
3.
Example of error
In this query D is the current database/schema.
a. SELECT A / (3 - 2 - 1) [...]
^ - Division by zero
b. SELECT A / B [...]
^ - Division by zero
© 2014 Advanced Systems srl
Sadas Database SQL Errors
363
12.63 SDS-0062 "Wrong use of function NEXT_DAY"
Error Code
0062
Error Description
“Wrong use of function NEXT_DAY”
SQL types
SELECT.
Reasons why
Sadas has encountered a bad use of function NEXT_DAY.
Notes
NEXT_DAY
accepts in input two parameters (date , char) and returns the date of the first
weekday named by char that is later than the date date. The argument char must be a day of
the week in the date language of your session, either the full name or the abbreviation. Sadas
returns this error when char parameter is bad; this parameter must follow these main rules:
This parameter must be a constant string.
This parameter must be a valid day name (complete or short) in your language session.
Examples of error
In this example the language of the session is English.
a. SELECT NEXT_DAY('02/01/2001','TUESDAM') as "NEXT DAY"
^ - Wrong use of function NEXT_DAY
b. SELECT NEXT_DAY('02/01/2001','TM') as "NEXT DAY"
^ - Wrong use of function NEXT_DAY
12.64 SDS-0063 "LPAD/RPAD functions: the second parameter must
be a not negative integer constant"
Error Code
0063
Error Description
LPAD/RPAD function: the second parameter must be a not negative
integer constant.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad parameter (the second) in functions LPAD/
RPAD.
Notes
The second parameter of functions LPAD/RPAD must be a not negative integer constant. It
© 2014 Advanced Systems srl
Sadas Database SQL Errors
364
cannot be a column or an expression.
Example of error
SELECT LPAD(C,3 / 4) [...]
^ - LPAD/RPAD function: the second parameter must be a
not negative integer constant
12.65 SDS-0064 "LPAD/RPAD functions: the third parameter must be
a char"
Error Code
0064
Error Description
LPAD/RPAD functions: the third parameter must be a char.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad parameter (the third) in functions LPAD/
RPAD.
Notes
The third parameter of functions LPAD/RPAD must be a char. It can be a column or an
expression.
Example of error
SELECT LPAD(C,20,'ab') [...]
^ - LPAD/RPAD functions: the third parameter must be a
char
12.66 SDS-0065 "SUBSTR function accepts only not negative integer
parameters"
Error Code
0065
Error Description
SUBSTR function accepts only not negative integer parameters.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad parameter in SUBSTR function.
Notes
The second and the third parameter of SUBSTR function must not be negative integer.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
365
Example of error
SELECT substr(l_comment,-1,6) FROM lineitem
^ - SUBSTR function accepts only not negative
integer parameters
12.67 SDS-0066 "Root of a negative number"
Error Code
0066
Error Description
Root of a negative number.
SQL types
SELECT.
Reasons why
Sadas has encountered a root of a negative number.
Notes
There are two functions that can generate a root of a negative number:
1. SQRT
2. POWER
In the first case you can never do a square root of a negative number.
In the second case you cannot do a power function of a negative number when the exponent
has a fractional part.
Sadas can encounter a root of a negative number during execution of query or during
simplifying query; there are two main cases:
1. A visible root of a negative number in SQL script (a. b. example).
2. A root of a negative number by executing a query expression (c. d. example).
Examples of error
a. SELECT SQRT(-10) FROM DUAL
^ - Root of a negative number
b. SELECT POWER(-2,0.3) FROM DUAL
^ - Root of a negative number
In following examples L_TAX numeric field assumes negative values.
c. SELECT SQRT(L_TAX) FROM DUAL
© 2014 Advanced Systems srl
Sadas Database SQL Errors
366
^ - Root of a negative number
d. SELECT POWER(L_TAX,0.3) FROM DUAL
^ - Root of a negative number
12.68 SDS-0067 "Improper use of INFO/SHADOW keywords"
Error Code
0067
Error Description
Improper use of INFO/SHADOW keywords.
SQL types
DESCRIBE TABLE.
Reasons why
The user have tried to use INFO or SHADOW keywords improperly.
Notes
In DESCRIBE TABLE command you can specify two additional keywords:
1. INFO
: To obtain the loading statistic information about table.
2. SHADOW: If you change structure of a loaded table, the changes to the table are not
immediately available, but Sadas creates a copy of catalog structure of the table
(shadow table). To obtain the description of the shadow table you can use the SHADOW
keyword.
The use of these two keywords follows some main rules:
You cannot use simultaneously these two keywords (a. example).
You must use one of these keywords only after SELECT clause (b. example).
Examples of error
a. DESCRIBE INFO T1, SHADOW T2, T3
^ - Improper use of INFO/SHADOW keywords
b. DESCRIBE T1, INFO T2, T3
^ - Improper use of INFO/SHADOW keywords
12.69 SDS-0068 "Illegal HAVING clause"
Error Code
0068
Error Description
Illegal HAVING clause.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
367
SQL types
SELECT.
Reasons why
Sadas has encountered a bad HAVING clause.
Notes
In the HAVING clause you can refer only expressions or fields belonging to GROUP BY clause. In
HAVING
clause you can specify only a linear sequence of conditions in AND or a linear sequence
of conditions in OR; this limit is managed by error 0029.
Example of error
select l_quantity,sum(l_extendedprice) from lineitem
group by l_quantity having L_EXTENDEDPRICE > 0
^ - Illegal HAVING clause
(expression
inconsistent
or
not
present
in
the
query)
12.70 SDS-0069 "Illegal use of function TRANSLATE"
Error Code
0069
Error Description
Illegal use of function TRANSLATE.
SQL types
SELECT.
Reasons why
The specified parameters for TRANSLATE function are not corrects.
Notes
TRANSLATE
returns expr (first parameter) with all occurrences of each character in
from_string
(second parameter) replaced by its corresponding character in to_string (third
parameter). The second parameter must have a length equal or greater then third parameter.
Example of error
SELECT TRANSLATE(C,'ab','xyz') [...]
^ - Illegal use of function TRANSLATE
(length('ab') 2 < length('xyz') 3)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
368
12.71 SDS-0070 "Table has not a PRIMARY KEY"
Error Code
0070
Error Description
This table has not a PRIMARY KEY.
SQL types
CREATE, ALTER, UPDATE.
Reasons why
The specified table has not a PRIMARY KEY to be referenced by a
FOREIGN KEY.
Notes
In a CREATE TABLE or ALTER TABLE/VIEW commands you can specify a FOREIGN KEY,
without specify the field of the referenced table: if the referenced table has not a PRIMARY KEY,
then Sadas returns this error.
The UPDATE TABLE/<columns list> command is a load process and it is possible only on
tables with PRIMARY KEY: if you try to start an update process on table without primary key,
Sadas returns this error.
This error message contains also the table name without PRIMARY KEY.
Example of error
a. CREATE TABLE N (C CHAR (16) FOREIGN KEY REFERENCES T)
^ - This table has not a PRIMARY
KEY (T)
b. UPDATE TABLE N […]
^ - This table has not a PRIMARY KEY (N)
12.72 SDS-0071 "Database ID is wrong (<> 10 characters)"
Error Code
0071
Error Description
Database ID is wrong (<> 10 characters).
SQL types
DUPLICATE DATABASE.
Reasons why
The specified Database ID has wrong length.
Notes
In DUPLICATE DATABASE command you can specify the DATABASE ID of new database. The
© 2014 Advanced Systems srl
Sadas Database SQL Errors
DATABASE ID
369
follows these main rules:
Sadas catalog cannot contains multiple DATABASE having the same ID (error 0072).
The DATABASE ID must be of 10 characters (this error).
This error message contains also the wrong DATABASE ID.
Example of error
DUPLICATE DATABASE O TO D @ '123456789'
^ - Database ID is wrong (<> 10 characters)
(123456789)
12.73 SDS-0072 "Database ID already exists"
Error Code
0072
Error Description
Database ID already exists.
SQL types
DUPLICATE DATABASE.
Reasons why
The specified Database ID already exists.
Notes
In DUPLICATE DATABASE command you can specify the DATABASE ID of new database. The
DATABASE ID
follows these main rules:
Sadas catalog cannot contains multiple DATABASE having the same ID (this error).
The DATABASE ID must be of 10 characters (error 0071).
This error message contains also the wrong DATABASE ID.
Example of error
DUPLICATE DATABASE O TO D @ 'A123456789'
^ - Database ID already exists (A123456789)
12.74 SDS-0073 "Wrong use of function DATEADD"
Error Code
0073
Error Description
Wrong use of function DATEADD.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
370
SQL types
SELECT.
Reasons why
Sadas has encountered bad parameters in DATEADD function.
Notes
The DATEADD function syntax has these parts:
Part
Description
interval Required. String expression that is the interval you want to add. See Settings section for
values.
number Required. Numeric expression that is the number of interval you want to add. The numeric
expression can either be positive, for dates in the future, or negative, for dates in the past. If
the numeric expression has decimals or is float value, Sadas truncate the value.
date
Required. DATE, TIME or TIMESTAMP representing the datetime to which interval is
added.
Sadas returns this error when one of these parameters is wrong.
This error message contains also an error description.
Examples of error
a. SELECT DateAdd(S,1,DATE) FROM T
^ - Wrong use of function DATEADD (first parameter is not
a constant (S))
b. SELECT DateAdd('ZZ',1,DATE) FROM T
^ - Wrong use of function DATEADD (unknown interval (ZZ))
c. SELECT DateAdd('MI',1,DATE) FROM T
^ - Wrong use of function DATEADD (wrong interval value
(MI))
d. SELECT DateAdd('YY',INTDEC,DATE) FROM T
^ - Wrong use of function DATEADD (second parameter
must be an integer without decimals (INTDEC))
© 2014 Advanced Systems srl
Sadas Database SQL Errors
371
12.75 SDS-0074 "Wrong use of function DATEDIFF"
Error Code
0074
Error Description
Wrong use of function DATEDIFF.
SQL types
SELECT.
Reasons why
Sadas has encountered bad parameters in DATEDIFF function.
Notes
The DATEDIFF function syntax has these parts:
Part
Description
interval
Required. String expression that is the interval you want to use to calculate the differences
between date1 and date2. See Settings section for values.
date1,
Required. Date, time or timestamp expressions. Two dates you want to use in the
date2
calculation.
Sadas returns this error when one of these parameters is wrong.
This error message contains also an error description.
Examples of error
a. SELECT DateDiff(S,DATE_1,DATE_2) FROM T
^ - Wrong use of function DATEDIFF (first parameter is
not a constant)
b. SELECT DateDiff('ZZ',DATE_1,DATE_2) FROM T
^ - Wrong use of function DATEDIFF (unknown interval)
c. SELECT DateDiff('MI',DATE_1,DATE_2) FROM T
^ - Wrong use of function DATEADD (invalid parameter for
specified interval)
12.76 SDS-0075 "Wrong use of function DATEPART"
Error Code
0075
Error Description
Wrong use of function DATEPART.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
372
SQL types
SELECT.
Reasons why
Sadas has encountered bad parameters in DATEPART function.
Notes
The DATEPART function syntax has these parts:
Part
Description
interval Required. String expression that is the interval of time you want to return. See Settings section
for values.
date
Required. Date, time or timestamp expression you want to evaluate.
Sadas returns this error when one of these parameters is wrong.
This error message contains also an error description.
Examples of error
a. SELECT DatePart(S,DATE) FROM T
^ - Wrong use of function DATEPART (first parameter is
not a constant)
b. SELECT DatePart('ZZ',DATE) FROM T
^ - Wrong use of function DATEPART (unknown interval)
c. SELECT DatePart('MI',DATE) FROM T
^ - Wrong use of function DATEPART (invalid parameter for
specified interval)
12.77 SDS-0078 "Wrong date"
Error Code
0078
Error Description
Wrong date.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad date.
Notes
This error occurs only at run-time and when argument of function is a column. In function
© 2014 Advanced Systems srl
Sadas Database SQL Errors
373
TO_DATE Sadas tries to convert a string field in a date: Sadas returns this error when input
value is not a valid date.
Example of error
In this example l_comment is a note field
SELECT TO_TIMESTAMP(l_comment) FROM LINEITEM
^ - Wrong date
12.78 SDS-0079 "Wrong time"
Error Code
0079
Error Description
Wrong time.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad time.
Notes
This error occurs only at run-time and when argument of function is a column. In function
TO_TIME Sadas tries to convert a string field in a time: Sadas returns this error when input
value is not a valid time.
Example of error
In this example l_comment is a note field
SELECT TO_TIME(l_comment) FROM LINEITEM
^ - Wrong time
12.79 SDS-0089 "IN clause: expected constant expression"
Error Code
0089
Error Description
IN clause: expected constant expression.
SQL types
SELECT.
Reasons why
Sadas has encountered a not constant value after IN clause.
Notes
© 2014 Advanced Systems srl
Sadas Database SQL Errors
IN
374
clause, without sub-queries, allows only a list of constant values.
Example of error
SELECT * FROM T WHERE C IN ('Napoli',FIELD,'ROMA')
^ - IN clause: expected constant (FIELD)expression
12.80 SDS-0090 "TO_CHAR function: second and third parameter
must be string constants"
Error Code
0090
Error Description
TO_CHAR function: second and third parameter must be string
constants.
SQL types
SELECT.
Reasons why
Sadas has encountered bad parameters in function TO_CHAR.
Notes
In function TO_CHAR you can specify optionally the second and the third parameters. These
parameters must be constant strings.
Example of error
SELECT TO_CHAR(l_shipdate, l_comment) FROM lineitem
^ - TO_CHAR function: second and third
parameter must be string constants
12.81 SDS-0091 "TO_CHAR function: erroneous NLS description"
Error Code
0091
Error Description
TO_CHAR function: erroneous NLS description.
SQL types
SELECT.
Reasons why
Sadas has encountered bad NLS description in function TO_CHAR.
Notes
In function TO_CHAR you can specify optionally the third parameter, that represents the NLS
description. When this parameter is a constant string, Sadas tries to validate this string as a
© 2014 Advanced Systems srl
Sadas Database SQL Errors
375
NLS description.
Example of error
SELECT TO_CHAR('05/01/2007', 'YY-MM-DD', 'NLS_LANGUAGE = LATIN') FROM DUAL
^ - TO_CHAR function: erroneous
NLS description
12.82 SDS-0092 "TO_CHAR function: invalid numeric format model"
Error Code
0092
Error Description
TO_CHAR function: invalid numeric format model.
SQL types
SELECT.
Reasons why
Sadas has encountered bad numeric format model in function TO_CHAR.
Notes
In function TO_CHAR you can specify optionally the second parameter, that represents the
model for conversion. When you are converting a numeric value, Sadas tries to validate the
second parameter as a numeric model.
Examples of error
a. SELECT TO_CHAR(Num,'09XXXX') FROM T
^ - TO_CHAR function:
invalid numeric format model (09XXXX)
b. SELECT TO_CHAR(Num,'9.9EEE') FROM T
^ - TO_CHAR function:
invalid numeric format model (9.9EEE)
12.83 SDS-0093 "TO_CHAR function: invalid date/time format model"
Error Code
0093
Error Description
TO_CHAR function: invalid date/time format model.
SQL types
SELECT.
Reasons why
Sadas has encountered bad date/time format model in function
TO_CHAR.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
376
Notes
In function TO_CHAR you can specify optionally the second parameter, that represents the
model for conversion. When you are converting a date, time or timestamp value, Sadas tries to
validate the second parameter as a date/time model.
Examples of error
SELECT TO_CHAR(DATE,'DD-XX-YYYY') FROM T
^ - TO_CHAR function:
invalid date/time format model (DD-XX-YYYY)
12.84 SDS-0094 "DECODE function: default parameter must be
constant"
Error Code
0094
Error Description
DECODE function: default parameter must be constant.
SQL types
SELECT.
Reasons why
Sadas has encountered bad parameter in function TO_CHAR.
Notes
In function DECODE you can specify only expr and default parameters; in this case the
default
parameter (the second) must be a constant.
Example of error
SELECT DECODE(L_SHIPDATE,L_COMMENT) FROM LINEITEM
^ - DECODE function:
second parameter must be constant (L_COMMENT)
12.85 SDS-0095 "Scalar sub-query must return an unique value"
Error Code
0095
Error Description
Scalar sub-query must return an unique value.
SQL types
SELECT.
Reasons why
Sadas has encountered a scalar sub-query that returns more than one
value.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
377
Notes
In WHERE clause you can specify a condition that has a scalar sub-query as comparison value, so
in this case the sub-query must return one value on one row.
In the sub-query you can specify one expression with grouping function in the SELECT clause.
Examples of error
SELECT [...] FROM T WHERE C > (SELECT MAX(C1), MIN(C2) FROM T1)
^ - Scalar sub-query must return an unique value
SELECT [...] FROM T WHERE C > (SELECT C1 FROM T1)
^ - Scalar sub-query must return an unique value
SELECT [...] FROM T WHERE C > (SELECT 10 FROM DUAL)
^ - Scalar sub-query must return an unique value
12.86 SDS-0096 "Wrong DISTRIBUTE parameter"
Error Code
0096
Error Description
Wrong DISTRIBUTE parameter.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad parameter in DISTRIBUTE clause.
Notes
You can do DISTRIBUTE clause only on one date column or numeric column. There are several
configurations of parameter to construct a valid DISTRIBUTE clause. This error message
indicates also the bad parameter.
Examples of error
a. SELECT [...] DISTRIBUTE A ON (-1)
^ - Wrong DISTRIBUTE parameter
(wrong ranges number)
In this example A is not a date column.
b. SELECT [...] DISTRIBUTE A ON ('12/08/2000',10,3)
^ - Wrong DISTRIBUTE parameter
© 2014 Advanced Systems srl
Sadas Database SQL Errors
378
(type mismatch)
c. SELECT [...] DISTRIBUTE A ON (10,9,...)
^ - Wrong DISTRIBUTE parameter
(null interval)
d. SELECT [...] DISTRIBUTE A ON ('01/01/2007',12,1,'mese')
^ - Wrong DISTRIBUTE parameter
(unknown date descriptor)
12.87 SDS-0097 "Illegal DISTRIBUTE clause"
Error Code
0097
Error Description
Illegal DISTRIBUTE clause.
SQL types
SELECT.
Reasons why
DISTRIBUTE
clause does not satisfy Sadas grammar.
Notes
A DISTRIBUTE clause must satisfy Sadas grammar and follow some main rules:
You can use only following aggregate functions:
[COUNT, MIN, MAX, SUM, AVG]
Each operand in SELECT clause, which is not an aggregation, must be also in GROUP BY
clause.
Each operand in GROUP BY clause must be also in SELECT clause.
You can specify only one operand in SELECT clause, that is not an aggregation.
Examples of error
a. SELECT A, B FROM T DISTRIBUTE A
^ - Illegal DISTRIBUTE clause
b. SELECT A, B FROM T DISTRIBUTE A, B
^ - Illegal DISTRIBUTE clause
c. SELECT A FROM T DISTRIBUTE B
^ - Illegal DISTRIBUTE clause
© 2014 Advanced Systems srl
Sadas Database SQL Errors
379
12.88 SDS-0098 "Too many DISTRIBUTE column ranges"
Error Code
0098
Error Description
Too many DISTRIBUTE column ranges.
SQL types
SELECT.
Reasons why
DISTRIBUTE
clause specify too many ranges referred to column.
Notes
You cannot specify in DISTRIBUTE clause a number of ranges greater than the number of
distinct values of the column.
Example of error
In this example A column has only 10 distinct values.
SELECT [...] DISTRIBUTE A ON (20)
^ - Too many DISTRIBUTE column ranges
12.89 SDS-0099 "Wrong DISTRIBUTE parameter configuration"
Error Code
0099
Error Description
Wrong DISTRIBUTE parameter configuration.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad set of parameters in DISTRIBUTE clause.
Notes
The set of parameters in DISTRIBUTE clause does not satisfy Sadas grammar.
Examples of error
a. SELECT [...] DISTRIBUTE A ON ('01/01/2007')
^ - Wrong DISTRIBUTE parameter
configuration (type mismatch)
b. SELECT [...] DISTRIBUTE A ON (1,10,11,20,21)
^ - Wrong DISTRIBUTE parameter
configuration (wrong ranges number)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
380
12.90 SDS-0100 "Too many DISTRIBUTE ranges"
Error Code
0100
Error Description
Too many DISTRIBUTE ranges.
SQL types
SELECT.
Reasons why
DISTRIBUTE
clause specifies too many ranges.
Notes
The total number of ranges cannot overcome a fixed parameter in server settings.
On 32 bit server this limit is 8192. On 64 bit server this limit is 65536.
12.91 SDS-0101 "Wrong timestamp"
Error Code
0101
Error Description
Wrong timestamp.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad timestamp.
Notes
This error occurs only at run-time and when argument of function is a column. In function
TO_TIMESTAMP Sadas tries to convert a string field in a timestamp: Sadas returns this error
when input value is not a valid timestamp.
Example of error
In this example l_comment is a note field
SELECT TO_TIMESTAMP(l_comment) FROM LINEITEM
^ - Wrong timestamp
12.92 SDS-0102 "STAR operand not supported in this context"
Error Code
0102
Error Description
STAR operand not supported in current query.
SQL types
SELECT.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
Reasons why
381
Sadas has encountered a not supported use of STAR operand.
Notes
This error occurs when you try to use STAR operand in a query that contains a sub-query in
FROM
clause.
Example of error
select l_tax from (select * from lineitem)
^ - STAR operand not supported in this context
12.93 SDS-0103 "Too many elements in update list"
Error Code
0103
Error Description
Too many elements in update list.
SQL types
UPDATE.
Reasons why
Sadas has encountered too many columns to update.
Notes
This error occurs when you try to update simultaneously more than 256 columns.
12.94 SDS-0104 "Illegal use of an aggregate function"
Error Code
0104
Error Description
Illegal use of an aggregate function.
SQL types
UPDATE.
Reasons why
SADAS has encountered an aggregate function in an UPDATE script.
Notes
This error occurs when you use an aggregate function in an UPDATE
script.
Example
update lineitem set l_quantity = sum(l_tax)
^ - Illegal use of aggregate function
© 2014 Advanced Systems srl
Sadas Database SQL Errors
382
12.95 SDS-0105 "UPDATE is not allowed on primary key"
Error Code
0105
Error Description
UPDATE is not allowed on primary key.
SQL types
UPDATE.
Reasons why
SADAS has encountered a primary key in an UPDATE set list.
Notes
This error occurs when you try to update a primary key.
Example of error
update orders set l_orderkey = 10
^ - UPDATE not allowed on primary key
12.96 SDS-0106 "User domain does not exist"
Error Code
0106
Error Description
“User domain” does not exist.
SQL types
CREAT USER.
Reasons why
Sadas has encountered an invalid domain name.
Notes
This error occurs when you try to add a user to a domain that does not exist.
Example of error
create user SMITH@ADVVSYS
^ - User domain does not exist
12.97 SDS-0107 "Domain not enabled for user"
Error Code
0107
Error Description
Domain not enabled for user.
SQL types
CREAT USER.
Reasons why
Sadas has encountered an invalid privilege on domain.
Notes
This error occurs when you try to manipulate users of a domain not allowed to your userid.
Example of error
© 2014 Advanced Systems srl
Sadas Database SQL Errors
383
create user SMITH@ADVSYS
^ - Domain not enabled for user
12.98 SDS-0108 "RATIO_TO_REPORT function: parameter must be a
column"
Error Code
0108
Error Description
RATIO_TO_REPORT function: parameter must be a column name.
SQL types
SELECT.
Reasons why
Sadas must encounter only a column in function parameter.
Notes
This error occurs when you try to use this function with bad parameters.
Example of error
Select ratio_to_report(l_quantity+10) from lineitem
^ - RATIO_TO_REPORT function:
parameter must be a column (l_quantity+10)
12.99 SDS-0109 "VSIZE function: parameter must be a column"
Error Code
0109
Error Description
VSIZE function: parameter must be a column.
SQL types
SELECT.
Reasons why
Sadas must encounter only a column in function parameter.
Notes
This error occurs when you try to use this function with bad parameters.
Example of error
Select vsize(l_quantity+10) from lineitem
^ - VSIZE function:
parameter must be a column (l_quantity+10)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
384
12.100SDS-0110 "TO_NUMBER function: unable to convert the string"
Error Code
0110
Error Description
TO_NUMBER function: unable to convert the string.
SQL types
SELECT.
Reasons why
Sadas has encountered an invalid string in function parameter.
Notes
This error occurs when you try to convert to number an invalid string.
Example of error
select to_number('10r10') from dual
^ - TO_NUMBER function: unable to convert the string
12.101SDS-0111 "Invalid numeric value for the function"
Error Code
0111
Error Description
Invalid numeric value for the function.
SQL types
SELECT.
Reasons why
Sadas has encountered a bad numeric parameter in the function.
Notes
This error occurs when you pass an invalid numeric parameter to following functions:
BIN_TO_NUM, ASIN, ACOS, BITAND, BITOR, BITXOR.
Example of error
select bin_to_num(1,2) from dual
^ - Invalid numeric value for the function
© 2014 Advanced Systems srl
Sadas Database SQL Errors
385
12.102SDS-0112 "UPDATE not allowed on column ROWID"
Error Code
0112
Error Description
UPDATE not allowed on column ROWID.
SQL types
UPDATE.
Reasons why
Sadas has encountered the ROWID pseudocolumn in fields list to
update in UPDATE statement.
Notes
This error occurs when you try to update the ROWID pseudocolumn.
Example of error
update table set rowid = 10;
^ - UPDATE not allowed on column ROWID.
12.103SDS-0113 "Wrong use of function SUBSTITUTE_WITH"
Error Code
0113
Error Description
Wrong use of function SUBSTITUTE_WITH.
SQL types
SELECT, UPDATE.
Reasons why
Sadas has encountered bad parameters in SUBSTITUTE_WITH function.
Notes
The SUBSTITUTE_WITH function accepts as first parameter only a constant of char type.
Example of error
update table set name = SUBSTITUTE_WITH(10);
^ - Wrong use of function SUBSTITUTE_WITH.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
386
12.104SDS-0114 "Domain already exists"
Error Code
0114
Error Description
“Domain already exists”
SQL types
CREATE, RENAME.
Reasons why
Sadas catalog cannot have two domains with the same name.
Notes
You are trying to create or duplicate a Sadas domain of users that already exists.
In this error message Sadas returns also the domain name that already exists.
Examples of error
In this example D is a domain already defined.
a. CREATE DOMAIN D
^ - Domain already exists (D)
b. DUPLICATE DATABASE O TO D
^ - Domain already exists (D)
12.105SDS-0115 "Domain does not exist"
Error Code
0115
Error Description
“Domain does not exist”
SQL types
DROP, RENAME.
Reasons why
Sadas tries to manipulate a domain that does not exist.
Notes
You are trying to manipulate a Sadas domain of users that does not exist in the catalog.
In this error message Sadas returns also the domain name that does not exist.
Examples of error
In this example D does not exist.
a. DROP DOMAIN D
^ - Domain does not exist (D)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
387
12.106SDS-0116 "LIKE works only on alphanumeric columns"
Error Code
0116
Error Description
“LIKE works only on alphanumeric columns”
SQL types
SELECT.
Reasons why
You are writing a LIKE predicate using in the left part a not
alphanumeric column
or expression.
Notes
You are writing a LIKE predicate using in the left part a not alphanumeric column or
expression. In this error message Sadas returns also the column/expression name that you are
using.
Examples of error
In this example L_Quantity is a numeric column.
a. SELECT * FROM LINEITEM WHERE L_QUANTITY LIKE '10'
^
-
LIKE
works
only
on
alphanumeric
columns
(LINEITEM.L_QUANTITY)
12.107SDS-0117 "Operands of different datatypes in between"
Error Code
0117
Error Description
“Operands of different datatypes in between”
SQL types
SELECT.
Reasons why
You are writing a BETWEEN predicate using wrong datatype in right
values.
Notes
You are writing a BETWEEN predicate using a datatype not equal to left column datatype in
right values. In this error message Sadas returns also the datatype and the wrong value that you
are using.
Examples of error
In this example L_Quantity is a numeric column.
a. select * from lineitem where l_quantity between 1 and '10'
© 2014 Advanced Systems srl
Sadas Database SQL Errors
388
^ - Operands of different datatypes in between (INTEGER <-> STRING
('10'))
12.108SDS-0118 "IN clause: operands of different datatypes in the list
of constants"
Error Code
0118
Error Description
“IN clause: operands of different datatypes in the list of constants”
SQL types
SELECT.
Reasons why
You are writing a static IN predicate using wrong datatype in right
values.
Notes
You are writing a IN predicate using a datatype not equal to left column datatype in right
values. In this error message Sadas returns also the datatype, the position in the list and the
wrong value that you are using.
Examples of error
In this example L_Quantity is a numeric column.
a. select * from lineitem where l_quantity in( 1,'12' )
^ - IN clause: operands of different datatypes in the list of
constants
(INTEGER (1) <-> STRING('12'))
b. select * from lineitem where l_quantity in( '10','12' )
^ - IN clause: operands of different datatypes in the list of
constants
(INTEGER (LINEITEM.L_QUANTITY) <-> STRING('10'))
12.109SDS-0119 "Join graph not supported"
Error Code
0119
Error Description
“Join graph not supported”
SQL types
SELECT.
Reasons why
You are trying to do a join on a not supported tables schema.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
389
Notes
You are trying to do a join on a not supported tables schema. Sadas supports:
in implcit join Star Schema and Snow Flake Schema
in explicit join Star Schema and Concatenation (a single branch of Snow Flake Schema)
In this error message Sadas returns also the wrong schema that you are trying to use.
Examples of error
In this example there are two pairs of tables [(tributi,anagrafica) and (cartelle,notifica)] that are
not linked by a join condition, so the schema is incomplete.
a. select "codice fiscale", nome
from tributi, anagrafica, cartelle, notifica
where tributi."codice fiscale"=anagrafica."codice fiscale"
and cartelle."codice fiscale"=notifica."codice fiscale"
^ - Join graph not supported (INCOMPLETE)
12.110SDS-0120 "Cannot use columns of code type as terms of an
expressions"
Error Code
0120
Error Description
“Cannot use columns of code type as terms of an expressions”
SQL types
SELECT.
Reasons why
You are trying to use a code column as term of an expression.
Notes
You are trying to use a code column as term of an expression.
In this error message Sadas returns also the code column name.
Examples of error
In this example SESSO is a code column.
a. select sesso || 'Ok' from anagrafica
^ - Cannot use columns of code type as terms of an expressions
(ANAGRAFICA.SESSO)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
390
12.111SDS-0121 "Illegal identifier: the first character must be a letter"
Error Code
0121
Error Description
“Illegal identifier: the first character must be a letter”
SQL types
All.
Reasons why
You are writing an identifier starting with a numeric digit.
Notes
You are writing an identifier (column name, table name, etc...) starting with a numeric digit.
In this error message Sadas returns also the wrong identifier name.
The name of identifiers can be of two types:
1. traditional: it can contain only following characters
'A'..'Z', 'a'..'z', '0'..'9' and '_';
the first character cannot be '0'..'9' and '_'.
2. extended: it can contain only following characters
'A'..'Z', 'a'..'z', '0'..'9', '_', ' '
(blank), ''', '-' and '.';
delimited by double quotes; an extended identifier name cannot contain in double
quotes all blank characters or empty string.
Sadas error message indicates the part of illegal identifier name preceding invalid character
Examples of error
select 00AB from lineitem
^ - Illegal identifier: the first character must be a letter
(00B...)
12.112SDS-0122 "Null identifier"
Error Code
0122
Error Description
“Null identifier”
SQL types
All
Reasons why
Sadas parser has encountered a null identifier name.
Notes
The name of identifiers can be of two types:
© 2014 Advanced Systems srl
Sadas Database SQL Errors
391
1. traditional: it can contain only following characters
'A'..'Z', 'a'..'z', '0'..'9' and '_';
the first character cannot be '0'..'9' and '_'.
2. extended: it can contain only following characters
'A'..'Z', 'a'..'z', '0'..'9', '_', ' '
(blank), ''', '-' and '.';
delimited by double quotes; an extended identifier name cannot contain in double
quotes all blank characters or empty string.
Examples of error
SELECT "" [...]
^ - Null identifier (")
12.113SDS-0123 "Column not found in the sub-query of the FROM
clause"
Error Code
0123
Error Description
“Column not found in the sub-query of the FROM clause”
SQL types
SELECT
Reasons why
Sadas parser haven't found a column in sub-query.
Notes
Sadas parser haven't found a column in sub-query column list of the FROM clause.
Examples of error
SELECT TAX FROM (SELECT L_TAX FROM LINEITEM)
^ - Column not found in the sub-query of the FROM clause (TAX)
12.114SDS-0124 "Too much tables in DELETE statement"
Error Code
0124
Error Description
“Too much tables in DELETE statement”
SQL types
DELETE, DELETE KEYS.
Reasons why
Sadas parser haven't found more than one table in DELETE statement.
Notes
© 2014 Advanced Systems srl
Sadas Database SQL Errors
392
Sadas parser haven't found more than one table in DELETE statement.
In this error message Sadas returns also the number of tables that you are using.
Examples of error
DELETE ORDERS, LINEITEM
^ - Too much tables in DELETE statement (2)
12.115SDS-0125 "Not supported syntax for CREATE VIEW statement"
Error Code
0125
Error Description
“Not supported syntax for CREATE VIEW statement”
SQL types
CREATE VIEW.
Reasons why
You are using a standard syntax to create a table without sub-query.
Notes
You are using a standard syntax to create a table without sub-query.
In SADAS you can create a view only using sub-query, withouth field specifications.
Examples of error
CREATE VIEW MY_VIEW (C1 CHAR(10))
^ - Not supported syntax for CREATE VIEW statement
12.116SDS-0126 "Cannot nest more group functions"
Error Code
0126
Error Description
“Cannot nest more group functions”
SQL types
SELECT.
Reasons why
You are nesting more than one group function.
Notes
You cannot nest more than one group function.
Examples of error
SELECT SUM(AVG(L_QUANTITY)) FROM LINEITEM
^ - Cannot nest more group functions
© 2014 Advanced Systems srl
Sadas Database SQL Errors
393
12.117SDS-0127 "In DUAL SELECT following clause is not allowed"
Error Code
0127
Error Description
“In DUAL SELECT following clause is not allowed”
SQL types
SELECT.
Reasons why
You are using wrong clause in DUAL select.
Notes
In DUAL select you cannot use WHERE, GROUP BY and ORDER BY clauses.
Examples of error
select 'region' as cx from dual group by cx
^ - In DUAL SELECT following clause is not allowed (GROUP
BY)
12.118SDS-0128 "UPDATE: group functions are not allowed on right
part"
Error Code
0128
Error Description
“UPDATE: group functions are not allowed on right part”
SQL types
UPDATE.
Reasons why
You are using a group function in UPDATE statement.
Notes
In UPDATE statement you cannot use group functions on right part of SET clause.
Example of error
update lineitem set l_quantyty = sum(1000)
^ - UPDATE: group functions are not allowed on right part (sum
(1000))
12.119SDS-0129 "TRUNC/ROUND: exceeded the limit of decimals"
Error Code
0129
Error Description
“TRUNC/ROUND: exceeded the limit of decimals”
SQL types
SELECT.
© 2014 Advanced Systems srl
Sadas Database SQL Errors
Reasons why
394
Too much decimals in the second parameter of Round or Trunc
function.
Notes
In Round and Trunc functions you can specify in the second parameter the number of decimal
that you want in the display format. The maximum is 10.
Example of error
select round(10.123,120) from dual
^ - TRUNC/ROUND: exceeded the limit of decimals (120 >
10)
12.120SDS-0130 "DELETE KEYS statement is not allowed on a view"
Error Code
0130
Error Description
“DELETE KEYS statement is not allowed on a view”
SQL types
DELETE KEYS.
Reasons why
You are trying a DELETE KEYS on a view.
Notes
In SADAS you cannot make a DELETE KEYS command on a view
Example of error
In this query V_Test is a view
delete keys from V_Test
^ - DELETE KEYS statement is not allowed on a view
12.121SDS-0131 "Internal error; undefined type; analyze the context!"
Error Code
0131
Error Description
“Internal error; undefined type; analyze the context!”
SQL types
All
Reasons why
Serious error in Parser SQL or in Optimizer of Sadas.
Notes
Sadas has encountered a unexpected situation during analyzing or calculating expressions. You
© 2014 Advanced Systems srl
Sadas Database SQL Errors
395
must analyze the context: script SQL, Catalog configuration, Sadas Server settings, HW/SW
system. It isn’t a query error, but a unexpected Sadas error.
12.122SDS-0132 "External function not found in Catalog"
Error Code
0132
Error Description
“External function not found in Catalog”
SQL types
SELECT
Reasons why
External function not found or loaded in Catalog.
Notes
Sadas cannot find an external function for one of these reasons:
- the dynamic library (.DLL, .so, etc..) is not defined in Sadas Catalog
- the dynamic library doesn't exist
- the dynamic library doesn't export the called function
12.123SDS-0133 "External function needs in the first parameter an
alphanumeric constant (FunctionId)"
Error Code
0134
Error Description
“External function error”
SQL types
SELECT
Reasons why
Error of the function of an external function
Notes
The call to the internal function (FunctionId) of an external function has returned an error
12.125SDS-0135 "Function not available in this Sadas version"
Error Code
0135
Error Description
“Function not available in this Sadas version”
SQL types
SELECT
© 2014 Advanced Systems srl
Sadas Database SQL Errors
Reasons why
396
Current Sadas version does not contain specified version
Notes
You must contact your seller for a Sadas version that contains the specified function.
12.126SDS-0136 "Data are not compatible with the Server"
Error Code
0136
Error Description
“Data are not compatible with the Server”
SQL types
CONNECT DB
Reasons why
Data of tables are not compatible with the current Server.
Notes
Data of tables are not compatible with the working Server, because you are trying to use data
loaded in an another environment (32-bit, 64-bit, Little Endian, Big Endian, etc...)
12.127SDS-0137 "Wrong number of columns in the sub-query of the
FROM clause"
Error Code
0137
Error Description
“Wrong number of columns in the sub-query of the FROM clause”
SQL types
LOAD, APPEND, REWRITE
Reasons why
Wrong number of columns in the sub-query of the FROM clause.
Notes
When you use a LOAD/APPEND/REWRITE TABLE ... FROM SELECT ... you must specify the
same number of columns in extern-query and sub-query.
Example of error
load table region from (select colopr from product)
^ - Wrong number of columns in the sub-query of the
FROM clause (1)
© 2014 Advanced Systems srl
Sadas Database SQL Errors
397
12.128SDS-0138 "INSERT: wrong number of constants"
Error Code
0138
Error Description
“INSERT: wrong number of constants”
SQL types
INSERT
Reasons why
Wrong number of constants in INSERT statement.
Notes
You can use two types of INSERT statement, with or withouth list of columns. When you omit
list of columns, SADAS considers all columns (not multi-field) of table. In both cases you must
specify the same number of constants, in VALUES clause, of number of columns.
Examples of error
insert into ttime (timeidpk,year,month,week,day) values (99,99,99,99)
^
Wrong
number of constants
insert into ttime values (99,99,99,99)
^ - Wrong number of constants
12.129SDS-0139 "INSERT: wrong type of a constant"
Error Code
0139
Error Description
“INSERT: wrong type of a constant”
SQL types
INSERT
Reasons why
Wrong type of a constant in INSERT statement.
Notes
In the constant list of a INSERT statement you have wrote a constant of a type not equal to
the type of the corresponding column.
Examples of error
insert into ttime (timeidpk,year,month,week,day) values (99,99,'99',99,99)
^ - Wrong type
of a constant
© 2014 Advanced Systems srl
Sadas Database SQL Errors
398
12.130SDS-0140 "Table locked"
Error Code
0140
Error Description
“Table locked”
SQL types
ALL
Reasons why
Table is locked.
Notes
You are trying to use a table that is locked by a system administrator user.
12.131SDS-0141 "DIGITS function allows only one integer column"
Error Code
0141
Error Description
“DIGITS function allows only one integer column”
SQL types
SELECT
Reasons why
DIGITS function allows only one integer column.
Notes
You are trying to use DIGITS function with an expression as argument.
© 2014 Advanced Systems srl
Part
XIII
How to Read Syntax Diagrams
13
400
How to Read Syntax Diagrams
This chapter describes how to read syntax diagrams.
This reference presents Sadas SQL syntax in both graphic diagrams and in text (Backus-Naur
Form—BNF). This chapter contains these sections:
Graphic Syntax Diagrams
Backus-Naur Form Syntax
13.1
Graphic Syntax Diagrams
Syntax diagrams are drawings that illustrate valid SQL syntax. To read a diagram, trace it from
left to right, in the direction shown by the arrows.
Commands and other keywords appear in UPPERCASE inside rectangles. Type them exactly
as shown in the rectangles. Parameters appear in lowercase inside ovals. Variables are used for
the parameters. Punctuation, operators, delimiters, and terminators appear inside circles.
If the syntax diagram has more than one path, then you can choose any path. For example, in
the following syntax you can specify either SHADOW or INFO:
If you have the choice of more than one keyword, operator, or parameter, then your options
appear in a vertical list. For example, in the following syntax diagram, you can specify one or
more of the five parameters:
© 2014 Advanced Systems srl
How to Read Syntax Diagrams
401
The following table shows some parameters that appear in the syntax diagrams and provides
examples of the values you might substitute for them in your statements:
Ta ble - Sy nt a x Pa ra me t e rs
Parameter Description
Examples
table
The substitution value must be the name of a table.
employees
The substitution value must be the name of a view.
v_employees
table_name
view
view_name
c
The substitution value must be a single character from 7-bit ASCII T
character set.
'text'
s
The substitution value must be a text string in single quotation 'Employee records'
marks.
char
The substitution value must be an expression of datatype CHAR, last_name
CHARACTER, VARCHAR or a character literal in single quotation 'Smith'
marks.
condition
The substitution value must be a condition that evaluates to TRUE last_name >'A'
or FALSE..
date
The substitution value must be a date constant or an expression of TO_DATE
d
DATE datatype.
expr
The substitution value can be an expression of any datatype as salary + 1000
defined in the syntax description of expr in “About SQL
Expression” chapter.
© 2014 Advanced Systems srl
('01/01/2002')
How to Read Syntax Diagrams
402
Parameter Description
integer
Examples
The substitution value must be an integer as defined by the syntax 72
description of integer in “Integer Literals” chapter.
number
The substitution value must be an expression of NUMBER datatype AVG(salary)
m
or a number constant as defined in the syntax description of number 15 * 7
n
in “Numeric Literals” chapter.
subquery
The substitution value must be a SELECT statement that will be SELECT last_name
db_name
used in another SQL statement.
FROM employees
The substitution value must be the name of a database.
sales_db
13.1.1 Required Keywords and Parameters
Required keywords and parameters can appear singly or in a vertical list of alternatives. Single
required keywords and parameters appear on the main path, which is the horizontal line you are
currently traveling. In the following example, db_name is a required parameter:
drop_database::=
If there is a database named DB_LIB, then, according to the diagram, the following statement is
valid:
DROP DATABASE DB_LIB
If multiple keywords or parameters appear in a vertical list that intersects the main path, then
one of them is required. You must choose one of the keywords or parameters, but not
necessarily the one that appears on the main path. In the following example, you must choose
one of the two ways:
© 2014 Advanced Systems srl
How to Read Syntax Diagrams
403
13.1.2 Optional Keywords and Parameters
If keywords and parameters appear in a vertical list above the main path, then they are
optional. In the following example, instead of traveling down a vertical line, you can continue
along the main path:
According to the diagrams, all of the following statements are valid:
CREATE TABLE …;
CREATE GLOBAL TEMPORARY TABLE …;
13.1.3 Syntax Loops
Loops let you repeat the syntax within them as many times as you like. In the following
example, after choosing one column definition, you can go back repeatedly to choose another,
separated by commas.
© 2014 Advanced Systems srl
How to Read Syntax Diagrams
404
13.1.4 Multipart Diagrams
Read a multipart diagram as if all the main paths were joined end to end. The following
example is a two-part diagram:
13.2
Backus-Naur Form Syntax
Each graphic syntax diagram in this reference is preceded by a text description of the graphic.
The text descriptions consists of a simple variant of Backus-Naur Form (BNF) that includes
the following symbols and conventions:
Symbol or
Convention
Meaning
[]
Brackets enclose optional items.
© 2014 Advanced Systems srl
How to Read Syntax Diagrams
405
Symbol or
Convention
Meaning
<>
Parameters list.
{}
Braces enclose items only one of which is required.
|
A vertical bar separates alternatives within brackets or braces.
delimiters
Delimiters other than brackets, braces, vertical bars, and ellipses must be
entered as shown.
boldface
Words appearing in boldface are keywords. They must be typed as shown.
(Keywords are case-sensitive in some, but not all, operating systems.) Words
that are not in boldface are placeholders for which you must substitute a name
or value.
© 2014 Advanced Systems srl
406
Index
-00001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
326
326
327
327
328
328
329
329
330
331
331
332
332
333
333
334
335
336
336
337
338
338
339
339
340
340
341
341
342
344
345
345
346
346
346
347
348
348
349
350
350
351
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0078
0079
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
351
352
353
353
354
354
355
355
356
357
357
359
359
360
360
361
361
362
362
363
363
364
364
365
366
366
367
368
368
369
369
371
371
372
373
373
374
374
375
375
376
376
377
378
379
379
380
380
407
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0134
0135
0136
0137
0138
0139
0140
0141
380
381
381
382
382
382
383
383
384
384
385
385
386
386
387
387
388
388
389
390
390
391
391
392
392
393
393
393
394
394
395
395
395
396
396
397
397
398
398
-AABS
48, 54
ACOS
54
ADD
178, 311
add column clauses
178
ADD_MONTHS
50, 55
Aggregate
53
Aggregate Functions
53
AGGREGATION
393
Alias name already used
337
Alias name is already a column name
339
ALL
164, 166, 209, 245, 270, 275, 296, 311
Alphanumeric
154
ALTER
177, 183
ALTER TABLE
159, 178, 311
ALTER USER
183
ALTER VIEW
185, 311
AND
145, 146, 147, 148, 153
AND Truth Table
148
Antijoins
169
APPEND TABLE
186, 311
Arithmetic
43
Arithmetic Operators
43
AS
196, 198, 200, 206, 235, 275
ASC
275
ASCII 29, 50, 56
ASCII Character Set
29
ASIN
56
ATAN
57
AVG
53, 57, 392
-BBackus-Naur
404
Backus-Naur Form Syntax
Between
145, 153, 387
BIN_TO_NUM
58
Binary
42
Binary Operators
42
BITAND
59
BITOR
59
BITXOR
60
Blank-Padded
29
400
-CCannot DROP current database
362
Cannot nest more group functions
392
Cartesian product
169
CASCADE
211, 213
Case Expressions
138
Case Sensitivity
152
CEIL
48, 61
CEILING
48, 61
408
CHAR
23, 25, 28, 29, 49
CHARACTER
23, 25, 28, 29, 49
Character Functions
49, 50
CHR
49, 62
Code
23, 28, 116, 125, 154, 389
COLUMN
137, 178, 188, 200, 253, 261, 305
Column already exists
352
column clauses
178
column definition
178, 200
Column isn’t a PRIMARY KEY
351
Column not found in the sub-query of the FROM
clause
391
COLUMNS
234
COMMENT 188, 190
Comments
35
Comparison Conditions
144
Compound Conditions
144, 155
Compound Expressions
135, 138
CONCAT 62
Concatenation
44
Concatenation Operators
44
CONDITION
400
Conditions
144, 145, 146, 147, 148, 150
CONNECT 191, 311
CONNECT SYSDBA
191, 311
constant
137
CONSTRAINT 159, 178
constraint clauses
178
Conversion Functions
51
Correlated Subquery
174
COS
63
COSH
63
COUNT 53, 64
COUNT DISTINCT 53
CREATE
177, 193, 194, 195, 196, 198, 199, 200,
204, 206, 392
CREATE DATABASE
193, 311
CREATE DBADMIN
194
CREATE DOMAIN
195
CREATE EXPRESSION
196
CREATE INDEX 198
CREATE SYNONYM
199
CREATE TABLE
159, 178, 200
CREATE USER
204, 311
CREATE VIEW
206, 392
CTL
213
CURDATE
65, 114
CURRENT_DATE
50, 65
CURRENT_TIME
50, 65
CURRENT_TIMESTAMP
50, 66
CURTIME
66, 115
Cyclic
388
-DData are not compatible with the Server
396
Data Definition Language
177
Data Manipulation Language
177, 178
DATABASE
20, 36, 208, 209, 230, 240, 254, 263,
267, 272, 295, 298
Database already exists
354
Database does not exist
355
Database ID already exists
369
Database ID is wrong (<> 10 characters)
368
DATATYPE
22, 23, 25, 27, 28, 29, 178, 200
DATE
23, 27, 28, 35, 50, 154
DATE_TO_JULIAN
72, 86
DATEADD
50, 66
DATEDIFF
50, 68
DATEPART 50, 70
DATETIME
27, 28, 35
Datetime Expressions
135, 140
Datetime Functions
50
Datetime Literals
35
DAY
27, 28
DAYNAME
50, 72
DAYOFWEEK
50, 73
DAYOFYEAR
74
DAYOFYEAR4
50
days
183, 204
DB
20, 191, 193
DB NAME
191, 193
DDL
159, 177
DEACTIVATE
208, 209
DEACTIVATE DATABASE
208, 209
DEACTIVATE TABLE
208, 209
DEC
400
DEC
23, 25, 28
DECIMAL
400
DECIMAL
23, 25, 28
DECIMALS
393
DECODE
52, 75
DECODE function: default parameter must be
constant
376
DELETE
178, 209, 211, 311, 391, 394
DELETE KEYS
213, 311, 391, 394
409
DELETE KEYS statement is not allowed on a view
394
DELETE STORED QUERIES
209, 311
DELETE TABLE
211
DESC
215, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 275, 311
DESC SYSALLCOLUMNS
218
DESC SYSDB
219
DESC SYSDOMAINS
220
DESC SYSFOREIGNKEYS
159, 221
DESC SYSKEYS
159, 221
DESC SYSLOG
222
DESC SYSOBJECTS
223
DESC SYSSYNONYMS
224
DESC SYSTABLES
225
DESC SYSUSERS
226
DESC SYSVIEWS
227
DESC USER
228
DESCR
215, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 311
DESCRIBE
215, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 311
DESCRIBE STORED QUERIES
217
DESCRIBE SYSALLCOLUMNS
218
DESCRIBE SYSDB
219
DESCRIBE SYSDOMAINS
220
DESCRIBE SYSFOREIGNKEYS
221
DESCRIBE SYSKEYS
221
DESCRIBE SYSLOG
222
DESCRIBE SYSOBJECTS
223
DESCRIBE SYSSYNONYMS
224
DESCRIBE SYSTABLES
225
DESCRIBE SYSUSERS
226
DESCRIBE SYSVIEWS
227
DESCRIBE TABLE
215
DESCRIBE USER
228
Diagrams
400, 402, 403, 404
DIGIT 33, 34
DIGITS
76, 398
DIGITS function allows only one integer column
398
DIRECT 186, 248, 255, 273, 311
DISABLE
229
DISABLE INDEXGBY
229, 311
DISC
230, 311
DISCONNECT 230, 311
DISTINCT 164, 168, 275, 311
DISTRIBUTE
275, 311
Division by zero
362
DML
177, 178
DOMAIN
195, 231, 264
Domain already exists
386
Domain does not exist
386
domain name
195, 204, 226
Domain not enabled for user
382
DOUBLE PRECISION
23, 25, 28
DROP
177, 178, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239
DROP COLUMN
178, 311
drop column clause
178
DROP DATABASE
230, 311
DROP DOMAIN
231
DROP EXPRESSION
232, 233
DROP EXPRESSIONS
232, 233
DROP GENERATED COLUMNS
234
DROP INDEX 235
DROP SYNONYM
236
DROP TABLE
237, 311
DROP USER
238, 311
DROP VIEW
239, 311
DUAL
175, 393
DUAL Table
175
DUPLICATE
240, 241, 243
DUPLICATE DATABASE
240, 311
Duplicate FOREIGN KEY
351
DUPLICATE TABLE
241, 311
DUPLICATE USER
243, 311
-EEBCDIC
29
EBCDIC Character Set
29
ELSE
138
ENABLE
243
ENABLE INDEXBGY
311
ENABLE INDEXGBY
243
Encoding and Decoding Functions
52
Encountered end of file in comments
326
END
138
ENGLISH
293
Equijoins
169, 170
Exceeded the limit of the number precision
EXEC
244, 311
EXECUTE
244
EXECUTE STORED QUERIES
311
EXECUTE STORED QUERUES
244
EXISTS
145, 156
EXISTS Condition
144, 156
336
410
EXP
77
Expected a constant positive expression in column
definition
346
Expected arithmetic operator
332
Expected identifier after point
332
Expected identifier or constant value
333
Expected logical operator
331
Expected relational operator
331
Expression
156, 196, 232, 233, 389
Expression Lists
135, 141
EXPRESSIONS
135, 137, 138, 140, 141, 232, 233
External function
78
External function error
395
External function not found in Catalog
395
EXTFUNC
78
-FFILE NAME
248, 253, 255, 273, 299, 305, 307
FIRST_DAY
80
FIRST_WORK_DAY
81
FLOAT 400
FLOAT
23, 25, 28
FLOOR
48, 81
Fmt
117
FOREIGN KEY
159, 161, 178, 185
Foreign Key Constraints
161
FROM
164, 211, 213, 270, 275, 311
FROM clause
173
FULL
173
FULL JOIN
275
FULL OUTER JOIN
275
function
35
Function ABS
54
Function ACOS
54
Function ADD_MONTHS
55
Function ASCII 56
Function ASIN
56
Function ATAN
57
Function AVG
57
Function BIN_TO_NUM
58
Function BITAND
59
Function BITOR
59
Function BITXOR
60
Function CEIL
61
Function CHR
62
Function CONCAT 62
Function COS
63
Function COSH
63
Function COUNT 64
Function CURRENT_DATE
65
Function CURRENT_TIME
65
Function CURRENT_TIMESTAMP
66
Function DATE_TO_JULIAN
72, 86
Function DATEADD
66
Function DATEDIFF
68
Function DATEPART 70
Function DAYNAME
72
Function DAYOFWEEK
73
Function DAYOFYEAR
74
Function DECODE
75
Function DIGITS
76
Function EXP
77
Function Expressions
135, 140
Function FIRST_DAY
80
Function FIRST_WORK_DAY
81
Function FLOOR
81
Function GREATEST 82
Function GROUPING
83
Function HEXTONUM
84
Function HEXTOSTR
84
Function INITCAP
85
Function INSTR
86, 99, 101
Function ISNUMERIC
87
Function JULIAN_TO_DATE
72, 86
Function LAST_DAY
87
Function LAST_WORK_DAY
88
Function LEAST 89
Function LENGTH
89
Function LN
90
Function LOG
91
Function LOWER
88, 91
Function LPAD
92
Function LTRIM
93
Function MAX 94
Function MIN
94
Function MOD
95, 102
Function MONTHNAME
96
Function MONTHS_BETWEEN
96
Function NEXT_DAY
97
Function NEXT_WORK_DAY
97
Function not available in this Sadas version
Function NUMTOHEX 98
Function PI 98
Function POWER
99
Function PREVIOUS_DAY
100
395
411
Function PREVIOUS_WORK_DAY
100
Function RATIO_TO_REPORT 101
Function REPLACE
101, 102
Function ROUND
102
Function RPAD
103
Function RTRIM
104
Function SDS_HASH
105
Function SDS_HASH_Sh1
106
Function SHUFFLE
109
Function SIGN
107
Function SIN
108
Function SINH
108
Function SOUNDEX 109
Function SQRT 110
Function STDDEV
111
Function STRTOHEX 112
Function SUBSTITUTE_WITH
112
Function SUBSTR
101, 113
Function SUM
114
Function SYSDATE
65, 114
Function SYSTIME
66, 115
Function SYSTIMESTAMP
90, 98, 115
Function TAN
115
Function TANH
116
Function TO_BASE
116
Function TO_CHAR(character)
117
Function TO_CHAR(datetime)
117
Function TO_CHAR(number)
122
Function TO_CODE
125
Function TO_DATE
125
Function TO_DESC
126
Function TO_NUMBER
127
Function TO_TIME
128
Function TO_TIMESTAMP
128
Function TODAY
129
Function TRANSLATE
129
Function TRIM
131
Function TRUNC(number)
131
Function UPPER
132
Function VARIANCE
132
Function VSIZE
133
function: invalid date/time format model
375
Functions
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 70, 72, 73, 74,
75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 122, 125, 126, 127, 128, 129, 131,
132, 133
-GGENERATED
234
GLOBAL TEMPORARY
200, 311
GRANT 177, 245
GRANT ALL
245, 311
Graphic Syntax Diagrams
400
GREATEST 51, 82
GROUP BY
275, 311, 393
GROUP BY CLAUSE
135, 164, 168
GROUP BY clause required in this case
GROUP FUNCTION
393
GROUPING
83
346
-HHAVING
164, 275, 311
HAVING CLAUSE
135, 144, 145, 146, 147, 148
HEXTONUM
84
HEXTOSTR
84
HOUR
27, 28
-IIdentifier name too long
328
Illegal DISTINCT clause
355
Illegal DISTRIBUTE clause
378
Illegal function in the context
340
Illegal GROUP BY clause
338
Illegal HAVING clause
366
Illegal identifier
329
Illegal identifier: the first character must be a letter
390
Illegal numeric literal
329
Illegal operation on operands
339
Illegal ORDER BY clause
345
Illegal UNION [ALL]/INTERSECT/MINUS
357
Illegal use of aggregate function
381
Illegal use of function TRANSLATE
367
Improper use of alias name
341
Improper use of DISTINCT clause
345
Improper use of INFO/SHADOW keywords
366
IN
145, 156, 388
IN clause: expected constant expression
373
IN Condition
144, 156
412
In DUAL SELECT following clause is not allowed
393
INDEX 198, 235
Indexed Columns
152
Indexes
36
INDEXGBY
229, 243
INFO
215, 311, 400
INITCAP
49, 85
inline view
173
INNER JOIN
169, 170, 171, 275
INSERT 247
INSERT TABLE
248
INSERT: wrong number of constants
397
INSERT: wrong type of a constant
397
INSTR
50, 86, 99, 101
INT
23, 25, 28
INTEGER
33
INTEGER
23, 25, 28
integrity constraint
159
Internal error; analyze the context! 346
Internal error; undefined type; analyze the context!
394
INTERSECT 45, 164, 166, 251, 275, 311
Invalid column description
347
Invalid constraint
349
Invalid NOT STAR JOIN
353
Invalid numeric value for the function
384
ISNUMERIC
87
ITALIAN
293
-JJoin
169, 388
Join clause
164
Join Conditions
169
JULIAN_TO_DATE
72, 86
-KKEY
394
KEYS
394
Keywords
402, 403
-LLANGUAGE
LAST_DAY
293
50, 87
LAST_WORK_DAY
88
LCASE
88, 91
LEAST 51, 89
LEFT 173
LEFT JOIN
275
LEFT OUTER JOIN
275
LEFTNULL
173
LENGTH
50, 89
Lexical
20
Lexical Conventions
20
Like
145, 152, 387
LIKE Conditions
150, 153
Literals
32, 33, 34, 35
LN
90
LOAD
177, 253, 254
LOAD COLUMN
253, 311
LOAD DATABASE
254, 311
LOAD TABLE
255, 311
LOCALTIMESTAMP
90, 115
LOCK
258, 259, 398
LOCK TABLE
258
LOCK USER
259
LOG
91
Logical Conditions
144, 148
LOKE
150, 153
Loops
403
LOWER
49, 88, 91
LPAD
49, 92
LPAD/RPAD functions: the second parameter must be
a not negative integer constant
363
LPAD/RPAD functions: the third parameter must be a
char
364
LTRIM
49, 93
-MMATERIALIZATED VIEW
275
MATERIALIZED
206
materialized view
173
MAX 53, 94, 392
MILLISECOND
27, 28
MIN
53, 94, 392
MINUS
45, 164, 166, 260, 275, 311
MINUTE
27, 28
MOD
48, 95, 102
MODIFY
159, 178, 185, 311
modify col properties
178
modify column clauses
178
413
MODIFY CONSTRAINT Clause
MONTH
27, 28
MONTHNAME
50, 96
MONTHS_BETWEEN
50, 96
Multipart Diagrams
404
185
-NNested Subquery
173, 174
NEXT_DAY
50, 97
NEXT_WORK_DAY
97
NLS_CALENDAR
117
NLS_CHARACTERSET 117
NLS_COMP
117
NLS_CURRENCY
117, 122
NLS_DATE_FORMAT 117
NLS_DATE_LANGUAGE
117
NLS_DUAL_CURRENCY
117
NLS_ISO_CURRENCY
117, 122
NLS_LANGUAGE
117
NLS_LENGTH_SEMANTICS
117
NLS_NCHAR_CHARACTER_SET 117
NLS_NCHAR_CONV_EXCP
117
NLS_NUMERIC_CHARACTERS
117, 122
NLS_RDBMS_VERSION
117
NLS_SORT 117
NLS_TERRITORY
117
NLS_TIME_FORMAT 117
NLS_TIME_TZ_FORMAT 117
NLS_TIMESTAMP_FORMAT 117
NLS_TIMESTAMP_TZ_FORMAT 117
No database available
361
No error
326
No user connected
361
Non executable SQL
357
Nonpadded
29
NOT 145, 146, 147, 148, 150, 153
NOT IN
156
NOT STAR JOIN
169, 275
Not supported syntax for CREATE VIEW statement
392
Not terminated text literal
327
NOT Truth Table
148
NOW
98, 115
NULL
154
Null Conditions
144, 154
Null identifier
390
Null SQL script
326
NUMBER
34
NUMBER
23, 25, 28
NUMERIC
154, 400
Numeric Literals
33, 34
NUMERIC
23, 25, 28
NUMTOHEX 98
-OON
196, 198, 261
ONLY
186, 248, 255, 273, 299
Operands of different datatypes
336
Operator
42
Operator Precedence
42
Operators
42, 43, 44, 45
Optional Keywords
403
OR
145, 146, 147, 148
OR Truth Table
148
ORDER BY
186, 275, 311, 393
ORDER BY CLAUSE
135, 164
Outer Joins
169, 173
-PParameters
402, 403
PASSWORD
183, 191, 204
PASWORD_LIFE_TIME
183, 204
Pattern-matching Conditions
144
PI 98
POSITION
86, 99, 101
POWER
48, 99
PR_CATALOG
245, 270, 311
PR_DESCRIBE
245, 270, 311
PR_LOAD
245, 270, 311
PR_SECURITY
245, 270, 311
PR_SELECT 245, 270, 311
PREVIOUS_DAY
100
PREVIOUS_WORK_DAY
100
PRIMARY KEY
159, 161, 178, 185
Primary Key Constraints
161
Primary key is not unique
350
PRIVILAGE LIST 270
privileges list
245
Pseudocolumn
39, 40
414
-QQUERIES
209, 217, 244
QUERY
164, 165, 166, 275
query_block
164
Quick Sort
168
-RRange Conditions
144, 153
RATIO_TO_REPORT 101
RATIO_TO_REPORT function: parameter must be a
column
383
RDBMS
18
REAL
400
REAL
23, 25, 28
REFERENCES
159, 178, 185
REGEXP_INSTR
86, 101
REGEXP_REPLACE
101, 102
REGEXP_SUBSTR
101, 113
Relational
20
Relational Databases
20
relational properties
200
relational table
200
REMAINDER
95, 102
RENAME
261, 263, 264, 265, 266
RENAME COLUMN
261
RENAME DATABASE
263, 311
RENAME DOMAIN
264
RENAME TABLE
265, 311
RENAME VIEW
266, 311
REPLACE
49, 101, 102, 206, 311
REPLICATE
267, 268
REPLICATE DATABASE
267, 311
REPLICATE TABLE
268, 311
Required Keywords
402
REVOKE
177, 270
REVOKE ALL
270, 311
REWRITE
272
REWRITE DATABASE
272
REWRITE TABLE
273
RIGHT 173
RIGHT JOIN
275
RIGHT OUTER JOIN
275
RIGHTNULL
173
Roles
37
ROMANIAN
293
Root of a negative number
365
ROUND
48, 102, 393
ROWID
39, 40
ROWID Pseudocolumn
39, 40
ROWNUM
39
ROWNUM Pseudocolumn
39
RPAD
49, 103
RTRIM
49, 104
RULE
28
Rules
28
-SSADAS
19
Sadas Call Interface
21
Sadas Console
21
Sadas Database Control Manager
21
Sadas Package
21
Sadas Web
21
Scalar Subquery
173, 174
Scalar Subquery Expressions
135, 141
Scalar sub-query must return an unique value
376
SCHEMA
36, 169, 199, 200, 213
SCI 21
SCL
21
SDS_HASH
105, 106
SDS_HASH_Sh1
106
SECOND
27, 28
SELECT 135, 164, 166, 178, 251, 260, 275, 311,
392, 393
select statement
206
Self Joins
170, 171
Selfjoins
169
Semijoins
169
SET 293, 294, 303, 308, 311
Set Operators
45
SHADOW
215, 311, 400
SHUFFLE
109
SIGN
48, 107
Simple Expressions
135, 137
SIN
108
Single-Row
48, 49, 50, 51, 52
Single-Row Functions
48, 49, 50, 51, 52
SINH
108, 305
SKIP
186, 248, 255, 273, 299
SMALLINT 23, 25, 28
Snow Flake schema
169, 388
415
SOUNDEX 49, 109
SQL
18, 19, 20
SQL Errors
326
SQL Functions
47
SQL Operator Precedence
42
SQL Operators
42
SQL Standards
18
SQRT 48, 110
Sructured Query Language
18
STAR JOIN
169, 275
STAR operand not supported in this context
380
Star schema
169, 388
STDDEV
53, 111, 392
storage path
193, 240, 267
STORED
209, 217, 244
STORED QUERIES
217, 311
STRTOHEX 112
SUBQUERY
147, 156, 164, 166, 173, 275, 391,
400
SUBSTITUTE_WITH
112
SUBSTR
49, 101, 113
SUBSTR function accepts only not negative integer
parameters
364
SUBSTRING
101, 113
SUM
53, 114, 392
SYNONYM
199, 236
Syntax
403, 404
Syntax error
330
Syntax Loops
403
Syntax Parameters
400
SYSALLCOLUMNS
218
SYSDATE
50, 65, 114
SYSDB
219, 311
SYSDBA
191
SYSDOMAINS
220, 311
SYSFOREIGNKEYS
221, 311
SYSKEYS
221, 311
SYSLOG
222, 311
SYSOBJECTS
223, 311
SYSSYNONYMS
224
SYSTABLES
225, 311
SYSTIME
50, 66, 115
SYSTIMESTAMP
50, 90, 98, 115
SYSUSERS
226, 311
SYSVIEWS
227, 311
-TTABLE
173, 188, 190, 200, 208, 209, 215, 237,
241, 258, 265, 268, 275, 296, 302, 307, 398, 400
Table has not a PRIMARY KEY
368
Table locked
398
TABLE NAME
200
Table reference
164
Table/view already exists
348
Table/view auto-reference thru FOREIGN KEY
350
Table/view does not exist
348
Tables
36
TAN
115
TANH
116
Text literal too long
327
text Literals
32
The comparison value for the coded field is too long
354
The user already exist
360
The user does not exist
360
THEN
138
TIME
23, 27, 28, 35, 50, 154, 244
TIMES
209
TIMESTAMP
23, 27, 28, 35, 50, 154
TO
240, 241, 243, 245, 261, 263, 264, 265, 266
TO_BASE
116
TO_CHAR function: erroneous NLS description
374
TO_CHAR function: invalid numeric format model
375
TO_CHAR function: second and third parameter must
be string constants
374
TO_CHAR(character)
51, 117
TO_CHAR(datetime)
50, 51, 117
TO_CHAR(number)
51, 122
TO_CODE
125
TO_DATE
35, 50, 51, 125
TO_DESC
126
TO_NUMBER
127
TO_NUMBER function: unable to convert the string
384
TO_TIME
35, 50, 51, 128
TO_TIMESTAMP
35, 50, 51, 128
TODAY
50, 129
Too many DISTINCT clauses
356
Too many DISTRIBUTE column ranges
379
Too many DISTRIBUTE ranges
380
Too many elements in update list
381
416
Too much tables in DELETE statement
391
TRANSLATE
49, 129
TRIM
49, 131
TRNUCATE
295, 296
TRNUCATE DATABASE
295
TRNUCATE TABLE
296
TRUNC
48, 131, 393
TRUNC(number)
131
TRUNC/ROUND: exceeded the limit of decimals
393
TRUNCATE
48, 131, 177
TRUNCATE DATABASE
311
TRUNCATE TABLE
311
Type mismatch for FOREIGN KEY
353
-UUCASE
132
Unary
42
Unary Operators
42
UNION
45, 164, 166, 275, 296, 311
UNION ALL
45, 164, 166, 296, 311
Unknown character
328
Unknown column name
334
Unknown table/view name
333
UNLOAD
298
UNLOAD DATABASE
298
UNLOAD TABLE
299
Unloaded table
341
UNLOCK
301, 302, 398
UNLOCK TABLE
302
UNLOCK USER
301
UNSET 294, 308
Unsupported function/operation
342
UPDATE
178, 303, 305, 307, 311, 393
UPDATE COLUMN
305, 311
UPDATE not allowed on column ROWID
385
UPDATE not allowed on primary key
382
UPDATE TABLE
307, 311
UPDATE: group functions are not allowed on right part
393
UPPER
49, 132
USER
183, 191, 194, 204, 228, 238, 243, 259, 301,
311
User domain does not exist
382
User has no rights to execute this command
359
Users
37
-VVALUES
247
VARCHAR
23, 25, 28, 29, 49
VARIABLE
294, 308
VARIANCE
53, 132, 392
VIEW
173, 185, 206, 239, 266, 275, 392, 400
view name
206
Views
36
VIRTUAL
159, 162
Virtual Constraints
162
VSIZE
133
VSIZE function: parameter must be a column
383
-WWHEN
138
WHERE
211, 275, 303, 311, 393
WHERE CLAUSE
135, 141, 144, 145, 146, 147,
148, 156, 164, 173
Wrong date
372
Wrong DISTRIBUTE parameter
377
Wrong DISTRIBUTE parameter configuration
379
Wrong hidden condition
359
Wrong number of columns in the sub-query of the
FROM clause
396
Wrong number of parameters
340
Wrong time
373
Wrong timestamp
380
Wrong use of function DATEADD
369
Wrong use of function DATEDIFF
371
Wrong use of function DATEPART 371
Wrong use of function NEXT_DAY
363
Wrong use of function SUBSTITUTE_WITH
385
Wrong use of function TO_DATE
335
Wrong use of function TO_TIME
344
Wrong use of function TO_TIMESTAMP
338
-YYEAR
27, 28