Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Target Audience
Consultants
Administrators
SAP Hardware Partners
Public
Document version 1.0 6/20/2011 - SAP HANA 1.0 Shipment for General Availability (GA)
SAP AG
Dietmar-Hopp-Allee 16
69190 Walldorf
Germany
T +49/18 05/34 34 34
F +49/18 05/34 34 20
www.sap.com
form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior notice.
any kind, and SAP Group shall not be liable for errors or omissions with
respect to the materials. The only warranties for SAP Group products
and services are those that are set forth in the express warranty
of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and
Disclaimer
other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open
Group.
service.sap.com/hana
Table of Contents
SAP HANA Guides .................................................................................................................................... 9
Introduction .......................................................................................................................................... 10
SQL .................................................................................................................................................... 10
Comment .......................................................................................................................................... 10
Language ........................................................................................................................................... 10
SQL Reserved Words ......................................................................................................................... 10
Data Types ............................................................................................................................................ 12
Data Type Summary .......................................................................................................................... 12
Classification of Data Types ............................................................................................................... 12
Datetime Types ................................................................................................................................. 12
Numeric Types................................................................................................................................... 13
Character String Types ....................................................................................................................... 14
Large Object (LOB) Types ................................................................................................................... 15
Date/Time Format ............................................................................................................................. 15
Data Type Conversion ........................................................................................................................ 17
Conditions ............................................................................................................................................. 21
Comparison Conditions...................................................................................................................... 21
Range Conditions............................................................................................................................... 21
In Conditions ..................................................................................................................................... 21
NULL Conditions ................................................................................................................................ 21
Exists Conditions................................................................................................................................ 21
Contains Conditions........................................................................................................................... 22
LIKE Conditions .................................................................................................................................. 22
NULL Conditions ................................................................................................................................ 22
Operators .............................................................................................................................................. 23
Unary and Binary Operators .............................................................................................................. 23
Operator Precedence ........................................................................................................................ 23
Arithmetic Operators ......................................................................................................................... 24
2
Guide/Tool
Quick Link
SAP HANA
Landscape,
Deployment &
Installation
https://service.sap.com/hana
SAP HANA
Administration &
Security
Introduction
This chapter describes the SQL language that manipulates data in a relational database and the
characteristics of SAP IMDB SQL. It also explains how to manage comments and reserve words.
SQL
SQL stands for Structured Query Language. It is the standard language for communicating with a
relational database and you can use it to retrieve or store information in the database. You can embed
SQL statements into programs or use them as a communication tool.
SQL normally manages tables using SQL statements to create or modify a table and to add or
manipulate data within a table. Such data management capabilities and quality assurance are the
major role of SQL.
Most SQL statements can perform the following tasks:*
Database definition
Database manipulation
Transaction management
Comment
Comments can be used in SQL statements as follows:
Comments are introduced by double hyphens "-- ". Everything from the double hyphens to the
end of the line is part of the comment.
Comments are delimited by "/*" and "*/". Everything from the open comment pair "/*" to the
close comment pair "*/" is considered part of the comment. These comment characters are used
for a multiple line comment.
Note:
In SAP IMDB SQL, comments are ignored when SQL statements are executed.
Language
SAP IMDB supports 8 bits ASCII, and Unicode.
ALL
ALTER
AS
BEFORE
BEGIN
BOTH
CASE
CONDITION
CONNECT
CROSS
CUBE
CURRENT_CONNECTION
CURRENT_SCHEMA
CURRENT_USER
CURRVAL
CURSOR
10
DISTINCT
ELSE
ELSEIF
END
EXCEPT
EXCEPTION
EXEC
FOR
FROM
FULL
GROUP
HAVING
IF
IN
INNER
INTERSECT
INTO
JOIN
LEADING
LEFT
LIMIT
LOOOP
MINUS
NATURAL
NEXTVAL
NULL
ON
ORDER
OUT
PRIOR
RETURN
RETURNS
REVERSE
RIGHT
ROLLUP
ROWID
SELECT
SET
SQL
START
SYSDATE
SYSTIME
SYSTIMESTAMP
SYSUUID
TOP
TRAILING
UNION
USING
UTCDATE
UTCTIME
UTCTIMESTAMP
VALUES
WHEN
WHERE
WHILE
WITH
Undelimited table and column names must start with a letter and cannot contain any symbols other
than numbers or an underscore "_". "Special characters" (special characters enclosed in double quotes)
are allowed in identifier names. However, "_SYS_" is not allowed in table names.
11
Data Types
This section describes the data types used in SAP IMDB.
When a table is created, each column of the table must be given a data type. All data types include
the null value, which is a special value and indicates the absence of a value. Although all data types
include the null value, columns that are defined as NOT NULL cannot contain null values. The following
table shows the built-in data types in SAP IMDB.
Data Type
Datetime types
Numeric types
VARCHAR, NVARCHAR
Binary types
VARBINARY
LOB types
Datetime Types
DATE
The DATE data type is used to store date information. The default format for the DATE data type is
'YYYY-MM-DD'. YYYY represents the year, MM represents the month, and DD represents the day.
The range of date value is 0001-01-01 through 9999-12-31.
Format
DATE
Example
date_value DATE
TIME
The TIME data type is used to store time information. The default format for the TIME data type is
'HH24:MI:SS'. HH24 represents the hour from 0 to 23, MM represents the minute from 0 to 59, SS
represents the second from 0 to 59.
Format
TIME
Example
time_value TIME
TIMESTAMP
The TIMESTAMP data type stores the date and time information. Its default format is 'YYYY-MMDD HH24:MI:SS.SSS' or 'YYYY/MM/DD, HH:MI:SS.SSS'.
12
TIMESTAMP
Example
timestamp_value TIMESTAMP
Numeric Types
TINYINT
The TINYINT data type stores an 8-bit unsigned integer. The minimum value is 0 and the
maximum value is 255 for TINYINT.
Format
TINYINT
Example
tinyint_value TINYINT
SMALLINT
The SMALLINT data type stores a 16-bit signed integer. The minimum value is -32,768 and the
maximum value is 32,767 for SMALLINT.
Format
SMALLINT
Example
smallint_value SMALLINT
INTEGER
The INTEGER data type stores a 32-bit signed integer. The minimum value is -2,147,483,648 and
the maximum value is 2,147,483,647 for INTEGER.
Format
INT or INTEGER
Example
int_value INT
BIGINT
The BIGINT data type stores a 64-bit signed integer. The minimum value is 9,223,372,036,854,775,808 and the maximum value is 9,223,372,036,854,775,807 for BIGINT.
Format
BIGINT
Example
bingint_value BIGINT
DECIMAL(precision, scale)
The DECIMAL(p, s) data type specifies a fixed-point decimal number with precision p and scale s.
The precision is the total number of significant digits and can range from 1 to 34. The scale is the
number of fractional digits to the right of the decimal point and can range from -6111 to 6176. If
the scale is not specified, it defaults to 0.
When precision and scale are not specified, it becomes a floating-point decimal number. In this
case, precision and scale can vary within the range described above, 1~34 for precision and 6111~6176 for scale, depending on the value being stored.
13
Example
decimal_value DECIMAL(7, 2)
decimal_float DECIMAL
REAL
The REAL data type specifies a single-precision 32-bit floating-point number.
Format
REAL
Example
real_value REAL
DOUBLE
The DOUBLE data type specifies a single-precision 64-bit floating-point number. The minimum
value is -1.79769 x 10308 and the maximum value is 1.79769x10308 . The smallest positive
DOUBLE value is 2.2207x10-308 and the largest negative DOUBLE value is -2.2207x10-308.
Format
Example
double_value DOUBLE
FLOAT(n)
The FLOAT(n) data type specifies a 32-bit or 64-bit real number, where n specifies the number of
significant bits and can range between 1 and 53.
When you use the FLOAT(n) data type, if n is smaller than 25, it becomes a 32-bit REAL data type.
If n is larger than or equal to 25, it then becomes a 64-bit DOUBLE data type. If n is not declared,
it becomes a 64-bit double data type by default.
Format
Example
float_value FLOAT(10)
VARCHAR(size)
Example
varchar_name VARCHAR(10)
NVARCHAR
The NVARCHAR(n) data type specifies a variable-length Unicode character set string.
14
Example
BLOB
Example
blob_value BLOB
CLOB
The CLOB data type is used to store large ASCII character data.
Format
CLOB
Example
clob_value CLOB
NCLOB
The NCLOB data type is used to store a large Unicode character object.
Format
NCLOB
Example
nclob_value NCLOB
LOB types are provided for storing and retrieving such large data. LOB types support the following
operations.
The length() function returns the LOB length.
The LIKE and CONTAINS predicates can be used to search LOB columns.
The LOB types have the following restrictions:
LOB columns cannot appear in ORDER BY, or GROUP BY clauses
LOB columns cannot appear in FROM clauses as a join condition
LOB columns cannot appear in SELECT clauses as an aggregate function argument.
LOB columns cannot appear in SELECT DISTICT clauses
LOB columns cannot be used in set operations such as EXCEPT. UNION ALL is an exception.
LOB columns cannot be used as a primary key
LOB columns cannot be used in CREATE INDEX statements
LOB columns cannot be used in statistics update statements
Date/Time Format
The following date/time format elements can be used when parsing a string into a date/time type and
converting a date/time type value into a string value. Refer to the TO_DATE, TO_TIME,
TO_TIMESTAMP, TO_CHAR and TO_NCHAR functions.
15
Description
DD
DDD
FF [1..9]
HH
HH12
HH24
MI
Minute (0-59).
MM
MON
MONTH
RM
SS
Second (0-59).
SSSSS
YYYY
4-digit year
YYY
YY
Y
The following date/time format elements can additionally be used when converting a date/time type
value into a string value. Refer to the TO_CHAR and TO_NCHAR functions.
Table 4: Additional date/time format elements
Element
Description
16
Description
DAY
DY
WW
17
Source
Timestamp
Date
Time
Timestamp
OK
OK
Date
OK
ERROR
Time
OK
ERROR
String (Timestamp)
OK
OK
OK
String (Date)
OK
OK
ERROR
String (Time)
ERROR
ERROR
OK
Error or Comparable
TIMESTAMP != '12:00:00'
TIMESTAMP !=
TIMESTAMP('12:00:00')
Error because of
incomplete timestamp
TIMESTAMP != '2001-06-13'
TIMESTAMP != TIMESTAMP('201106-13')
Comparable (converted as
'2011-06-13 00:00:00')
TIMESTAMP != '2001-06-13
12:00:00'
Comparable
DATE != '12:00:00'
DATE != DATE('12:00:00')
DATE != '2001-06-13'
DATE != DATE('2011-06-13')
Comparable
DATE != '2001-06-13
12:00:00'
DATE != DATE('2011-06-13
12:00:00')
TIME != '12:00:00'
TIME != TIME('12:00:00')
Comparable
TIME != '2001-06-13'
TIME != TIME('2011-06-13')
TIME != '2001-06-13
12:00:00'
TIME != TIME('2011-06-13
12:00:00')
18
NVARCHAR
VARCHAR
TIMESTAMP
TIME
DATE
DECIMAL(P,S)
DECIMAL
DOUBLE
DOUBLE
REAL
REAL
BIGINT
BIGINT
INTEGER
INTEGER
SMALLINT
Source
TINYINT
Data
Type
SMALLINT
TINYINT
Target Data
Type
OK OK OK OK OK OK
OK OK OK OK OK
OK OK OK OK
OK
OK OK
OK
DECIMAL
DECIMAL(P,S)
OK
DATE
TIME
TIMESTAMP
OK OK
VARCHAR
NVARCHAR
VARBINARY
Highest
TIMESTAMP
DATE
TIME
DOUBLE
19
VARBINARY
20
Conditions
A condition is specified by combining one more expressions or Boolean (logical) operators. The
specified condition then returns one of the following logical or truth values: TRUE, FALSE, or
UNKNOWN. This chapter describes the conditions used in SAP IMDB.
Comparison Conditions
Two values can be compared using comparison conditions and this returns true, false, or unknown.
Syntax:
comparison_condition ::=
expr { = | != | <> | > | < | >= | <= } { ANY | SOME| ALL } { { expr_list } | subquery }
expr_list ::= expr, ...
Expressions can be a simple expression such as a character, date, or number. An expression can also
be a scalar subquery.
ANY, SOME, ALL When ANY or SOME is specified, a comparison returns true if at least one value
returned by subquery or expr_list is true. A comparison returns true if the comparison for all values
returned by subquery or expr_list is true.
Range Conditions
A value can be compared with the list of values within the provided range and returns true, false, or
null.
Syntax:
range_condition ::= expr1 [NOT] BETWEEN expr2 AND expr3
BETWEEN When BETWEEN and AND are specified, the condition returns true if expr1 is within the
range specified by expr2 and expr3 assuming that expr2 has a lesser value than expr3.
In Conditions
A value can be compared with a specified set of values and returns true, false, or null.
Syntax:
In_condition ::= expr [NOT] IN { expr_list | subquery }
NULL Conditions
A value can be compared with NULL and returns true if a value is NULL.
Syntax:
null_condition ::= expr IS [NOT] NULL
Exists Conditions
A value can be compared with the result set of the subquery and returns true if the subquery contains
the value.
Syntax:
exists_condition ::= EXISTS ( subquery )
21
Contains Conditions
A value of the first argument is tested to check whether it contains the value of the second argument as
a substring. If the value of the first argument is an empty (zero-length) string, then the function returns
false. If the value of the second argument is an empty string, then the function returns true. If the value
of the first or second argument is NULL, then the function returns false. If the values of the first and
second arguments are both empty string, then the function returns true.
Syntax:
contains_condition ::= CONTAINS ( target_expr, pattern_expr )
LIKE Conditions
A value is tested for pattern with the wildcard characters ( % ) and ( _ ) in the specified expr and returns
true if the pattern specified by expr2 is found. The percentage sign ( %) matches zero or more characters
and underscore ( _ ) matches exactly one character. To match a percent sign or underscore in the LIKE
condition, an escape character must be provided.
Syntax:
like_condition ::= expr1 [NOT] LIKE expr2 [ESCAPE expr3]
NULL Conditions
A value can be compared with NULL and returns true if a value is NULL.
Syntax:
null_condition ::= expr IS [NOT] NULL
22
Operators
By using operators in expressions, you can perform arithmetic computation, compare values, or assign
values to each data item. This section describes the operators that are supported by SAP IMDB.
Operation
Format
Description
Unary
A unary operator
applies to one
operand or a single
value expression.
operator operand
A binary operator
applies to two
operands or two
values expressions.
Binary
Operator Precedence
An expression can have several operators in it. If the order of evaluation is specified by parentheses,
then expressions in parentheses are evaluated first. If not, SAP IMDB uses precedence rules to decide
which one to use first. For example, SAP IMDB evaluates operators with a higher precedence before
evaluating those with a lower precedence, and evaluates operators with equal precedence from left to
right within an expression. Operators listed on the same line have the same precedence.
Table 9. SQL operator precedence
Operator
Operation
()
parentheses
+, -
*, /
multiplication, division
+, -
addition, subtraction
||
concatenation
comparison operator
NOT
logical negation
AND
conjunction
OR
disjunction
23
Arithmetic Operators
Arithmetic operators can be used to perform arithmetic operations such as negate, add, subtract,
multiply, and divide numeric values. The result is a numeric value.
Table 10. Arithmetic operators
Operator
Description
+, -
*, /
Concatenation Operators
A concatenation operator combines two items such as strings, expressions, or constants into one.
Table 11. Concatenation operators
Operator
Description
Example
||
Two string concatenation results in another string. If either string is of data type NVARCHAR, the
result has data type NVARCHAR and is limited to 5000 characters.
Comparison Operators
Comparison operators check whether two expressions are the same and return one of these three
values: TRUE, FALSE, or UNKNOWN.
Table 12. Comparison operators
Operator
Description
Example
"Equal"
!=
"Not equal"
24
Description
Example
>
"Greater than"
<
"Less than"
>=
<=
IN
NOT IN
EXISTS
x [NOT] LIKE
y [ESCAPE 'z']
IS [NOT]
NULL
LIKE
The LIKE operator determines if a character string matches a given pattern. The equal (=) operator
exactly matches each character between two strings, whereas the LIKE operator matches a pattern by
searching the pattern specified by the second.
Patterns can use special pattern-matching characters as follows:
With the %in pattern, zero or more characters in the value can be matched.
With the _ in the pattern, exactly one character in the value can be matched.
25
Logical Operators
This section describes the general usage of a logical operator in SAP IMDB.
A logical operator combines the results of two conditions to produce a single result based on them, or
to invert the result of a single condition.
The following table lists the SAP IMDB logical operators.
Table 13. Logical operators
Operator
Operation
NOT
AND
Example
Set Operators
The combination of two component queries into one result can be done by Set Operators. This type of
queries can be called compound queries.
Table 14. Set operators
Operator
Returned Value
UNION
UNION ALL
26
Returned Value
INTERSECT
MINUS, EXCEPT
27
Expressions
An expression is the result evaluated from one or more values, operators, and SQL functions.
Simple Expressions
A simple expression defines a constant, a column, a sequence number, or null.
Syntax:
simple_expression ::= NULL | column_reference | constant | sequence_name.{ CURRVAL | NEXTVAL }
Compound Expressions
A compound expression combines other expressions and returns a single valued result.
Syntax:
compound_expression ::= ( expr ) | - expr | expr { * | / | + | - | || } expr
Case Expressions
A case expression allows the user to use IF ... THEN ... ELSE logic without using procedures in SQL
statements.
Syntax:
case_expression ::= CASE { simple_case | searched_case } [ else_case ] END
simple_case ::= expr { { WHEN comparison_expr THEN return_expr } ... }
searched_case ::= { WHEN condition THEN return_expr } ...
else_case ::= ELSE expr
Function Expressions
SQL built-in functions can be used as an expression.
Syntax:
function_expression ::= func_name ( expr, ... )
Aggregate Expressions
An aggregate expression uses an aggregate function to calculate a single value from the values of
multiple rows in a column.
Syntax:
aggregate_expression ::= agg_name ( { * | [ ALL | DISTINCT ] expr } )
agg_name ::= COUNT | MIN | MAX | SUM | AVG | STDDEV | VAR
28
Functions
Similar to an operator, a function manipulates data items and returns a result. Functions differ from
operators in the format of their arguments. Functions can take zero, one, or more arguments. This
chapter describes the SQL functions used in SAP IMDB.
SQL Function
SQL functions can be used to emphasize a general query or manipulate data item easily. SQL
functions are used to calculate data, display the group result of the data items conversion, or to
convert the data types. In addition, a function may be used in places where an expression is used.
Function Format
The syntax for the SQL function is as follows:
function (argument, argument, ... )
29
Number Functions
Number functions take numeric values or strings with numeric characters as inputs and returns
numeric values. When strings with numeric characters are given as inputs, implicit conversion from
string to number is performed automatically before computing the result values.
ABS Function
Syntax :
ABS ( n )
Description:
Computes the absolute value of n.
Example:
Retrieves:
absolute
1
ACOS Function
Syntax:
ACOS ( n )
Description:
Calculates the arc cosine of the argument n between -1 and 1 and returns a value between 0 and pi
expressed in radians.
Example:
SELECT ACOS(0.5) "acos" FROM dual;
Retrieves:
acos
1.0471975511965979
ASIN Function
Syntax:
ASIN ( n )
Description:
Calculates the arc sine of the argument n between -1 and 1 and returns a value between -pi/2 and
pi/2 expressed in radians.
Example:
SELECT ASIN(0.5) "asin" FROM dual;
Retrieves:
asin
0.5235987755982989
30
atan
0.4636476090008061
ATAN2 Function
Syntax :
ATAN2 (n, m)
Description:
Computes the arc tangent of n and m. This is the same result as ATAN(n/m).
Example:
SELECT ATAN2(1.0, 2.0) "atan2" FROM dual;
Retrieves:
atan2
0.4636476090008061
BITAND Function
Syntax:
BITAND (expr1, expr2)
Description:
Calculates an AND operation on the bits of expr1 and expr2. Both expr1 and expr2 must be non-negative
integers: an integer is returned then.
Example:
SELECT BITAND(255, 123) "bitand" FROM dual;
Retrieves:
bitand and
123
31
ceiling
15
COS Function
Syntax:
COS ( n )
Description:
Computes the cosine of n, where n is an angle expressed in radians.
Example:
SELECT COS(0.0) "cos" FROM dual;
Retrieves:
cos
1.0
COSH Function
Syntax:
COSH ( n )
Description:
Computes the hyperbolic cosine of n.
Example:
SELECT COSH(0.0) "cosh" FROM dual;
Retrieves:
cosh
1.0
COT Function
Syntax:
COT ( n )
Description:
Computes the cotangent of n.
Example:
SELECT COT(40) "cot" FROM dual;
Retrieves:
Cot
1.5423510453569202
EXP Function
Syntax:
EXP ( n )
32
exp
2.718281828459045
FLOOR Function
Syntax:
FLOOR ( n )
Description:
Computes the largest integer that is less than or equal to n.
Example:
SELECT FLOOR(14.5) "floor" FROM dual;
Retrieves:
floor
14
GREATEST Function
Syntax:
GREATEST ( n1 [, n2]...)
Description:
Returns the greatest value among the arguments: n1, n2, ...
Example:
SELECT GREATEST ('aa', 'ab', 'ba', 'bb') "greatest" FROM dual;
Retrieves:
greatest
bb
LEAST Function
Syntax:
LEAST ( n1 [, n2]...)
Description:
Returns the least value among the arguments: n1, n2...
Example:
SELECT LEAST('aa', 'ab', 'ba', 'bb') "least" FROM dual;
Retrieves:
least
aa
33
ln
1.0
LOG Function
Syntax :
LOG(m, n)
Description:
Computes the logarithm, base m, of n. The base m must be a positive value other than 1 and n must
be any positive value.
Example:
SELECT LOG(10, 2) "log" FROM dual;
Retrieves:
log
0.30102999566398114
MOD Function
Syntax:
MOD(m, n)
Description:
Computes the remainder of m divided by n. If n is 0, then the function returns m.
This function acts differently from the classical modulus function when m is negative.
The classical modulus function can be expressed by the formula shown below:
m - n * FLOOR( m / n ), however MOD functions returns a value differently.
The following explains example of what MOD functions returns as the result.
If n is zero, then this function returns m.
If m is greater than 0 and m is less than n, then this function returns m.
If m is less than 0 and m is greater than n, then this function returns m.
Otherwise, this function calculates the remainder of the absolute value of n divided by the
absolute value of n to calculate the absolute value of the remainder. If m is less than 0, then the
returned remainder from MOD is less than 0, and if m is greater than 0, then the returned
remainder from MOD is greater than zero.
Example:
SELECT MOD(15, 4) "modulus" FROM dual;
Retrieves:
modulus
3
34
power
1024.0
ROUND Function
Syntax:
ROUND(n [, pos ])
Description:
Computes n rounded to pos places to the right of the decimal point. If pos is not provided, then n is
rounded to the nearest number without a decimal point.
Example:
SELECT ROUND(16.16, 1) "round" FROM dual;
Retrieves:
round
16.2
SELECT ROUND(16.56) "round" FROM dual;
Retrieves:
round
17
SIGN Function
Syntax:
SIGN ( n )
Description:
Returns different value depending on the sign of n. Returns 1 if n is a positive value, -1 if n is a
negative value, and 0 if n is equal to zero.
Example:
SELECT SIGN(-15) "sign" FROM dual;
Retrieves:
sign
-1
35
sine
1.0
SINH Function
Syntax:
SINH (n )
Description:
Computes the hyperbolic sine of n which is an angle expressed in radians.
Example:
SELECT SINH(0.0) "sinh" FROM dual;
Retrieves:
sinh
0.0
SQRT Function
Syntax:
SQRT ( n )
Description:
Computes the square root of n which is a non-negative value.
Example:
SELECT SQRT(2) "sqrt" FROM dual;
Retrieves:
sqrt
1.4142135623730951
TAN Function
Syntax:
TAN ( n )
Description:
Computes the tangent of n which is an angle expressed in radians.
Example:
SELECT TAN(0.0) "tan" FROM dual;
Retrieves:
tan
0.0
36
tanh
0.7615941559557649
Character Functions
ASCII Function
Syntax:
ASCII(c)
Description:
Returns the ASCII value of first character of c string.
Example:
SELECT ASCII('Ant') "ascii" FROM dual;
Retrieves:
ascii
65
CHR Function
Syntax:
CHR ( n )
Description:
Converts an integer n in range 0 255 into a character based on ascii code.
Example:
SELECT CHR(65) || CHR(110) || CHR(116) "character" FROM dual;
Retrieves:
character
Ant
CONCAT Function
Syntax :
CONCAT(str1, str2)
Description:
Returns a combined string which consists of str1 followed by str2. The concatenation operator (||) is
identical to this function.
37
concat
Cat
INSTR Function
Syntax:
INSTR(str, substr [, pos [, occur ] ])
Description:
Searches str for substr and finds the position of this occurrence.
The value of pos specifies a starting position of str to search for substr.
The value of occur specifies the position of the character in str that is the first character of this
occurrence. The value of occur must be positive.
The default values of both pos and occur are 1. If the search is unsuccessful, then the return value is 0.
Example:
SELECT INSTR('in string in', 'in', 3, 2) "in string" FROM dual;
Retrieves:
in string
11
LEFT Function
Syntax :
LEFT(str, n)
Description:
Returns the first n character from str.
Example:
SELECT LEFT('Hello', 3) "left" FROM dual;
Retrieves:
left
Hel
LCASE Function
Syntax:
LCASE(c)
Description:
Returns c with all lowercase letters.
Example:
SELECT LCASE('Cat') "lcase FROM dual;
Retrieves:
lcase
cat
38
length
14
LOCATE Function
Syntax:
LOCATE(str, search_str)
Description:
Returns the position in str if search_str is found in str. Returns 0 if search_str is not found from str.
Example:
SELECT LOCATE('length in char', char) "locate" FROM dual;
Retrieves:
Locate
11
LOWER Function
Syntax
LOWER(c)
Description
Returns c with all lowercase letters
Example
SELECT LOWER('Ant') "lower" FROM dual;
Retrieves:
lower
ant
LPAD Function
Syntax:
LPAD(target, n[, pattern])
Description:
Pad space or pattern to the left of the target string to make the target the length of n.
Example:
SELECT LPAD('end', 15, '12345') "lpad" FROM dual;
39
lpad
123451234512end
LTRIM Function
Syntax:
LTRIM(c [, str])
Description:
Removes from the leftmost of c all of the characters that appear in set until reaching a character not in
str and then returns the result. If str is not specified, a single blank space is used.
Example:
SELECT LTRIM('babababAabend','ab') "ltrim" FROM dual;
Retrieves:
ltrim
Aabend
NCHR Function
Syntax:
NCHR ( n )
Description:
This function returns the character with the binary equivalent to n in the national character set.
Example:
SELECT NCHR (65) "nchr" FROM dual;
Retrieves:
nchr
A
REPLACE Function
Syntax:
REPLACE (target, pattern, replace)
Description:
Returns a string value created by replacing every non-overlapping occurrence of the pattern in target
with the replace.
If target is an empty string, then the result is also the empty string.
If two overlapping substrings match the pattern in the target string, then only the first one is
replaced with the replace.
If target does not contain any occurrence of pattern, then the function returns target. If target,
pattern, or replace is NULL, then the function returns NULL.
Example:
SELECT REPLACE ('DOWNGRADE DOWNWARD','DOWN', 'UP') "replace" from dual;
Retrieves:
replace
UPGRADE UPWARD
40
right
789
RPAD Function
Syntax:
RPAD (target, n[, pattern])
Description:
Pad space or pattern to the right of the target string to make the target the length of n.
Example:
SELECT RPAD('end', 15, '12345') "right padded" FROM dual;
Retrieves:
right padded
end123451234512
RTRIM Function
Syntax:
RTRIM (c [, str])
Description:
Similar to a LTRIM function, but RTRIM removes from the rightmost of c all of the characters that
appear in str.
Example:
SELECT RTRIM ('endabAabbabab','ab') "rtrim" FROM dual;
Retrieves:
right trimmed
endabA
SUBSTR Function
Syntax:
SUBSTR (string, position [, string length])
Description:
Returns a substring from string starting from the position-th character of the string.
The position of the first character in the string is 1, hence if position is positive, the position
number of characters are skipped before calculating the return value, and takes the string length
number of characters as a result.
If position is less than 0, then it is considered as 1.
If string length is less than 1, then an empty string is returned as the result.
41
substring
cdef
SUBSTR_AFTER Function
Syntax:
SUBSTR_AFTER(target, pattern)
Description:
Returns the substring of the target string after the pattern.
If target does not contain a substring which is the same as pattern, then an empty string is
returned.
If pattern is an empty string, then target is returned.
If target or pattern is NULL, then NULL is returned.
Example:
SELECT SUBSTR_AFTER('Hello My Friend','My ') "substr after" FROM dual;
Retrieves:
substr after
Friend
SUBSTR_BEFORE Function
Syntax:
SUBSTR_BEFORE(target, pattern)
Description:
Returns the substring of the target string before the pattern.
If target does not contain a substring which is the same as pattern, then an empty string is
returned.
If pattern is an empty string, then target is returned.
If target or pattern is NULL, then NULL is returned.
Example:
SELECT SUBSTR_BEFORE('Hello My Friend','My') "substr before" FROM dual;
Retrieves:
substr before
Hello
TRIM Function
Syntax:
TRIM ( [ [LEADING | TRAILING | BOTH] trim_char FROM] trim_source])
42
trim both
123456789
SELECT TRIM (LEADING 0 FROM 00012345678900) "trim leading" FROM dual;
Retrieves:
trim leading
12345678900
UCASE Function
Syntax :
UCASE(c)
Description:
Returns c with all uppercase letters.
Example:
SELECT UCASE('Ant') "ucase" FROM dual;
Retrieves:
ucase
ANT
UNICODE Function
Syntax :
UNICODE(c)
Description:
Computes the positive integer UNICODE value of first character of c string.
Example:
SELECT UNICODE('#') "unicode" FROM dual;
Retrieves:
unicode
54620
UPPER Function
Syntax:
UPPER(c)
43
Description:
Returns a string, c, after converting all characters to upper case.
Example:
SELECT UPPER('Ant') "uppercase" FROM dual;
Retrieves:
uppercase
ANT
DateTime Functions
ADD_DAYS Function
Syntax:
ADD_DAYS(d, n)
Description:
Computes the date d plus n days.
Example:
SELECT ADD_DAYS(TO_DATE('2009-12-05', 'YYYY-MM-DD'), 30) "add days" FROM dual;
Retrieves:
add days
2010-01-04
ADD_MONTHS Function
Syntax:
ADD_MONTHS(d, n)
Description:
Computes the date d plus n months.
Example:
SELECT ADD_MONTHS(TO_DATE('2009-12-05', 'YYYY-MM-DD'), 1) "add months" FROM dual;
Retrieves:
add months
2010-01-05
ADD_YEARS Function
Syntax:
ADD_YEARS(d, n)
Description:
Computes the date d plus n years.
Example:
SELECT ADD_YEARS(TO_DATE('2009-12-05', 'YYYY-MM-DD'), 1) "add years" FROM dual;
Retrieves:
add years
2010-12-05
44
add seconds
00:00:45.000
CURDATE Function
Syntax:
CURDATE()
Description:
Returns SYSDATE value.
Example:
SELECT CURDATE() FROM dual;
Retrieves:
SYSDATE
2011-06-03
CURTIME Function
Syntax:
CURTIME()
Description:
Returns SYSTIME value.
Example:
SELECT CURTIME() FROM dual;
Retrieves:
SYSTIME
12:38:57
DAYS_BETWEEN Function
Syntax:
DAYS_BETWEEN (date1, date2)
Description:
Computes the number of days between date1 and date2.
Example:
SELECT DAYS_BETWEEN(TO_DATE('2009-12-05', 'YYYY-MM-DD'), TO_DATE('2010-01-05', 'YYYYMMDD')) "days between" FROM dual;
45
days between
31
DAYNAME Function
Syntax:
DAYNAME(expr)
Description:
Returns the name of the weekday in English.
Example:
SELECT DAYNAME('2011-05-30') "dayname" FROM dual;
Retrieves:
dayname
MONDAY
DAYOFMONTH Function
Syntax:
DAYOFMONTH(expr)
Description:
Returns the day of the month in integer.
Example:
SELECT DAYOFMONTH ('2011-05-30') "dayofmonth" FROM dual;
Retrieves:
dayofmonth
30
DAYOFYEAR Function
Syntax:
DAYOFYEAR(expr)
Description:
Returns the day of the year in integer.
Example:
SELECT DAYOFYEAR ('2011-05-30') "dayofyear" FROM dual;
Retrieves:
dayofyear
150
EXTRACT Function
Syntax:
EXTRACT({YEAR | MONTH | DAY | HOUR | MINUTE | SECOND} FROM datetime_value_expr)
Description:
Finds and returns the value of a specified datetime field from a datetime_value_expr.
Example:
SELECT EXTRACT(YEAR FROM TO_DATE('2010-01-04', 'YYYY-MM-DD')) "extract" FROM dual;
46
extract
2010
HOUR Function
Syntax:
HOUR(expr)
Description:
Extract hour from expr.
Example:
SELECT HOUR ('12:34:56) "hour" FROM dual;
Retrieves:
hour
12
LAST_DAY Function
Syntax:
LAST_DAY(d)
Description:
Returns the date of the last day of the month that contains d.
Example:
SELECT LAST_DAY(TO_DATE('2010-01-04', 'YYYY-MM-DD')) "last day" FROM dual;
Retrieves:
last day
2010-01-31
MINUTE Function
Syntax:
MINUTE(expr)
Description:
Extract minute from expr.
Example:
SELECT MINUTE ('12:34:56) "minute" FROM dual;
Retrieves:
minute
34
MONTH Function
Syntax:
MONTH(expr)
Description:
Returns the number of the month from a given date.
47
month
5
MONTHNAME Function
Syntax:
MONTHNAME(expr)
Description:
Returns the name of the month in English.
Example:
SELECT MONTHNAME ('2011-05-30) "monthname" FROM dual;
Retrieves:
monthname
MAY
NEXT_DAY Function
Syntax:
NEXT_DAY(d)
Description:
Returns the date of the next day of d.
Example:
SELECT NEXT_DAY(TO_DATE('2009-12-31', 'YYYY-MM-DD')) "next day" FROM dual;
Retrieves:
next day
2010-01-01
NOW Function
Syntax:
NOW()
Description:
Returns the current timestamp.
Example:
SELECT NOW() "now" FROM dual;
Retrieves:
now
2010-01-01 16:34:19
SECOND Function
Syntax:
SECOND(t)
48
second
56
SECONDS_BETWEEN Function
Syntax:
SECONDS_BETWEEN(d1, d2)
Description:
Computes the number of seconds between d1 and d2, which is semantically equal to d2 d1.
Example:
SELECT SECONDS_BETWEEN('2009-12-05', '2010-01-05') "seconds between" FROM dual;
Retrieves:
Seconds between
2678400
SYSDATE Function
Syntax:
SYSDATE
Description:
Returns the current system date.
Example:
SELECT SYSDATE "system date" FROM dual;
Retrieves:
system date
2010-01-11
SYSTIME Function
Syntax:
SYSTIME
Description:
Returns the current system time.
Example:
SELECT SYSTIME "system time" FROM dual;
Retrieves:
system time
17:37:37.279
49
system timestamp
2010-01-11 17:38:48.802
UTCDATE Function
Syntax:
UTCDATE
Description:
Returns the current UTC date. The UTC stands for Coordinated Universal Time, also known as
Greenwich Mean Time (GMT).
Example:
SELECT UTCDATE "Coordinated Universal Date" FROM dual;
Retrieves:
UTCTIME Function
Syntax:
UTCTIME
Description:
Returns the current UTC time.
Example:
SELECT UTCTIME "Coordinated Universal Time" FROM dual;
Retrieves:
UTCTIMESTAMP Function
Syntax:
UTCTIMESTAMP
Description:
Returns the current UTC timestamp.
Example:
SELECT UTCTIMESTAMP "Coordinated Universal Timestamp" FROM dual;
50
WEEK Function
Syntax:
WEEK(d)
Description:
Returns the week number of a given date d.
Example:
SELECT WEEK(TO_DATE('2011-05-30', 'YYYY-MM-DD')) "week" FROM dual;
Retrieves:
week
22
WEEKDAY Function
Syntax:
WEEKDAY(d)
Description:
Returns the day of week of a given date d. The return value ranges from 0 to 6, each of which
represents Monday to Sunday.
Example:
SELECT WEEKDAY(TO_DATE('2010-12-31', 'YYYY-MM-DD')) "week day" FROM dual;
Retrieves:
week day
4
YEAR Function
Syntax:
YEAR(d)
Description:
Returns the year number of a given date d.
Example:
SELECT YEAR(TO_DATE('2011-05-30', 'YYYY-MM-DD')) "year" FROM dual;
Retrieves:
year
2011
Conversion Functions
CAST Function
Syntax:
CAST(expr AS to_data_type)
51
Description:
Converts an expression to another type.
cast
7
HEXTORAW Function
Syntax:
HEXTORAW(expr)
Description:
Returns a raw value after converting expr to a raw value. expr has to be a string with hexadecimal
values.
Example:
SELECT HEXTORAW('B7') "hextoraw" FROM dual;
Retrieves:
hextoraw
B7
TO_BIGINT Function
Syntax:
TO_BIGINT(expr)
Description:
Converts the expr of a data type into a value of bigint data type.
Example:
SELECT TO_BIGINT('10') "to bigint" FROM dual;
Retrieves:
to bigint
10
TO_BINARY Function
Syntax:
TO_BINARY(expr)
Description:
Converts the expr of a data type into a value of binary string type.
Example:
SELECT TO_BINARY('abcde') "to binary" FROM dual;
52
to binary
6162636465
TO_BLOB Function
Syntax:
TO_BLOB(expr)
Description:
Converts the expr of a data type into a value of blob type. expr must be a binary string.
Example:
SELECT TO_BLOB(TO_BINARY('abcde')) "to blob" FROM dual;
Retrieves:
to blob
abcde
TO_CHAR Function
Syntax:
TO_CHAR(expr [,format])
Description:
Converts the expr of a data type into a value of character data type.
Example:
SELECT TO_CHAR(TO_DATE('2009-12-31'), 'YYYY/MM/DD') "to char" FROM dual;
Retrieves:
to char
2009/12/31
TO_CLOB Function
Syntax:
TO_CLOB(expr)
Description:
Converts the expr of a data type into a value of CLOB data type.
Example:
SELECT TO_CLOB ('TO_CLOB converts an expression into a value of CLOB data type') "to clob"
FROM dual;
Retrieves:
to clob
TO_DATE Function
Syntax:
TO_DATE(expr [, format])
Description:
Converts the expr of a data type into a value of DATE data type.
Example:
SELECT TO_DATE('2010-01-12', 'YYYY-MM-DD') "to date" FROM dual;
53
to date
2010-01-12
TO_DATS Function
Syntax:
TO_DATS(expr)
Description:
Converts the expr of a data type into a value of ABAP DATE data type.
Example:
SELECT TO_DATS('2010-01-12') "abap date" FROM dual;
Retrieves:
abap date
20100112
TO_DECIMAL Function
Syntax:
TO_DECIMAL(expr[, precision, scale])
Description:
Converts the expr of a data type into a value of DECIMAL(precision, scale) data type.
Example:
SELECT TO_DECIMAL(7654321.89, 9, 2) "to decimal" FROM dual;
Retrieves:
to decimal
7654321.89
TO_DOUBLE Function
Syntax:
TO_DOUBLE(expr)
Description:
Converts the expr of a data type into a value of DOUBLE (double precision) data type.
Example:
SELECT 3*TO_DOUBLE ('15.12') "to double" FROM dual;
Retrieves:
to double
45.36
TO_INT Function
Syntax:
TO_INT(expr)
Description:
Converts the expr of a data type into a value of INTEGER data type.
54
Example:
SELECT TO_INT('10') "to int" FROM dual;
Retrieves:
to int
10
TO_INTEGER Function
Syntax:
TO_INTEGER(expr)
Description:
Converts the expr of a data type into a value of INTEGER data type.
Example:
SELECT TO_INTEGER('10') "to int" FROM dual;
Retrieves:
to int
10
TO_NCHAR Function
Syntax:
TO_NCHAR(expr [,format])
Description:
Converts the expr of a data type into a value of national character data type.
If format is omitted, it converts to the corresponding format using the date format model.
Example:
SELECT TO_NCHAR(TO_DATE('2009/12/31'), 'YY-MM-DD') "to nchar" FROM dual;
Retrieves:
to nchar
09-12-31
TO_NCLOB Function
Syntax:
TO_NCLOB(expr)
Description:
Converts the expr of a data type into a value of NCLOB data type.
Example:
SELECT TO_NCLOB ('TO_NCLOB converts an expression into a value of NCLOB data type') "to
nclob" FROM dual;
Retrieves:
to nclob
TO_NCLOB converts an expression into a value of NCLOB data type
55
to number
46.5
TO_REAL Function
Syntax:
TO_REAL(expr)
Description:
Converts the expr of a data type into the value of REAL (single precision) data type.
Example:
SELECT 3*TO_REAL ('15.12') "to real" FROM dual;
Retrieves:
to real
45.36
TO_SMALLINT Function
Syntax:
TO_SMALLINT(expr)
Description:
Converts the expr of a data type into a value of SMALLINT data type.
Example:
SELECT TO_SMALLINT('10') "to smallint" FROM dual;
Retrieves:
to smallint
10
TO_TINYINT Function
Syntax:
TO_TINYINT(expr)
Description:
Converts the expr of a data type into a value of TINYINT data type.
Example:
SELECT TO_TINYINT('10') "to tinyint" FROM dual;
56
to tinyint
10
TO_TIME Function
Syntax:
TO_TIME(expr [, format])
Description:
Converts the expr of a data type into a value of TIME data type.
If format is omitted, it converts expr into the corresponding format using the date format model as
explained in Table 4.
Example:
SELECT TO_TIME ('13:30:00') "to time" FROM dual;
Retrieves:
to time
13:30:00
TO_TIMESTAMP Function
Syntax:
TO_TIMESTAMP(expr [, format])
Description:
Converts the expr of a data type into the TIMESTAMP data type.
If format is omitted, it converts expr into the corresponding format using the date format model as
explained in Table 4.
Example:
SELECT TO_TIMESTAMP ('2010-01-11 13:30:00', 'YYYY-MM-DD HH24:MI:SS') "to timestamp"
FROM dual;
Retrieves:
to timestamp
2010-01-11 13:30:00.000
Miscellaneous Functions
COALESCE Function
Syntax :
COALESCE(expr_list)
Description:
Computes the first non-null expr_list in the expression list. If all the values of expr are null, it returns
null.
Example:
SELECT * FROM tab;
57
ID
1
2
3
A
100.0
NULL
NULL
B
80.0
63.0
NULL
ID
1
2
3
A
100.0
NULL
NULL
B
80.0
63.0
NULL
coalesce
100
69.3
50
IFNULL Function
Syntax:
IFNULL(expr1, expr2)
Description:
Returns expr1 if expr1 is not null and expr2 if expr1 is null.
Example:
SELECT NULLIF('diff', 'same') "ifnull" FROM dual;
Retrieves:
ifnull
diff
NULLIF Function
Syntax:
NULLIF(expr1, expr2)
Description:
Compares expr1 and expr2. Returns null if both values are the same and returns expr1 if they are not
the same. The expr1 cannot be specified with the literal NULL.
Example:
SELECT NULLIF('diff', 'same') "nullif" FROM dual;
Retrieves:
nullif
diff
SELECT NULLIF('same', 'same') "nullif" FROM dual;
Retrieves:
nullif
NULL
NVL Function
Syntax:
NVL(expr1, expr2)
58
ID
1
2
3
A
100.0
NULL
NULL
B
80.0
63.0
NULL
nvl
100.0
63.0
NULL
CURRENT_CONNECTION Function
Syntax:
CURRENT_CONNECTION
Description:
Returns the current connection id.
Example:
SELECT CURRENT_CONNECTION "current connection" FROM dual;
Retrieves:
current connection
2
CURRENT_SCHEMA Function
Syntax:
CURRENT_SCHEMA
Description:
Returns the current schema name in the string.
Example:
SELECT CURRENT_SCHEMA "current schema" FROM dual;
Retrieves:
current schema
SYSTEM
CURRENT_USER Function
Syntax:
CURRENT_USER
59
current user
SYSTEM
DATABASE Function
Syntax:
DATABASE()
Description:
Returns the current schema name.
Example:
SELECT DATABASE() FROM dual;
Retrieves:
current schema
SYSTEM
GROUPING_ID Function
Syntax:
GROUPING_ID(column_name_list)
Description:
GROUPING_ID function can be used with GROUPING SETS to return multiple levels of aggregations in
a single result set. GROUPING_ID returns an integer value to identify which grouping set each row
belongs to. Each column in GROUPING_ID must be an element of the GROUPING SETS.
GROUPING_ID is assigned by converting the bit vector generated from GROUPING SETS to a decimal
number by treating the bit vector as a binary number. When a bit vector is composed, 0 is assigned to
each column specified in the GROUPING SETS and 1 otherwise in the order it appears in the
GROUPING SETS. By treating the bit vector as a binary number, this function returns an integer value
as the output.
Example:
SELECT customer, year, product, SUM(sales),
GROUPING_ID(customer, year, product)
FROM guided_navi_tab
GROUP BY GROUPING SETS
(
(customer, year, product),
(customer, year),
(customer, product),
(year, product),
(customer),
(year),
(product)
);
60
CUSTOMER YEAR
PRODUCT SUM(SALES)
GROUPING_ID(CUSTOMER,YEAR,PRODUCT)
C1
2009 P1
100
C1
2010 P1
50
C2
2009 P1
200
C2
2010 P1
100
C1
2009 P2
200
C1
2010 P2
150
C2
2009 P2
300
C2
2010 P2
150
C1
2009 ?
300
10
C1
2010 ?
200
11
C2
2009 ?
500
12
C2
2010 ?
250
13
C1
P1
150
14
C2
P1
300
15
C1
P2
350
16
C2
P2
450
17
2009 P1
300
18
2010 P1
150
19
2009 P2
500
20
2010 P2
300
21
C1
500
22
C2
750
23
2009 ?
800
24
2010 ?
450
25
P1
450
26
P2
800
SESSION_CONTEXT Function
Syntax:
SESSION_CONTEXT(session_parameter)
Description:
Returns the value of session_parameter assigned to the current user or the value of a personal setting.
The parameter has to be set when the user is created.
Example:
SELECT SESSION_CONTEXT(conn_Id) session context FROM dual;
Retrieves:
session context
4
61
SYSUUID
4DE3CD576C79511BE10000000A3C2220
62
SQL Statements
This chapter describes the SQL statements that are provided by SAP IMDB.
Description
DDL
DCL
(Data Control Language)
63
64
GENERATED ALWAYS AS
Specifies the expression to generate the column value in runtime.
column_constraint ::= NULL | NOT NULL | UNIQUE [BTREE | CPBTREE]
|PRIMARY KEY [BTREE | CPBTREE]
NULL | NOT NULL
Constraint prohibits a column value from being null.
If the NULL constraint is specified, it is not considered a constraint. It
represents a column that may contain a null value.
If neither NOT NULL nor NULL constraint is specified, it defaults to null.
UNIQUE
Specifies a column as a unique key.
A composite unique key enables the specification of multiple columns as a
unique key. A unique constraint prohibits multiple rows from having the same
value in the same column.
PRIMARY KEY
A primary key constraint is a combination of a NOT NULL constraint and a
UNIQUE constraint. It prohibits multiple rows from having the same value in
the same column.
BTREE | CPBTREE
Specifies the index type. When column data types are character string types,
binary string types, decimal types, or when the constraint is a composite key,
or non-unique constraint, the default index type is CPBTREE. Otherwise,
BTREE is used.
BTREE keyword has to be used in order to use B+-tree index and the CPBTREE
keyword has to be used for the CPB+-tree index.
If the index type is omitted, SAP IMDB chooses the appropriate index
considering the column data types.
table_constraint ::=UNIQUE [BTREE | CPBTREE] | PRIMARY KEY [BTREE |
CPBTREE]
Table constraint defines a table constraint which can be defined on one or
more columns of a table. There are two kinds of a table constraint. They are:
UNIQUE
Specifies a uniqueness constraint for a table. A unique constraint prohibits
multiple rows from having the same values in the same column list.
PRIMARY KEY
A primary key constraint is a combination of a NOT NULL constraint and a
UNIQUE constraint. It prohibits multiple rows from having the same value in
the same primary key.
BTREE | CPBTREE
Specifies the index type. When column data types are character string types,
binary string types, decimal types, or when the constraint is a composite key,
or non-unique constraint, the default index type is CPBTREE, BTREE is used
otherwise.
BTREE keyword has to be used in order to use the B+-tree index and the
CPBTREE keyword has to be used for the CPB+-tree index.
65
66
parameter_key_value
'AUTO_MERGE' = 'ON' | 'OFF'
Default=ON
Automatic delta merge triggered by memwatcher.
'SESSION_TYPE' = 'SIMPLE' | 'HISTORY'
Default = 'SIMPLE'
Creates a table with a certain transaction session type. Tables with session type HISTORY
support time travel.
'COMPRESSION' = ('column_name', 'compression_type'):
Sets the compression for the specified column. ('compression_type' = 'PREFIXED' | 'SPARSE' |
'CLUSTERED' | 'INDIRECT' | 'RLE')
'INDEX' = ('column_name', 'index_type')
Sets the inverted index for the specified column. ('index_type' 'FULL' | 'SIGNATURE')
'FAST_PREPROCESS' = 'ON' | 'OFF'
Turns fast preprocessing on or off. This feature is used for column tables that have attributes
that should support text-search on attribute of type 'AETEXT'.
'LOCATION' = 'host:port'
Specifies the target node for creation with host:port. If not given, the table will be
automatically assigned to one node.
'PARTITION_SPEC' = 'partition spec',
For example 'HASH 2 a, b' where 2 is the number of parts to create and 'a' and 'b' are the
columns that are used to create that hash value for each row.
'TREX_FLAGS' = ('column_name','flags'),
Flags are the implementation flags, integer value is currently between 0 and 67108864.
Description:
The CREATE TABLE statement creates a table. Tables are created with no data. A user can add data
to a table with the INSERT statement.
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
sequence_name.CURRVAL
sequence_name.NEXTVAL
When you create a sequence for the first time, NEXTVAL pseudocolumn can be used to get the initial
value of the sequence. An error occurs if CURVAL is used before using NEXTVAL.
The sequence value is manipulated in the memory so that SAP IMDB guarantees the efficiency of
generating a sequence value. In such a case, to avoid the sequence value loss when rebooting a
database, a RESET BY statement has to be used to automatically assign the user-specified value.
During the rebooting of the database, SAP IMDB automatically executes the RESET BY statement and
returns the result to assign the sequence value. Therefore, no additional effort is needed to manage a
sequence.
Example 2:
If the sequence s is used to create a unique key on column A in the table R, then after a database is
rebooted, a UNIQUE key value can be created by automatically assigning the maximum value of
column A to the sequence value using a RESET BY statement as follows:
create sequence s reset by select nvl(max(a), 0) + 1 from r;
A sequence can be created with the following parameters.
83
84
85
86
87
88
89
90
91
A
1
B
2.0
242.0
11
22.0
24642.0
111
222.0
92
93
94
95
96
97
98
99
100
101
sqltrace
session
sql
transaction
Configuration Parameter
Default
Value
Possible Value
Online
reconfigurabl
e with 'alter
system inifile'
trace
off
on/off
yes
level
none
normal,error,rollback
,all,all_with_results
yes
flush_interval
seconds
yes
statement_type
all
yes
user
all
all, username
yes
object
all
yes
tracefile
trace/sqltrace
.py
protocol_trace
off
maximum_connections
8192
no
default_prefetched_rows
32
yes
table_onversion_parallelis
m
default_table_type
yes
row
yes
query_cache_size
268435456
byte
yes
sql_executors
yes
lock_wait_timeout
300000
in ms
yes
yes
on/off
yes
KILL|STOP|RECONFIGURE SERVICE
KILL SERVICE kills the running service.
STOP SERVICE stops the service.
RECONFIGURE SERVICE reconfigures the service with current parameters.
KILL SESSION
Kills the specified session.
QUERY CACHE FLUSH
Flushes the query cache.
SET MONITOR LEVEL
Sets the monitoring level.
102
103
104
105
System Management
These privileges authorize the various system activities which can be performed using the ALTER
SYSTEM commands. Because of the high level of impact on the system, these privileges are not
relevant to a normal database user and should only be granted with care (for example, only to a
support user/role.)
Below is a short overview of the relevant privileges, while detailed descriptions can be found under
Alter System Privileges.
BACKUP ADMIN: This privilege authorizes the commands ALTER SYSTEM BACKUP for defining
and initiating a backup process or to perform a recovery process.
CHECKPOINT ADMIN: This privilege authorizes the commands ALTER SYSTEM
[ENABLE|DISABLE] CHECKPOINT for enabling/disabling the checkpoint mechanism.
CHECKPOINT EXEC: This privilege authorizes the execution of a checkpoint process via the
command ALTER SYSTEM CHECKPOINT.
106
107
Sequence Synonym
Function/Procedure
CREATE ANY
OK
ALL
PRIVILEGES
DROP
OK
OK
OK
OK
OK
OK
OK
OK
OK
ALTER
OK
OK
OK
OK
OK
SELECT
OK
OK
OK
OK
OK
INSERT
OK
OK
OK
OK
UPDATE
OK
OK
OK
OK
DELETE
OK
OK
OK
OK
INDEX
OK
OK
OK
EXECUTE
OK
OK
Notes:
CREATE ANY: This privilege allows the creation of all kinds of objects, in particular tables,
views, sequences, synonyms, SQL Script functions, or DB procedures in a schema. Obviously,
this privilege can only be granted on a schema.
ALL PRIVILEGES: This is actually a collection of all DDL and DML privileges, which a) the
grantor currently has and is allowed to grant further, and b) can be granted on this particular
object. This collection is dynamically evaluated for the given grantor and object. ALL
PRIVILEGES is not applicable to a schema, but only a table, view, or table type.
DROP and ALTER are DDL privileges and authorize the DROP and ALTER SQL commands.
While the DROP privilege is valid for all kinds of objects, the ALTER privilege is not valid for
sequences and synonyms as their definitions cannot be changed after creation.
INDEX is a special DDL privilege and authorizes the creation/changing/dropping of indexes for
an object via the commands CREATE INDEX, DROP INDEX, and ALTER INDEX. This privilege
can only be applied to schema, table, and table type.
SELECT, INSERT, UPDATE and DELETE are DML privileges and authorize respective SQL
commands. While SELECT is valid for all kinds of objects, except for functions/procedures,
INSERT, UPDATE, and DELETE are valid for schemas, tables, and table types only.
EXECUTE is a special DML privilege and authorizes the execution of a SQL Script function or a
DB procedure via the commands CALLS or CALL, respectively.
All DDL and DML privileges are valid for schemas in the sense that they authorize applicable
activities on the objects created in this schema.
Synonyms can be created for tables, views, sequences, and database procedures, but not for
schemas and SQL Script functions. The privileges which can be granted and revoked on a
synonym will be determined by the actual object the synonym stands for.
108
109
110
111
112
113
114
115
116
DISTINCT, ALL
DISTINCT returns only one copy of each set of duplicate rows selected.
ALL statement returns all rows selected, including all copies of duplicates. The default is ALL.
select_list
The select list allows users to specify the columns they want to retrieve from the database.
* [asterisk] selects all the data in all columns from all tables or views listed in the FROM clause
column_alias, table_alias
The user may rename the existing column or table name.
from_clause ::= FROM table,
table ::= table_name [ [AS] table_alias ] | ( subquery ) [ [AS] table_alias ] | joined_table
joined_table ::= table [join_type] JOIN table ON condition | table CROSS JOIN table |
( joined_table )
join_type::=INNER | {{LEFT | RIGHT | FULL} OUTER}where_clause::=WHERE
condition
The join_type specifies the types of join being performed. RIGHT indicates a right
outer join, LEFT indicates a left outer join, and FULL indicates a full outer join. The
OUTER keyword may or may not be used when an outer join is being performed.
ON condition
The ON clause specifies a join condition.
CROSS JOIN
The CROSS keyword indicates that a cross join is being performed. A cross join
produces the cross-product of two relations and is identical with the comma-delimited
(,) notation.
where_clause
The WHERE condition is used to specify a condition on the records to be selected and the user
therefore can retrieve the desired data.
having_clause::=HAVING condition
The HAVING keyword is used to select the specified groups that satisfy the conditions. If this
keyword is omitted, all groups are selected.
order_by_clause
The ORDER BY keyword sorts the results of a query.
The ORDER BY clause can only sort the records by the field specified in SELECT statement. The
ASC keyword sorts the result in ascending order and the ASC keyword sorts the result in
descending order. The default value is ASC.
117
118
Description
OPERATOR_NAME
The string specified as PLAN_ID on executing the EXPLAIN PLAN command. This is used
to distinguish plans from each other when there are multiple plans in the QUERY_PLANS
view.
Name of an operator. Details are described in the following section.
OPERATOR_DETAILS
Details of an operator. Predicates and expressions used by the operator are shown here.
OBJECT_NAME
119
Description
SUBTREE_COST
Estimated cost of executing the subtree starting from an operator. The unit of this value
is time in seconds, but the absolute value would not match the actual execution time.
This value is only for relative comparisons between different subtrees.
INPUT_CARDINALITY
OUTPUT_CARDINALITY
Estimated input row count of an operator. This is available only for operators accessing
tables and views directly. For column store, estimation is done in row granularity, but
for row store, estimation is done in page granularity and there can be large errors for
small tables.
Estimated output row count of an operator.
OPERATOR_ID
PARENT_OPERATOR_ID
OPERATOR_ID of the parent of an operator. The shape of a query plan is a tree and the
topology of the tree can be reconstructed using OPERATOR_ID and
PARENT_OPERATOR_ID. PARENT_OPERATOR_ID of the root operator is shown as 0.
LEVEL
Level from the root operator. Level of the root operator is 1, level of a child of the root
operator is 2 and so on. This can be utilized for output indentation.
POSITION
Position in the parent operator. Position of the first child is 0, position of the second
child is 1 and so on.
TIMESTAMP
Date and time when the EXPLAIN PLAN command was executed.
Description
LIMIT
ORDER BY
HAVING
GROUP BY
DISTINCT
FILTER
JOIN
COLUMN TABLE
MULTIPROVIDER
Table 19. List of row engine operators shown in the OPERATOR_NAME column.
Operator Name
Description
ROW SEARCH
LIMIT
ORDER BY
HAVING
GROUP BY
MERGE AGGREGATION
Operator for merging the results of multiple parallel grouping and aggregations
120
Description
DISTINCT
FILTER
UNION ALL
MATERIALIZED UNION ALL Operator for producing union-all of input relations with intermediate result
materialization
BTREE INDEX JOIN
Operator for joining input relations through B-Tree index searches. Join type suffix can
be added. For example, B-Tree index join for left outer join is shown as BTREE INDEX
JOIN (LEFT OUTER). Join without join type suffix means inner join.
Operator for joining input relations through CPB-Tree index searches. Join type suffix
can be added.
HASH JOIN
Operator for joining input relations through probing hash table built on the fly. Join
type suffix can be added.
Operator for joining input relations through nested looping. Join type suffix can be
added.
TABLE SCAN
AGGR TABLE
MONITOR SEARCH
MONITOR SCAN
COLUMN SEARCH is a mark for the starting position of column engine operators and ROW SEARCH is a
mark for the starting position of row engine operators.
In the example below, the intermediate result produced by the red COLUMN SEARCH is consumed by
the blue ROW SEARCH, and the intermediate result produced by the blue ROW SEARCH is consumed
by the black COLUMN SEARCH at the root.
The operators below the red COLUMN SEARCH explain how the red COLUMN SEARCH is executed. The
operators between the blue ROW SEARCH and the red COLUMN SEARCH explain how the blue ROW
SEARCH processes the intermediate result produced by the red COLUMN SEARCH. The operators
between the black COLUMN SEARCH and the blue ROW SEARCH explain how the black COLUMN
SEARCH processes the intermediate result produced by the blue ROW SEARCH.
Table 20. Operators
operator_name
COLUMN SEARCH
LIMIT
ORDER BY
GROUP BY
JOIN
COLUMN TABLE
ROW SEARCH
BTREE INDEX JOIN
operator_id
parent_operator_id
level
position
121
operator_id
parent_operator_id
level
position
10
11
10
10
12
11
11
122
LIMIT
ORDER BY
operator_details
CUSTOMER.C_CUS
TKEY,
CUSTOMER.C_NAM
E,
SUM(LINEITEM.L_E
XTENDEDPRICE *
(1 LINEITEM.L_DISCO
UNT)),
CUSTOMER.C_ACC
TBAL,
NATION.N_NAME,
CUSTOMER.C_ADD
RESS,
CUSTOMER.C_PHO
NE,
CUSTOMER.C_COM
MENT
NUM RECORDS: 20
SUM(LINEITEM.L_E
XTENDEDPRICE *
(1 LINEITEM.L_DISCO
UNT)) DESC
NUM PARTITIONS:
MERGE
AGGREGATIO 4
N
GROUP GROUPING:
BY
CUSTOMER.C_CUS
TKEY,
CUSTOMER.C_NAM
E,
CUSTOMER.C_ACC
TBAL,
CUSTOMER.C_PHO
NE,
NATION.N_NAME,
CUSTOMER.C_ADD
RESS,
CUSTOMER.C_COM
MENT,
AGGREGATION:
SUM(LINEITEM.L_E
XTENDEDPRICE *
(1 LINEITEM.L_DISCO
UNT))
CPBTR INDEX NAME:
_SYS_TREE_964_#
EE INDEX
0_#P0, INDEX
JOIN
CONDITION:
ORDERS.O_ORDER
KEY =
LINEITEM.L_ORDER
KEY, INDEX
FILTER: 'R' =
LINEITEM.L_RETUR
NFLAG
object
_name
subtre
e_cost
input_car
dinality
output_ca
rdinality
operat
or_id
parent_op
erator_id
le
ve
l
posi
tion
None
0.0158 None
06
20
None
0.0156 None
75
0.0156 None
69
20
409.2
None
None
0.0045 None
74
409.2
None
0.0045 None
74
409.2
R_LINEI
TEM
0.0035
62
257.04
6426
123
operator_details
object
_name
subtre
e_cost
input_car
dinality
output_ca
rdinality
operat
or_id
parent_op
erator_id
le
ve
l
posi
tion
R_NATI
ON
0.0028
05
3840
409.2
R_CUST
OMER
0.0026
13
2557.5
409.2
R_ORD
ERS
0.0024
23
2557.5
409.2
E INDEX
JOIN
124
is:
is:
is:
is:
correct!","31323334353637383930"
correct!","31323334353637383930"
correct!","31323334353637383930"
correct!","31323334353637383930"
125
126
127
128
Appendix
Restrictions for SQL Statements
Database
Maximum number of schemas
Maximum number of Users
Unlimited
Unlimited
Unlimited for record locks, 16384 for
table locks
Limited by configuration parameter,
"maximum_sessions", limited by OS limit
Limited by storage size RS: 1TB, CS: 2^31
* number of partitions
Schemas
Maximum number of objects in a schema
Maximum number of tables in a schema
Length of an identifier
Length of an alias name
Unlimited
131072
127 characters
128 characters
1023
1023
Limited by storage size RS: 1TB, CS: 2^31
* number of partitions
Limited by RS storage size ( 1TB )
Limited by RS storage size ( 1TB )
1023
16
16
16
16KB
SQL
Maximum length of an SQL statement
Maximum depth of SQL view nesting
Maximum depth of SQL parse tree
2GB
128
255
1,000,000
Approximately 2^31
129
Approximately 2^31
Approximately 2^31
Approximately 2^31
Unlimited
Approximately 2^31
Approximately 2^31
2^31
2^64
Approximately 2^31
Approximately 2^31
Unlimited
Maximum number of SET clauses in a single update operation Approximately 2^31
SQLScript
Maximum size of all stored procedures
Collation
A collation is used to distinguish each character set from the Unicode data types (NCHAR, NVARCHAR,
and NCLOB). A collation is used as follows:
NCHAR( n ) [COLLATE collation_name]
A collation_name consists of 'lcode'_'ccode', where lcode is a language code, and ccode is a country
code.
Language Code
The following table lists the language code provided in SAP IMDB.
Table 21. Language code
Language Name
Language Code
Afar
aa
Abkhazian
ab
Afrikaans
af
Amharic
ma
Arabic
ar
130
Language Code
Assamese
as
Aymara
ay
Azerbaijani
az
Bashkir
ba
Byelorussian
be
Bulgarian
bg
Bihari
bh
Bislama
bi
Bengali; Bangla
bn
Tibetan
bo
Breton
br
Catalan
ca
Corsican
co
Czech
cs
Welsh
cy
Danish
da
German
de
Bhutani
dz
Greek
el
English
en
Esperanto
eo
Spanish
es
Estonian
et
Basque
eu
Persian
fa
Finnish
131
Language Code
Fiji
fj
Faeroese
fo
French
fr
Frisian
fy
Irish
ga
Scots
gd
Galician
gl
Guarani
gn
Gujarati
gu
Hausa
ha
Hindi
hi
Croatian
hr
Hungarian
hu
Armenian
hy
Interlingua
ia
Interlingue
ie
Inupiak
ik
Indonesian
in
Icelandic
is
Italian
it
Hebrew
iw
Japanese
ja
Yiddish
ji
Javanese
jw
132
Language Code
Georgian
ka
Kazakh
kk
Greenlandic
kl
Cambodian
km
Kannada
kn
Korean
ko
Kashmiri
ks
Kurdish
ku
Kirghiz
ky
Latin
la
Lingala
ln
Laotian
lo
Lithuanian
lt
Latvian
lv
Malagasy
mg
Maori
mi
Macedonian
mk
Malayalam
ml
Mongolian
mn
Moldavian
mo
Marathi
mr
Malay
ms
Maltese
mt
Burmese
my
133
Language Code
Nauru
na
Nepali
ne
Dutch
nl
Norwegian
no
Occitan
oc
(Afan)
om
Oriya
or
Punjabi
pa
Polish
pl
Pashto
ps
Portuguese
ps
Quechua
qu
Rhaeto-Romance
rm
Kirundi
rn
Romanian
ro
Russian
ru
Kinyarwanda
rw
Sanskrit
sa
Sindhi
sd
Sangro
sg
Serbo-Croatian
sh
Singhalese
si
Slovak
sk
Slovenian
sl
Samoan
sm
134
Language Code
Shona
sn
Somali
so
Albanian
sq
Serbian
sr
Siswati
ss
Sesotho
st
Sudanese
su
Swedish
sv
Swahili
sw
Tamil
ta
Tegulu
te
Tajik
tg
Thai
th
Tigrinya
ti
Turkmen
tk
Tagalog
tl
Setswana
tn
Tonga
to
Turkish
tr
Tsonga
ts
Tatar
tt
Twi
tw
Ukrainian
uk
Urdu
ur
Uzbek
uz
135
Language Code
Vietnamese
vi
Volapuk
vo
Wolof
wo
Xhosa
xh
Yoruba
yo
Chinese
zh
Zulu
zu
Country Code
The following table lists the country codes provided in SAP IMDB.
Table 22. Country codes
Country Name
Country Code
AFGHANISTAN
AF
LANDISLANDS
AX
ALBANIA
AL
ALGERIA
DZ
AMERICAN SAMOA
AS
ANDORRA
AD
ANGOLA
AO
ANGUILLA
AI
ANTARCTICA
AQ
AG
ARGENTINA
AR
ARMENIA
AM
ARUBA
AW
AUSTRALIA
AU
136
Country Code
AUSTRIA
AT
AZERBAIJAN
AZ
BAHAMAS
BS
BAHRAIN
BH
BANGLADESH
BD
BARBADOS
BB
BELARUS
BY
BELGIUM
BE
BELIZE
BZ
BENIN
BJ
BERMUDA
BM
BHUTAN
BT
BOLIVIA
BO
BA
BOTSWANA
BW
BOUVET ISLAND
BV
BRAZIL
BR
IO
BRUNEI DARUSSALAM
BN
BULGARIA
BG
BURKINA FASO
BF
BURUNDI
BI
CAMBODIA
KH
CAMEROON
CM
CANADA
CA
CAPE VERDE
CV
137
Country Code
CAYMANISLANDS
KY
CENTRALAFRICANREPUBLIC
CF
CHAD
TD
CHILE
CL
CHINA
CN
CHRISTMAS ISLAND
CX
CC
COLOMBIA
CO
COMOROS
KM
CONGO
CG
CD
COOKISLANDS
CK
COSTA RICA
CR
CTE D'IVOIRE
CI
CROATIA
HR
CUBA
CU
CYPRUS
CY
CZECH REPUBLIC
CZ
DENMARK
DK
DJIBOUTI
DJ
DOMINICA
DM
DOMINICAN REPUBLIC
DO
ECUADOR
EC
EGYPT
EG
EL SALVADOR
SV
EQUATORIAL GUINEA
GQ
138
Country Code
ERITREA
ER
ESTONIA
EE
ETHIOPIA
ET
FK
FAROE ISLANDS
FO
FIJI
FJ
FINLAND
FI
FRANCE
FR
FRENCH GUIANA
GF
FRENCH POLYNESIA
PF
TF
GABON
GA
GAMBIA
GM
GEORGIA
GE
GERMANY
DE
GHANA
GH
GIBRALTAR
GI
GREECE
GR
GREENLAND
GL
GRENADA
GD
GUADELOUPE
GP
GUAM
GU
GUATEMALA
GT
GUINEA
GN
GUINEA-BISSAU
GW
139
Country Code
GUYANA
GY
HAITI
HT
HM
VA
HONDURAS
HN
HONG KONG
HK
HUNGARY
HU
ICELAND
IS
INDIA
IN
INDONESIA
ID
IR
IRAQ
IQ
IRELAND
IE
ISRAEL
IL
ITALY
IT
JAMAICA
JM
JAPAN
JP
JORDAN
JO
KAZAKHSTAN
KZ
KENYA
KE
KIRIBATI
KI
KP
KOREA, REPUBLIC OF
KR
KUWAIT
KW
KYRGYZSTAN
KG
LA
140
Country Code
LATVIA
LV
LEBANON
LB
LESOTHO
LS
LIBERIA
LR
LY
LIECHTENSTEIN
LI
LITHUANIA
LT
LUXEMBOURG
LU
MACAO
MO
MK
MADAGASCAR
MG
MALAWI
MW
MALAYSIA
MY
MALDIVES
MV
MALI
ML
MALTA
MT
MARSHALL ISLANDS
MH
MARTINIQUE
MQ
MAURITANIA
MR
MAURITIUS
MU
MAYOTTE
YT
MEXICO
MX
FM
MOLDOVA, REPUBLIC OF
MD
MONACO
MC
MONGOLIA
MN
141
Country Code
MONTSERRAT
MS
MOROCCO
MA
MOZAMBIQUE
MZ
MYANMAR
MM
NAMIBIA
NA
NAURU
NR
NEPAL
NP
NETHERLANDS
NL
NETHERLANDS ANTILLES
AN
NEW CALEDONIA
NC
NEW ZEALAND
NZ
NICARAGUA
NI
NIGER
NE
NIGERIA
NG
NIUE
NU
NORFOLK ISLAND
NF
MP
NORWAY
NO
OMAN
OM
PAKISTAN
PK
PALAU
PW
PALESTINIANTERRITORY, OCCUPIED
PS
PANAMA
PA
PG
PARAGUAY
PY
PERU
PE
142
Country Code
PHILIPPINES
PH
PITCAIRN
PN
POLAND
PL
PORTUGAL
PT
PUERTO RICO
PR
QATAR
QA
RUNION
RE
ROMANIA
RO
RUSSIAN FEDERATION
RU
RWANDA
RW
SAINT HELENA
SH
KN
SAINT LUCIA
LC
PM
VC
SAMOA
WS
SAN MARINO
SM
ST
SAUDI ARABIA
SA
SENEGAL
SN
CS
SEYCHELLES
SC
SIERRA LEONE
SL
SINGAPORE
SG
SLOVAKIA
SK
SLOVENIA
SI
143
Country Code
SOLOMON ISLANDS
SB
SOMALIA
SO
SOUTH AFRICA
ZA
GS
SPAIN
ES
SRI LANKA
LK
SUDAN
SD
SURINAME
SR
SJ
SWAZILAND
SZ
SWEDEN
SE
SWITZERLAND
CH
SYRIANARABREPUBLIC
SY
TAIWAN, PROVINCEOFCHINA
TW
TAJIKISTAN
TJ
TZ
THAILAND
TH
TIMOR-LESTE
TL
TOGO
TG
TOKELAU
TK
TONGA
TO
TT
TUNISIA
TN
TURKEY
TR
TURKMENISTAN
TM
TC
144
Country Code
TUVALU
TV
UGANDA
UG
UKRAINE
UA
AE
UNITED KINGDOM
GB
UNITED STATES
US
UM
URUGUAY
UY
UZBEKISTAN
UZ
VANUATU
VU
VE
VIET NAM
VN
VIRGINISLANDS, BRITISH
VG
VIRGIN ISLANDS,U.S.
VI
WF
WESTERN SAHARA
EH
YEMEN
YE
ZM
ZIMBABWE
ZW
145