Sei sulla pagina 1di 146

SAP In-Memory Database - SQL Reference Manual

SAP In-Memory Appliance (SAP HANA) 1.0

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

Copyright 2011 SAP AG. All rights reserved.


JavaScript is a registered trademark of Sun Microsystems, Inc., used
No part of this publication may be reproduced or transmitted in any

under license for technology invented and implemented by Netscape.

form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior notice.

SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, PartnerEdge,


ByDesign, SAP Business ByDesign, and other SAP products and

Some software products marketed by SAP AG and its distributors

services mentioned herein as well as their respective logos are

contain proprietary software components of other software vendors.

trademarks or registered trademarks of SAP AG in Germany and in


several other countries all over the world. All other product and service

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered

names mentioned are the trademarks of their respective companies. Data

trademarks of Microsoft Corporation.

contained in this document serves informational purposes only. National


product specifications may vary.

IBM, DB2, DB2 Universal Database, System i, System i5, System p,


System p5, System x, System z, System z10, System z9, z10, z9,

These materials are subject to change without notice. These materials

iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390,

are provided by SAP AG and its affiliated companies ("SAP Group")

OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM,

for informational purposes only, without representation or warranty of

Power Architecture, POWER6+, POWER6, POWER5+, POWER5,

any kind, and SAP Group shall not be liable for errors or omissions with

POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System

respect to the materials. The only warranties for SAP Group products

Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks,

and services are those that are set forth in the express warranty

OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere,

statements accompanying such products and services, if any. Nothing

Netfinity, Tivoli and Informix are trademarks or registered trademarks

herein should be construed as constituting an additional warranty.

of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and

Disclaimer

other countries.

Some components of this product are based on Java. Any code


change in these components may cause unpredictable and severe

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either

malfunctions and is therefore expressively prohibited, as is any

trademarks or registered trademarks of Adobe Systems Incorporated in

decompilation of these components.

the United States and/or other countries.


Any Java Source Code delivered with this product is only to be used
Oracle is a registered trademark of Oracle Corporation.

by SAPs Support Services and may not be modified or altered in any


way.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open

Documentation in the SAP Service Marketplace

Group.

You can find this documentation at the following Internet address:

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame,

service.sap.com/hana

VideoFrame, and MultiWin are trademarks or registered trademarks of


Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered
trademarks of W3C, World Wide Web Consortium, Massachusetts
Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc

SAP In-Memory Database: SQL Reference Manual

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

SAP In-Memory Database: SQL Reference Manual


Concatenation Operators .................................................................................................................. 24
Comparison Operators ...................................................................................................................... 24
Logical Operators............................................................................................................................... 26
Set Operators .................................................................................................................................... 26
Expressions ........................................................................................................................................... 28
Simple Expressions ............................................................................................................................ 28
Compound Expressions...................................................................................................................... 28
Case Expressions ............................................................................................................................... 28
Function Expressions ......................................................................................................................... 28
Aggregate Expressions ....................................................................................................................... 28
Scalar Subquery Expressions .............................................................................................................. 28
Functions .............................................................................................................................................. 29
SQL Function ..................................................................................................................................... 29
Function Format ................................................................................................................................ 29
Number Functions ............................................................................................................................. 30
ABS Function ................................................................................................................................. 30
ACOS Function ............................................................................................................................... 30
ASIN Function ................................................................................................................................ 30
ATAN Function............................................................................................................................... 31
ATAN2 Function ............................................................................................................................. 31
BITAND Function............................................................................................................................ 31
CEIL / CEILING Function ................................................................................................................. 31
COS Function ................................................................................................................................. 32
COSH Function ............................................................................................................................... 32
COT Function ................................................................................................................................. 32
EXP Function.................................................................................................................................. 32
FLOOR Function ............................................................................................................................. 33
GREATEST Function........................................................................................................................ 33
LEAST Function .............................................................................................................................. 33
LN Function ................................................................................................................................... 34
LOG Function ................................................................................................................................. 34
MOD Function ............................................................................................................................... 34
3

SAP In-Memory Database: SQL Reference Manual


POWER Function............................................................................................................................ 35
ROUND Function............................................................................................................................ 35
SIGN Function ................................................................................................................................ 35
SIN Function .................................................................................................................................. 36
SINH Function ................................................................................................................................ 36
SQRT Function ............................................................................................................................... 36
TAN Function ................................................................................................................................. 36
TANH Function............................................................................................................................... 37
Character Functions ........................................................................................................................... 37
ASCII Function................................................................................................................................ 37
CHR Function ................................................................................................................................. 37
CONCAT Function .......................................................................................................................... 37
INSTR Function .............................................................................................................................. 38
LEFT Function ................................................................................................................................ 38
LCASE Function .............................................................................................................................. 38
LENGTH Function ........................................................................................................................... 39
LOCATE Function ........................................................................................................................... 39
LOWER Function ............................................................................................................................ 39
LPAD Function ............................................................................................................................... 39
LTRIM Function.............................................................................................................................. 40
NCHR Function .............................................................................................................................. 40
REPLACE Function .......................................................................................................................... 40
RIGHT Function .............................................................................................................................. 41
RPAD Function ............................................................................................................................... 41
RTRIM Function ............................................................................................................................. 41
SUBSTR Function ........................................................................................................................... 41
SUBSTR_AFTER Function ................................................................................................................ 42
SUBSTR_BEFORE Function ............................................................................................................. 42
TRIM Function ............................................................................................................................... 42
UCASE Function ............................................................................................................................. 43
UNICODE Function ......................................................................................................................... 43
UPPER Function ............................................................................................................................. 43
4

SAP In-Memory Database: SQL Reference Manual


DateTime Functions ........................................................................................................................... 44
ADD_DAYS Function ...................................................................................................................... 44
ADD_MONTHS Function ................................................................................................................ 44
ADD_YEARS Function ..................................................................................................................... 44
ADD_SECONDS Function ................................................................................................................ 45
CURDATE Function......................................................................................................................... 45
CURTIME Function ......................................................................................................................... 45
DAYS_BETWEEN Function .............................................................................................................. 45
DAYNAME Function ....................................................................................................................... 46
DAYOFMONTH Function ................................................................................................................ 46
DAYOFYEAR Function ..................................................................................................................... 46
EXTRACT Function.......................................................................................................................... 46
HOUR Function .............................................................................................................................. 47
LAST_DAY Function ........................................................................................................................ 47
MINUTE Function........................................................................................................................... 47
MONTH Function ........................................................................................................................... 47
MONTHNAME Function ................................................................................................................. 48
NEXT_DAY Function ....................................................................................................................... 48
NOW Function ............................................................................................................................... 48
SECOND Function .......................................................................................................................... 48
SECONDS_BETWEEN Function ....................................................................................................... 49
SYSDATE Function .......................................................................................................................... 49
SYSTIME Function .......................................................................................................................... 49
SYSTIMESTAMP Function ............................................................................................................... 50
UTCDATE Function ......................................................................................................................... 50
UTCTIME Function ......................................................................................................................... 50
UTCTIMESTAMP Function .............................................................................................................. 50
WEEK Function .............................................................................................................................. 51
WEEKDAY Function ........................................................................................................................ 51
YEAR Function ............................................................................................................................... 51
Conversion Functions ........................................................................................................................ 51
CAST Function................................................................................................................................ 51
5

SAP In-Memory Database: SQL Reference Manual


HEXTORAW Function ..................................................................................................................... 52
TO_BIGINT Function ...................................................................................................................... 52
TO_BINARY Function...................................................................................................................... 52
TO_BLOB Function ......................................................................................................................... 53
TO_CHAR Function ........................................................................................................................ 53
TO_CLOB Function ......................................................................................................................... 53
TO_DATE Function ......................................................................................................................... 53
TO_DATS Function ......................................................................................................................... 54
TO_DECIMAL Function ................................................................................................................... 54
TO_DOUBLE Function .................................................................................................................... 54
TO_INT Function ............................................................................................................................ 54
TO_INTEGER Function.................................................................................................................... 55
TO_NCHAR Function ...................................................................................................................... 55
TO_NCLOB Function ...................................................................................................................... 55
TO_NUMBER Function ................................................................................................................... 56
TO_REAL Function ......................................................................................................................... 56
TO_SMALLINT Function ................................................................................................................. 56
TO_TINYINT Function ..................................................................................................................... 56
TO_TIME Function ......................................................................................................................... 57
TO_TIMESTAMP Function .............................................................................................................. 57
Miscellaneous Functions.................................................................................................................... 57
COALESCE Function........................................................................................................................ 57
IFNULL Function............................................................................................................................. 58
NULLIF Function............................................................................................................................. 58
NVL Function ................................................................................................................................. 58
CURRENT_CONNECTION Function.................................................................................................. 59
CURRENT_SCHEMA Function ......................................................................................................... 59
CURRENT_USER Function............................................................................................................... 59
DATABASE Function ....................................................................................................................... 60
GROUPING_ID Function ................................................................................................................. 60
SESSION_CONTEXT Function .......................................................................................................... 61
SYSUUID Function .......................................................................................................................... 62
6

SAP In-Memory Database: SQL Reference Manual


SQL Statements ..................................................................................................................................... 63
Classification of SQL Statements ........................................................................................................ 63
General Rules for SQL Statements ..................................................................................................... 63
DDL (Data Definition Language) Statements ...................................................................................... 64
CREATE TABLE ............................................................................................................................... 64
DROP TABLE .................................................................................................................................. 68
ALTER TABLE .................................................................................................................................. 69
RENAME TABLE .............................................................................................................................. 72
RENAME COLUMN ......................................................................................................................... 73
CREATE INDEX ............................................................................................................................... 74
DROP INDEX .................................................................................................................................. 75
RENAME INDEX.............................................................................................................................. 76
CREATE VIEW ................................................................................................................................. 77
CREATE COLUMN VIEW ................................................................................................................. 78
DROP VIEW .................................................................................................................................... 81
CREATE SEQUENCE ........................................................................................................................ 82
DROP SEQUENCE ........................................................................................................................... 84
CREATE SYNONYM ......................................................................................................................... 85
DROP SYNONYM ............................................................................................................................ 86
CREATE SCHEMA............................................................................................................................ 87
DROP SCHEMA............................................................................................................................... 88
CREATE TYPE.................................................................................................................................. 89
DROP TYPE..................................................................................................................................... 90
CREATE CALCULATION SCENARIO .................................................................................................. 91
DROP CALCULATION SCENARIO ..................................................................................................... 93
CREATE USER ................................................................................................................................. 94
DROP USER .................................................................................................................................... 95
ALTER USER ................................................................................................................................... 96
CREATE ROLE ................................................................................................................................. 97
ALTER ROLE ................................................................................................................................... 98
DROP ROLE .................................................................................................................................... 99
ALTER SYSTEM ............................................................................................................................. 100
7

SAP In-Memory Database: SQL Reference Manual


ALTER SESSION ............................................................................................................................ 103
SET TRANSACTION ....................................................................................................................... 104
DCL (Data Control Language) Statements......................................................................................... 105
GRANT ......................................................................................................................................... 105
REVOKE ....................................................................................................................................... 109
DML (Data Manipulation Language)................................................................................................. 110
INSERT ......................................................................................................................................... 110
DELETE ........................................................................................................................................ 111
UPDATE ....................................................................................................................................... 112
LOAD ........................................................................................................................................... 113
UNLOAD ...................................................................................................................................... 114
UPSERT / REPLACE ....................................................................................................................... 115
SELECT ......................................................................................................................................... 116
EXPLAIN PLAN.............................................................................................................................. 119
SQL Commands for Export/Import Data ........................................................................................... 125
DUMP TABLE ............................................................................................................................... 125
LOAD FROM ................................................................................................................................. 126
EXPORT........................................................................................................................................ 127
IMPORT ....................................................................................................................................... 128
Appendix ............................................................................................................................................. 129
Restrictions for SQL Statements ....................................................................................................... 129
Collation .......................................................................................................................................... 130
Language Code ............................................................................................................................ 130
Country Code............................................................................................................................... 136

SAP In-Memory Database: SQL Reference Manual

SAP HANA Guides


For more information about SAP HANA landscape, security, installation and administration, see the
resources listed in the table below.
Topic

Guide/Tool

Quick Link

SAP HANA
Landscape,
Deployment &
Installation

SAP HANA Knowledge


Center on SAP Service
Marketplace

https://service.sap.com/hana

SAP HANA
Administration &
Security

SAP HANA Knowledge


Center on SAP Help
Portal

SAP HANA 1.0 Master Guide


SAP HANA 1.0 Installation Guide
http://help.sap.com/hana
SAP HANA 1.0 Technical Operations Manual
SAP HANA 1.0 Security Guide

SAP In-Memory Database: SQL Reference Manual

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.

SQL Reserved Words


This section describes reserved words and SAP IMDB SQL reserved words.
Reserved words are words that have a special meaning and are reserved for future use. Reserved
words are usually used for commands or functions and cannot be used for identifier names such as
databases, tables, or fields. The following table lists the reserved words in SAP IMDB. However, SAP
IMDB allows the use of reserved words as identifiers as long as the SQL grammar does not contain a
fragment statement.
Table 1. SAP IMDB reserved words

ALL

ALTER

AS

BEFORE

BEGIN

BOTH

CASE

CONDITION

CONNECT

CROSS

CUBE

CURRENT_CONNECTION

CURRENT_SCHEMA

CURRENT_USER

CURRVAL

CURSOR

10

SAP In-Memory Database: SQL Reference Manual


DECLARE

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

SAP In-Memory Database: SQL Reference Manual

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 Summary


Classification of Data Types
In SAP IMDB, each data type can be classified by its characteristic as follows.
Table 2. Classification of data types
Classification

Data Type

Datetime types

DATE, TIME, TIMESTAMP

Numeric types

TINYINT, SMALLINT, INTEGER, BIGINT,SMALLDECIMAL, DECIMAL, REAL,


DOUBLE, FLOAT

Character string types

VARCHAR, NVARCHAR

Binary types

VARBINARY

LOB types

BLOB, CLOB, NCLOB

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

SAP In-Memory Database: SQL Reference Manual


Format

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

SAP In-Memory Database: SQL Reference Manual


Format

DECIMAL(p, s) , DEC(p,s), (p, s), or (p, s) where p=precision and s=scale

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

DOUBLE or DOUBLE PRECISION

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

FLOAT (n) or FLOAT

Example

float_value FLOAT(10)

Character String Types


The character string data types are used to store values that contain character strings. While
VARCHAR data types contain ASCII character strings, NVARCHAR are used for storing Unicode
character strings.
VARCHAR
The VARCHAR(n) data type specifies a variable-length ASCII character string, where n indicates
the maximum length and is an integer between 1 and 5000. When n is not specified, it defaults to
the maximum or 5000. An attempt to store a longer string into a column of this type will truncate
the string to the specified maximum length.
Format

VARCHAR(size)

Example

varchar_name VARCHAR(10)

NVARCHAR
The NVARCHAR(n) data type specifies a variable-length Unicode character set string.

14

SAP In-Memory Database: SQL Reference Manual


Format

NVARCHAR(size) [COLLATE collation_name]

Example

nvarchar_name NVARCHAR(10) COLLATE ko_KR

Large Object (LOB) Types


LOB (large objects) data types, CLOB, NCLOB and BLOB, are used to store a large amount of data
such as text documents and images. The maximum size of an LOB is 2GB.
BLOB
The BLOB data type is used to store large binary data.
Format

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

SAP In-Memory Database: SQL Reference Manual


Table 3: Date/time format elements used with strings
Element

Description

DD

Day of month (1-31).

DDD

Day of year (1-366).

FF [1..9]

Fractional seconds. Use the numbers 1 to 9 after FF


to specify the number of digits in the fractional
second portion of the date time value returned.
If a digit is not specified, the default value is used.
Example: 'HH:MI:SS.FF' SELECT
TO_CHAR( SYSTIMESTAMP,'SS.FF3' ) FROM dual;

HH

Hour of day (1-12).

HH12

Hour of day (1-12).

HH24

Hour of day (0-23).

MI

Minute (0-59).

MM

Month (01-12; JAN = 01).

MON

Abbreviated name of month.


(JANUARY = JAN, ... , DECEMBER = DEC).

MONTH

Name of month. (JANUARY - DECEMBER).

RM

Roman numeral month (I-XII; JAN = I).

SS

Second (0-59).

SSSSS

Seconds past midnight (0-86399).

YYYY

4-digit year

YYY

Last 3, 2, or 1 digit(s) of year.

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

SAP In-Memory Database: SQL Reference Manual


Element

Description

Day of week (1-7).

DAY

Name of day (MONDAY - SUNDAY).

DY

Abbreviated name of day


(MONDAY=MON, ... , SUNDAY=SUN).

Quarter of year (1, 2, 3, 4; JANMAR = 1).

Week of month (1-5).

WW

Week of year (1-53).

Data Type Conversion


This section describes the data type conversion allowed in SAP IMDB.
Explicit type conversion
The type of an expression result, for example a field reference, a function on fields, or literals can
be converted using the following functions:
CAST, HEXTORAW, RAWTOHEX, RAWTONHEX, TO_BIGINT, TO_BINARY, TO_BLOB, TO_CLOB,
TO_DATE, TO_DATS, TO_DECIMAL, TO_DOUBLE, TO_INTEGER, TO_NCLOB, TO_NUMBER,
TO_REAL, TO_SMALLINT, TO_TINYINT, TO_TIME, TO_TIMESTAMP.
Implicit type conversion
When a given set of operand/argument types does not match what an operator/function expects,
type conversion is inserted by the system if such a conversion is available and it makes the
operation/function executable. For instance, a comparison of BIGINT and VARCHAR is performed
by implicitly converting VARCHAR to BIGINT. The entire explicit conversions can be used for
implicit conversion except for the TIME and TIMESTAMP data types. TIME and TIMESTAMP can be
converted to each other using TO_TIME(TIMESTAMP) and TO_TIMESTAMP(TIME).
Sample examples
Given Expression

Transformed Expression with Implicit Conversion

BIGINT > VARCHAR BIGINT > BIGINT(VARCHAR)


BIGINT > DECIMAL

DECIMAL(BIGINT) > VARCHAR

TIMESTAMP > DATE TIMESTAMP > TIMESTAMP(DATE)


DATE > TIME

Error because there is no conversion available between DATE and TIME

Known Limitation when converting a data from string to other types


OK: Convertible, ERROR: Not Convertible
Table 5: Limitations

17

SAP In-Memory Database: SQL Reference Manual


Target

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

Table 6: Expressions and errors or comparables


Given Expression

After Implicit Conversion

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'

TIMESTAMP != TIMESTAMP('201106-13 12:00:00')

Comparable

DATE != '12:00:00'

DATE != DATE('12:00:00')

Error because of improper


date type

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')

Comparable because only


the date part is
compared.

TIME != '12:00:00'

TIME != TIME('12:00:00')

Comparable

TIME != '2001-06-13'

TIME != TIME('2011-06-13')

Error because the date


type is not comparable
with the time type.

TIME != '2001-06-13
12:00:00'

TIME != TIME('2011-06-13
12:00:00')

Comparable because the


date part is ignored by
timestamp.

18

SAP In-Memory Database: SQL Reference Manual


In the table below, a green box with OK means data type conversions are allowed without any
checks. An orange box means the data type can be converted if the data is valid for the target type.
Gray boxes indicate that data type conversion is not allowed. The rule is applicable to both implicit and
explicit conversion except for Time to Timestamp conversion. Only explicit conversion is allowed for
converting the Time data type to Timestamp using the TO_TIMESTAMP or CAST function.
Table 7. Data type conversion table
VARBINARY

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

Data Type Precedence


This section describes the data type precedence provided by SAP IMDB. Data type precedence
specifies that the data type with lower precedence is converted to the data type with higher
precedence.

Highest

TIMESTAMP
DATE
TIME
DOUBLE

19

SAP In-Memory Database: SQL Reference Manual


REAL
DECIMAL
BIGINT
INTEGER
SMALLINT
TINYINT
NCLOB
NVARCHAR
CLOB
VARCHAR
BLOB
Lowest

VARBINARY

20

SAP In-Memory Database: SQL Reference Manual

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

SAP In-Memory Database: SQL Reference Manual

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

SAP In-Memory Database: SQL Reference Manual

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.

Unary and Binary Operators


Table 8. Unary and binary operators
Operator

Operation

Format

Description

Unary

A unary operator
applies to one
operand or a single
value expression.

operator operand

unary plus operator(+)

A binary operator
applies to two
operands or two
values expressions.

operand1 operator operand2

Binary

unary negation operator(-)


logical negation(NOT)
multiplicative operators ( *, / ,% )
additive operators ( +,- )
comparison operators
( =,!=,<,>,<=,>=,IS NULL, LIKE,
BETWEEN )
logical operators ( AND, OR )

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

+, -

unary positive and negative operators

*, /

multiplication, division

+, -

addition, subtraction

||

concatenation

=, !=, <, >, <=, >=, IS NULL, LIKE, BETWEEN

comparison operator

NOT

logical negation

AND

conjunction

OR

disjunction

23

SAP In-Memory Database: SQL Reference Manual


Parentheses can be used to override the order of precedence and to force some parts of an expression
to be evaluated before others. Operations within parentheses are always performed before those
outside the parentheses.

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

+, -

The unary (plus) operator yields its


numeric argument unchanged and
the unary - (minus) operator yields
the negation of its numeric argument.
When they add or subtract, they are
binary operators. The operators
return the result of numeric
calculation.

*, /

These are binary operators used for


multiplication or division and return
the result of numeric calculation.

SELECT * FROM students WHERE score = -1;


SELECT * FROM students WHERE
absent_days < 5;

UPDATE students SET score = score * 1.2;

Concatenation Operators
A concatenation operator combines two items such as strings, expressions, or constants into one.
Table 11. Concatenation operators
Operator

Description

Example

||

The concatenation operator


returns the concatenation of its
right and left character strings.

SELECT 'ID is ' || student_id FROM students;


SELECT (8/2) || (3*3) FROM dual;

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"

SELECT * FROM students WHERE id = 25;

!=

"Not equal"

SELECT * FROM students WHEREid!= 25;

24

SAP In-Memory Database: SQL Reference Manual


Operator

Description

Example

>

"Greater than"

SELECT * FROM students WHERE id > 25;

<

"Less than"

SELECT * FROM students WHERE id < 25;

>=

"Greater than or equal to"

SELECT * FROM students WHERE id >= 25;

<=

"Less than or equal to"

SELECT * FROM students WHERE id <= 25;

IN

True if a value exists in a list


of values.

NOT IN

False if a value exists in a list


of values.

SELECT * FROM students WHERE id IN (1,3,5);

SELECT * FROM students WHERE id NOT IN (1,3,5);

All rows evaluate to


UNKNOWN and no rows are
returned if any item in the list
following a NOT IN operation
is null.
[NOT]
BETWEEN x
AND y

True [false] if a value exists


[NOT] between x and y,
inclusively.

SELECT * FROM students WHERE id BETWEEN 20


AND 30;

EXISTS

True if a subquery returns at


least one record.

SELECT grade FROM grade_table g WHERE EXISTS


(SELECT * FROM students s WHERE g.grade =
s.grade );

x [NOT] LIKE
y [ESCAPE 'z']

True if x matches pattern y.

SELECTname FROM students WHERE name LIKE


"A%";
SELECT a_column from a_table where a_column like
'%\%AAA%' escape '\';
For more information about LIKE and ESCAPE, see
below.

IS [NOT]
NULL

True if the value is null. This


operator must be used to test
for null values.

SELECT name FROM students WHERE address IS


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

SAP In-Memory Database: SQL Reference Manual


ESCAPE Clause Example
The "%" or "_" character can be included in the pattern by using the escape character. If the escape
character appears in the pattern before the character "%" or "_", then SAP IMDB interprets this
character literally in the pattern, rather than as a special pattern-matching character.

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

The result of NOT(TRUE) is FALSE.


The result of NOT(FALSE) is TRUE.
The result of NOT(UNKNOWN) IS
UNKNOWN.

AND

Returns TRUE if the following two


conditions are both TRUE.
Returns FALSE if one of the
condition is FALSE.

Example

SELECT * FROM students WHERE NOT (student_id


< 0 );

SELECT * FROM students WHERE student_id =


'0123' AND address = some address;

Otherwise, returns UNKNOWN.


OR

Returns TRUE if one of the following


condition is TRUE.
Returns FALSE if the two conditions
are both FALSE.

SELECT * FROM studentsWHERE student_id


= 0123 OR address = some address;

Otherwise, returns UNKNOWN.

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

Takes output from two queries and combines


them into a distinct result set.

UNION ALL

Takes output from two queries, including all


duplicate rows.

26

SAP In-Memory Database: SQL Reference Manual


Operator

Returned Value

INTERSECT

Takes output from two queries, and returns all


common rows.

MINUS, EXCEPT

Takes output from the first query and then


removes rows selected by the second query.

27

SAP In-Memory Database: SQL Reference Manual

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

Scalar Subquery Expressions


A scalar subquery expression is a subquery that returns a single row consisting of a single value. If the
subquery does not return a row, then the result of this expression is NULL. If the subquery returns
more than one row, an error occurs.
Syntax:
scalar_subquery_expression ::= ( subquery )

28

SAP In-Memory Database: SQL Reference Manual

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

SAP In-Memory Database: SQL Reference Manual

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:

SELECT ABS(-1) "absolute" FROM dual;

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

SAP In-Memory Database: SQL Reference Manual


ATAN Function
Syntax :
ATAN ( n )
Description:
Calculates the arc tangent of the argument n and returns a value between -pi/2 and pi/2 expressed in
radians. The argument is a number and the range of n is unlimited.
Example:
SELECT ATAN(0.5) "atan" FROM dual;
Retrieves:

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

CEIL / CEILING Function


Syntax :
CEIL ( n )
Description:
Calculates the smallest integer value which is greater than or equal to n.

31

SAP In-Memory Database: SQL Reference Manual


Example:
SELECT CEIL(14.5) "ceiling" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Description:
Calculates the base of the natural logarithm (e) raised to the n-th power, where e= 2.718281828459.
Example:
SELECT EXP(1.0) "exp" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


LN Function
Syntax:
LN ( n )
Description:
Computes the natural logarithm of n, where n is greater than 0.
Example:
SELECT LN(EXP(1.0)) "ln" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


POWER Function
Syntax:
POWER(m, n)
Description:
Computes m raised to the n-th power. If m is negative, then n must be an integer.
Example:
SELECT POWER(2, 10) "power" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


SIN Function
Syntax:
SIN ( n )
Description:
Computes the sine of n which is an angle expressed in radians.
Example:
SELECT SIN( 3.141592653589793/2) "sine" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


TANH Function
Syntax:
TANH ( n )
Description:
Computes the hyperbolic tangent of n.
Example:
SELECT TANH(1.0) "tanh" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Example:
SELECT CONCAT('C', 'at') "concat" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


LENGTH Function
Syntax:
LENGTH(c)
Description:
Computes the length of c which is a character string.
Example:
SELECT LENGTH('length in char') "length" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


RIGHT Function
Syntax:
RIGHT(str, n)
Description:
Returns right n characters as a substring from str.
Example:
SELECT RIGHT('HI0123456789', 3) "right" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Example:
SELECT SUBSTR('abcdefgh',3,4) "substring" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Description:
Returns a string after trimming a trim_char from trim_source string.
With the LEADING option, leading substring, trim_char will be removed the from trim_source
string.
With the TRAILING option, trailing substring, trim_char will be removed from the trim_source
string.
With the BOTH option, it removes both the leading and trailing substring, trim_char from
trim_source string.
If trim_char is not specified, then a single blank space will be used.
If either trim_source or trim_char is a null value, then NULL is returned.
Example:
SELECT TRIM (0 FROM 00012345678900) "trim both" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual

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

SAP In-Memory Database: SQL Reference Manual


ADD_SECONDS Function
Syntax:
ADD_SECONDS(t, n)
Description:
Computes the time t plus n seconds.
Example:
SELECT ADD_SECONDS(TO_TIME('23:30:45'), 60*30) "add seconds" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Example:
SELECT MONTH ('2011-05-30) "month" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Description:
Returns the second number of a given time t.
Example:
SELECT SECOND(12:34:56) "second" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


SYSTIMESTAMP Function
Syntax:
SYSTIMESTAMP
Description:
Returns the current system timestamp.
Example:
SELECT SYSTIMESTAMP "system timestamp" FROM dual;
Retrieves:

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:

Coordinated Universal Time


2010-01-11

UTCTIME Function
Syntax:
UTCTIME
Description:
Returns the current UTC time.
Example:
SELECT UTCTIME "Coordinated Universal Time" FROM dual;
Retrieves:

Coordinated Universal Time


08:41:19.267

UTCTIMESTAMP Function
Syntax:
UTCTIMESTAMP
Description:
Returns the current UTC timestamp.
Example:
SELECT UTCTIMESTAMP "Coordinated Universal Timestamp" FROM dual;

50

SAP In-Memory Database: SQL Reference Manual


Retrieves:

Coordinated Universal Timestamp


2010-01-11 08:41:42.484

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

SAP In-Memory Database: SQL Reference Manual

Description:
Converts an expression to another type.

BIGINT | BINARY | BLOB | char | clob | DATE | decimal | double | nchar |


nclob | REAL | TIME | timestamp
Example:
SELECT CAST(7 AS CHAR(10)) "cast" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual

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

SAP In-Memory Database: SQL Reference Manual


TO_NUMBER Function
Syntax:
TO_NUMBER(expr)
Description:
Converts the expr of a data type into a numeric data type.
Example:
SELECT 3.1*TO_NUMBER ('15') "to number" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Retrieves:

ID
1
2
3

A
100.0
NULL
NULL

B
80.0
63.0
NULL

SELECT id, a, b, COALESCE(a, b*1.1, 50.0) "coalesce" FROM tab;


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Description:
Returns expr2 if the value of expr1 is null. If expr1 is not null, then the function returns expr1. If expr1
and expr2 have different data types, then the function converts the data type of expr2 to the data type
of expr1.
Example:
SELECT * FROM tab;
Retrieves:

ID
1
2
3

A
100.0
NULL
NULL

B
80.0
63.0
NULL

SELECT NVL(a, b) "nvl" FROM tab;


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Description:
Returns the current user name in the string.
Example:
SELECT CURRENT_USER "current user" FROM dual;
Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


Retrieves:

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

SAP In-Memory Database: SQL Reference Manual


SYSUUID Function
Syntax:
SYSUUID
Description:
Returns the SYSUUID.
Example:
SELECT SYSUUID FROM dual;
Retrieves:

SYSUUID
4DE3CD576C79511BE10000000A3C2220

62

SAP In-Memory Database: SQL Reference Manual

SQL Statements
This chapter describes the SQL statements that are provided by SAP IMDB.

Classification of SQL Statements


SQL statement can be classified into categories shown in the following table.
Table 15. Classification of SQL statements
SQL Statements

Description

DDL

DDL statements are used to build and modify the database


structure. A table schema, that is, the logical structure of a
database, is specified using DDL commands.

(Data Definition Language)


DML
(Data Manipulation Language)

DCL
(Data Control Language)

In practice, DML statements handle a concrete task that is


data manipulation. It allows data in a given database to be
searched, inserted, deleted, updated, imported into the
database or exported from the database.
DQL statements control access to data in a database. Grant
allows specified users to perform specified tasks, and
revoke cancels previously granted or denied permissions.

General Rules for SQL Statements


This section explains the general rules for creating SQL statements.
Below are the general rules for creating SQL statements:
Statements may be inserted on a single line or multiple lines.
To ensure that the statement can be modified easily, a statement is generally inserted into
another line.
A TAB can be used.
The keywords in an SQL statement cannot be ignored or separated.
SQL statements are not case sensitive.
SQL statements must end with a semicolon (;).

63

SAP In-Memory Database: SQL Reference Manual

DDL (Data Definition Language) Statements


CREATE TABLE
SQL Syntax:
CREATE [ <table_type> ] TABLE table_name <table_contents_source> [ LOGGING ] | [ NOLOGGING
[ RETENTION retention_period ] ] [ WITH PARAMETERS ( <parameter_key_value>, ... ) ]
Parameters:
table_type:
table_type::= COLUMN | ROW | GLOBAL TEMPORARY COLUMN | LOCAL TEMPORARY COLUMN
DEFAULT
Default specifies a value to be assigned to the column if a subsequent INSERT keyword omits
a value for the column.
ROW, COLUMN
If the majority of access is through a large number of tuples but with only a few selected
attributes, COLUMN-based storage makes sense. If the majority of access involves selecting a
few records with all attributes selected, ROW-based storage is preferable. SAP in-memory
database uses a combination to enable storage and interpretation in both forms. You can
define the type of organization for each table. The default value is ROW.
GLOBAL TEMPORARY COLUMN
Table definition is globally available while data is visible only to the current session. The table
is truncated at the end of the session.
LOCAL TEMPORARY
The table definition and data is visible only to the current session. The table is truncated at the
end of the session.
table_contents_source:
table_contents_source ::= ( <table_element> )|[ (column_name, ...) ] <as_table_subquery>
[ WITH [NO] DATA ] ]
table_element ::=column_definition column_constraint | table_constraint
( column_name, ... )
column_definition ::=column_name data type [<column store data type>]
[<ddic data type>] [DEFAULT default_value] [GENERATED ALWAYS AS
<expression> ]
DEFAULT
Default specifies a value to be assigned to the column if a subsequent INSERT
keyword omits a value for the column.
DATA TYPE in column definition
Available column store data types are CS_ALPHANUM, CS_UNITEDECFLOAT,
CS_TEXT, CS_DATE, CS_TIME, CS_FIXEDSTRING.
Available DDIC data types are ABAP_CHAR, ABAP_DATE, ABAP_DECFLOAT16,
ABAP_DECFLOAT34, ABAP_FLOAT, ABAP_HEX, ABAP_INT, ABAP_INT1,
ABAP_INT2, ABAP_NUM, ABAP_PACKED, ABAP_STRING, ABAP_TIME,
ABAP_XSTRING.

64

SAP In-Memory Database: SQL Reference Manual

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

SAP In-Memory Database: SQL Reference Manual


If the index type is omitted, SAP IMDB chooses the appropriate index
considering the column data types.
as_table_subquery ::=AS TABLE as_table_name [THREAD int_const] [BATCH int_const] | AS
( <select_query>)
AS TABLE as_table_name name [THREAD int_const] [BATCH int_const] | AS
( <select_query> )
Creates a table and fills it with the data from as_table_name or computed by the
<select_query>.
Only NOT NULL constraints are copied by this clause.
If column_names are specified, specified column_names override the column names
from as_table_name or select_query.
THREADS int_const
Specifies how many threads should be used in parallel.
Default:
The default value is TABLE_CONVERSION_PARALLELISM that is, the number of CPU
cores specified in the indexserver.ini file.
BATCH int_const
Specifies the number of rows inserted in batch. Insert into column table will be
immediately committed in every batch_size records insertion, which may reduce
memory consumption.
BATCH option can be used only when the table is converted from ROW to COLUMN.
Default:
The default value is INTERMEDIATE_COMMIT_INTERVAL that is, the maximum number
of records (2147483647) on the column table specified in the indexserver.ini file.
Description:
A new table with a different storage type can be created from an existing table by
copying the existing table's columns and data. This command is used to convert the
table storage from ROW to COLUMN or from COLUMN to ROW. If the source table was
in ROW storage, then the created table will be in COLUMN storage.
WITH [NO] DATA
Specifies whether the data is copied from as_table_name or <select_query>.
The default value is WITH DATA.
LOGGING | NOLOGGING [RETENTION retention_period]:
LOGGING | NOLOGGING
LOGGING (default value) specifies that table logging is activated.
NOLOGGING specifies that logging is deactivated. A NOLOGGING table means that the
definition of the table is persistent and globally available, data is temporary and global. The
resource manager should therefore explicitly drop a NOLOGGING table.
RETENTION
Specifies the retention time in seconds of the column table created by NOLOGGING.
parameter_key_value ::= <string_literal> = <string_literal> | <identifier> = <string_literal> |
<string_literal> = (<string_literal>, ...
Options that can be used only for column store tables can be passed in using "WITH PARAMETERS"
clause.

66

SAP In-Memory Database: SQL Reference Manual


Parameter keys and string values can be any string constant. Duplicate keys are allowed. Keys are
automatically mapped into their upper-case representation.

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

SAP In-Memory Database: SQL Reference Manual


DROP TABLE
SQL Syntax:
DROP TABLE table_name [ drop_option ]
Parameters:
drop_option ::= CASCADE | RESTRICT
Default:
Non-cascaded drop
For drop USER, SCHEMA is RESTRICT
For drop TABLE, VIEW, PROCEDURE, SEQUENCE, SYNONYM, QUERY is non-cascaded drop.
Cascaded drop drops the object and dependent objects. When CASCADE option is not specified, noncascaded drop behavior drops the object and does not drop the dependent objects, but invalidates the
dependent objects (VIEW, PROCEDURE).
The invalidated object can be revalidated when an object that has the same schema and object name
is created. The object ID, schema name, and object name pair will be reserved for revalidating
dependent objects.
Restrict drop behavior drops the object when there is no dependent object. If there is a dependent
object, an error is thrown. The default option for drop USER, SCHEMA is RESTRICT.
Description:
The DROP TABLE statement deletes a table.

68

SAP In-Memory Database: SQL Reference Manual


ALTER TABLE
SQL Syntax:
ALTER TABLE table_name { add_column_clause | drop_column_clause | modify_column_clause
| add_primary_key_clause | drop_primary_key_clause | preload_clause | add_statistics_clause |
update_statistics_clause | drop_statistics_clause | table_conversion_clause}
[ WITH PARAMETERS ( parameter_key_value, ... ) ]
Parameters:
add_column_clause::= ADD ( column_definition, ... )
drop_column_clause ::=DROP ( column_name, ... )
modify_column_clause ::=MODIFY ( column_definition, ... )
add_primary_key_clause ::= ADD [CONSTRAINT constraint_name] PRIMARY KEY ( column_name, ... )
CONSTRAINT
Specifies the name of a constraint.
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.
drop_primary_key_clause ::= DROP PRIMARY KEY
preload_clause ::= PRELOAD ALL | PRELOAD ( column_name ) | PRELOAD NONE
PRELOAD sets/removes the preload flag of the given tables or columns. As a consequence,
these tables are automatically loaded into memory after an index server start. The current
status of the preload flag is visible in the system table TABLES, column PRELOAD, possible
values ('FULL', 'PARTIALLY', 'NO' ) and in system table COLUMN_TABLES, column PRELOAD,
possible values ('TRUE', 'FALSE').
add_statistics_clause ::= ADD STATISTICS [ ( column_list ) ]
ADD STATISTICS
Creates statistics for the columns of a table. If a column list is not specified, the statistics for
all columns of the table are created.
System view statistics has the statistics of columns of a table.
Statistics are min, max, count, distinct count ,null count values.
update_statistics_clause ::= UPDATE STATISTICS [ ( column_list ) ]
UPDATE STATISTICS
Updates statistics for columns of table. If a column list is not specified, the statistics for all
columns of the table are updated. DROP STATISTICS drops statistics for columns for a table. If
a column list is not specified, all existing statistics of the table are dropped.
System view statistics has the statistics of columns of a table.
Statistics are min, max, count, distinct count ,null count values.
drop_statistics_clause ::= DROP STATISTICS [ ( column_list ) ]
DROP STATISTICS
System view statistics has the statistics of columns of a table.
Statistics are min, max, count, distinct count ,null count values.

69

SAP In-Memory Database: SQL Reference Manual


table_conversion_clause ::= [ MODIFY TYPE ] [ ROW | COLUMN ] [ THREADS int_constr ] [ BATCH
batch_size ]
MODIFY TYPE ROW | COLUMN
This command is used to convert the table storage from ROW to COLUMN or from COLUMN to
ROW.
THREADS
Specifies how many threads should be used in parallel.
Default value: the number of CPU cores. It can be specified by using
TABLE_CONVERSION_PARALLELISM in the indexserver.ini file.
BATCH
Specifies the number of rows inserted in batch. Insert into column table will be immediately
committed in every batch_size records insertion, which may reduce memory consumption.
BATCH option can be used only when the table is converted from ROW to COLUMN.
Default value: the maximum number of records (2147483647) in the column table that can be
specified using INTERMEDIATE_COMMIT_INTERVAL in the index server.ini file.
WITH PARAMETERS (parameter_key_value):
Column store-specific options can be passed in using the "WITH PARAMETERS" clause.

Keys and single values can be any string constant

Duplicate keys are allowed

Keys are automatically mapped into their uppercase representation


parameter_key_value ::=
<string_literal> = <string_literal> |
<identifier> = <string_literal> |
<string_literal> = (<string_literal>, ...
Current parameters
CONCAT_ATTRIBUTE = (new_att, exist_att_list)
new_att:= 'str_const'
exist_att_list = 'str_const' | exist-att-list ',' 'str_const'
DELETE_CONCAT_ATTRIBUTE := exist_att
exist_att := 'str_const'
TREX_FLAGS = ('column_name','flags'),
Flags are the implementation flags; the integer value is currently between 0 and 67108864.
INDEX_PROPERTY = ('prop#', 'value')
Changing column table properties
ALTER <table> WITH PARAMETERS (INDEX_PROPERTY = ('prop#', 'value') )
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. The ALTER TABLE either splits
or merges the table. Use 'MERGE' as partition spec to merge the parts. The tables have to be
merged before they can be split using a different partition specification.
DSO_ACTIVATE_REQUESTS = (rid_list)
dso-activation of the given request IDs in the corresponding DSO index.

70

SAP In-Memory Database: SQL Reference Manual


rid_list has to be a comma-separated list of strings. Activation in the DSO sense means
changing the active data of the DSO index by applying the changes of the given requests
residing in the Activation Queue. This parameter will only work for DSO indexes.
DSO_ROLLBACK_REQUESTS = (rid_list)
dso-rollback of the given RequestIds in the corresponding DSO index.
rid_list has to be a comma-separated list of strings. Rollback in the DSO sense means
removing the changes in the active data of the DSO that were caused by the given requests.
This parameter will only work for DSO indexes.
Description:
The ALTER TABLE statement adds, deletes or modifies a column from a table and creates or drops a
primary key. It can also delete or add multiple columns at a time. The new column will initially be
filled with a default value. If a default is not specified, then the value is null.

71

SAP In-Memory Database: SQL Reference Manual


RENAME TABLE
SQL Syntax:
RENAME TABLE old_table_name TO new_table_name
Description:
The RENAME TABLE statement changes the name of a table.

72

SAP In-Memory Database: SQL Reference Manual


RENAME COLUMN
SQL Syntax:
RENAME COLUMN table_name.old_column_name TO new_column_name
Description:
The RENAME COLUMN statement changes the name of a column.

73

SAP In-Memory Database: SQL Reference Manual


CREATE INDEX
SQL Syntax:
CREATE [BTREE | CPBTREE] INDEX index_name ON table_name ( column_name, ... ) [ ASC | DESC ]
Parameters:
BTREE | CPBTREE
Used to decide which kind of index to use.
When column data types are character string types, binary string types, decimal types, or when the
constraint is a composite key, or a non-unique constraint, the default index type is CPBTREE;
otherwise, BTREE is used.
If neither BTREE nor CPBTREE keyword is specified, then SAP IMDB chooses the appropriate index
type.
ASC | DESC
Specifies whether the index should be created in ascending or descending order.
These keywords can be only used in the btree index.
Description:
The CREATE INDEX statement creates an index.

74

SAP In-Memory Database: SQL Reference Manual


DROP INDEX
SQL Syntax:
DROP INDEX index_name
Description:
The DROP INDEX statement removes an index.

75

SAP In-Memory Database: SQL Reference Manual


RENAME INDEX
SQL Syntax:
RENAME INDEX old_index_name TO new_index_name
Description:
The RENAME INDEX statement changes the name of an index.

76

SAP In-Memory Database: SQL Reference Manual


CREATE VIEW
SQL Syntax:
CREATE VIEW view_name [ ( alias, ... ) ] AS select_statement
Description:
The CREATE VIEW statement is used to create a view.
Views are logical tables that are created as needed and use data from one or more physical tables or
views. A view contains no data itself.
The tables upon which a view is based are called base tables.
A query specifies what information from base tables or views has to be retrieved when a view is
created.
When a column name is specified along with the view name, a query result is displayed with a column
name. If a column name is omitted, a query result gives an appropriate name to the column
automatically.
A created view can only exist within the FROM clause in a SELECT statement. A view cannot be
updated.

77

SAP In-Memory Database: SQL Reference Manual


CREATE COLUMN VIEW
SQL Syntax:
CREATE COLUMN VIEW view_name [ ( alias, ... ) ] [ TYPE types ] AS select_statement [ WITH
PARAMETERS (<parameter_key_value>, ... ) ]
Parameters:
TYPE types := OLAP | JOIN | HIERARCHY | PROPERTY | LANGUAGE | CALCULATION | FBO
WITH PARAMETERS ( <parameter_key_value>, ... )
parameter_key_value:= parameter | parameter-list ',' parameter
parameter := | description | codepage | index_type | join_index | join_condition | join_path |
constraint | index_alias | join_index_type | join_index_estimation |view_attribute | view |
default_view | semantic_relation | rfc_destination | auto_replication| key_figure |
unit_conversion | optimize_metamodel | free_style_search_attribute
|all_attrs_free_style_relevant | template_index | new_fact_table | flags | p_object_key
|p_property_name | p_value_name | free_style_translation | characteristic |
multi_provider_config | is_memory_index |use_initial_reorg | is_transactional | auto_delete
description := DESCRIPTION '=' str_const
codepage := CODEPAGE '=' str_const
index_type := INDEXTYPE '=' int_const
int_const defined as TREX_LOGICAL_INDEX_TYPE in ims_search_api/TRexApiGlobals.h
note that if CREATE VIEW ... WITH PARAMETER variant is chosen, parameter INDEXTYPE
overrides symbol TYPE
join_index := JOININDEX '=' table_name
join_condition :=
JOINCONDITION '=' '(' str_const ',' table_name ',' column_name ',' table_name
','column_name ')' |
JOINCONDITION '=' '(' str_const ',' table_name ',' column_name ',' table_name','
column_name ',' str_const ',' int_const ',' int_const ')' |
JOINCONDITION '=' '(' str_const ','table_name ',' column_name ',' table_name ','
column_name ',' str_const ',' int_const ',' int_const'',' str_const ')' |
JOINCONDITION '=' '(' str_const ',' table_name ',' column_name ',' table_name
','column_name ',' str_const ',' int_const ',' int_const' ',' str_const ',' str_const ')'
join_path := JOINPATH '=' '(' str_const ',' str_const ')' | JOINPATH '=' '(' str_const ',' str_const
','str_const ')'
constraint := CONSTRAINT '=' '(' str_const ',' int_const ',' str_const ',' table_name ','
column_name',' str_const ',' str_const [ ',' int_const ',' str_const ] ')'
index_alias := INDEXALIAS '=' '(' table_name '=' str_const ')'
join_index_type := JOININDEXTYPE '=' int_const
join_index_estimation := JOININDEXESTIMATION '=' int_const
view_attribute :=

78

SAP In-Memory Database: SQL Reference Manual


VIEWATTRIBUTE '=' '(' str_const ',' table_name ',' column_name ',' str_const ',' str_const ','
str_const ')' |
VIEWATTRIBUTE '=' '(' str_const ',' table_name ',' column_name ',' str_const ',' str_const
','str_const ',' str_const ')' |
VIEWATTRIBUTE '=' '(' str_const ',' table_name ',' column_name ',' str_const ',' str_const
','str_const ',' str_const ',' str_const ')' |
VIEWATTRIBUTE '=' '(' str_const ',' str_const ')'
view := VIEW '=' '(' str_const ',' table_name [ ',' str_const ]')'
default_view := DEFAULTVIEW '=' str_const
semantic_relation := SEMANTICRELATION '=' '(' str_const ',' str_const ',' str_const ','
str_const ')'
key_figure :=
KEYFIGURE '=' '(' column_name ',' int_const ')' |
KEYFIGURE '=' '(' column_name ',' int_const ',' str_const ')' |
KEYFIGURE '=' '(' column_name ',' str_const ',' int_const ')' |
KEYFIGURE '=' '(' column_name ',' str_const ',' int_const ',' str_const ')' |
KEYFIGURE '=' '(' column_name ',' str_const ',' int_const ',' str_const ',' RESTRICTION '='
str_const')' |
KEYFIGURE '=' '(' column_name ',' str_const ',' int_const ',' str_const ',' str_const ','
RESTRICTION'=' str_const ')' |
KEYFIGURE '=' '(' column_name ',' int_const ',' FORMULA '=' str_const ',' DESCRIPTION '='
str_const ',' UNITCONVERSIONNAME '=' str_const ',' EXPRESSION '=' str_const ','
EXPRESSIONFLAGS '=' int_const ')' |
KEYFIGURE '=' '(' column_name ',' int_const ',' FORMULA '=' str_const ',' DESCRIPTION '='
str_const ',' UNITCONVERSIONNAME '=' str_const ',' EXPRESSION '=' str_const ','
EXPRESSIONFLAGS '=' int_const ',' RESTRICTION '=' str_const ')' |
KEYFIGURE '=' '(' column_name ',' int_const ',' FORMULA '=' str_const ',' DESCRIPTION '='
str_const ',' UNITCONVERSIONNAME '=' str_const ',' EXPRESSION '=' str_const ','
EXPRESSIONFLAGS '=' int_const ',' INDEXID '=' table_ref_trex ',' ATTRIBUTE '='
column_name ')' |
KEYFIGURE '=' '(' column_name ',' int_const ',' FORMULA '=' str_const ',' DESCRIPTION '='
str_const ',' UNITCONVERSIONNAME '=' str_const ',' EXPRESSION '=' str_const ','
EXPRESSIONFLAGS '=' int_const ',' INDEXID '=' table_ref_trex ',' ATTRIBUTE '='
column_name ',' RESTRICTION '=' str_const ',' ALIAS '=' int_const ')'
unit_conversion := UNITCONVERSION '=' '(' str_const ',' table_name ',' column_name ','
str_const ',' column_name ',' str_const ',' name ')'
optimize_metamodel := OPTIMIZEMETAMODEL '=' int_const
free_style_search_attribute := FREESTYLESEARCHATTRIBUTE '=' str_const
all_attrs_free_style_relevant := ALLATTRSFREESTYLERELEVANT '=' int_const
template_index := TEMPLATEINDEX '=' table_name
new_fact_table := NEWFACTTABLE '=' table_name
flags := FLAGS '=' int_const
p_object_key := POBJECTKEY '=' '(' comma-separated-str_consts ')'
p_property_name := PPROPERTYNAME '=' column_name
p_value_name := PVALUENAME '=' column_name

79

SAP In-Memory Database: SQL Reference Manual

free_style_translation := FREESTYLETRANSLATION '=' '(' column_name ',' table_name


','column_name ',' column_name ')'
characteristic := CHARACTERISTIC '=' '(' str_const characteristic_param_list ')'
characteristic_param_list := ',' SIDATTRIBUTE '=' column_name | ',' KEYATTRIBUTE
'=' column_name | ',' TEXTATTRIBUTE '=' column_name | ',' EXTERNALATTRIBUTE '='
column_name | ',' HIERARCHYNAME '=' str_const | HIERARCHYINDEX '=' str_const |
',' str_const *
multi_provider_config := MULTIPROVIDERCONFIG '=' str_const
is_memory_index := ISMEMORYINDEX '=' int_const
use_initial_reorg := USEINITIALREORG '=' int_const
auto_delete := AUTODELETE '=' int_const
register_view_for_ap_check := 'REGISTERVIEWFORAPCHECK' '=' int_const
Register_view_for_ap_check is required to define that a column view (join, olap, or calculation)
is registered for the AnalyticalPrivileges check.

80

SAP In-Memory Database: SQL Reference Manual


DROP VIEW
SQL Syntax:
DROP VIEW view_name [ drop_option ]
Parameter:
drop_option ::= CASCADE | RESTRICT
Default:
Non-cascaded drop
For drop USER, SCHEMA is RESTRICT
For drop TABLE, VIEW, PROCEDURE, SEQUENCE, SYNONYM, QUERY is non-cascaded drop.
Cascaded drop drops the object and dependent objects. When CASCADE option is not specified, noncascaded drop behavior drops the object and does not drop the dependent objects, but invalidates the
dependent objects (VIEW, PROCEDURE).
The invalidated object can be revalidated when an object that has same schema and object name is
created. Object ID, schema name, and object name pair will be reserved for revalidating dependent
objects.
Restrict drop behavior will drop the object when there is no dependent object. If there is a dependent
object, an error will be thrown. The default option for drop USER, SCHEMA is RESTRICT.
Description:
The DROP VIEW statement removes a view.

81

SAP In-Memory Database: SQL Reference Manual


CREATE SEQUENCE
SQL Syntax:
CREATE SEQUENCE sequence_name [sequence_parameter_list] [RESET BY select_statement]
Parameters:
sequence_parameter_list ::= sequence_parameter, ...
sequence_parameter ::= INCREMENT BY integer | START WITH integer | MAXVALUE integer |
NOMAXVALUE |MINVALUE integer | NOMINVALUE | CYCLE | NOCYCLE
INCREMENT BY
Specifies the interval between sequence numbers. This integer value can be any 64-bit positive or
negative integer except 0, and the absolute value must be less than the difference of MAXVALUE
and MINVALUE. If the interval is not specified, then it defaults to 1.
START WITH
Specifies the first sequence number value. For ascending sequences, a value has to be greater
than MINVALUE and the default value is the minimum value of the sequence. For descending
sequences, a value has to be less than MAXVALUE, the default value is the maximum value of the
sequence.
MAXVALUE
Specifies the maximum value and can range from 0 to 4611686018427387903.
MAXVALUE must be greater than or equal to START WITH and must be greater than MINVALUE
NOMAXVALUE
Does not specify the MAXVALUE. For ascending sequences, a value is 4611686018427387903 and
for descending sequences, a value is -1.
MINVALUE
Specifies the minimum value and can range from 0 to 4611686018427387903.
MINVALUE must be less than or equal to START WITH and must be less than MAXVALUE.
NOMINVALUE
Does not specify the MINVALUE. For ascending sequences a value is 1, and for descending
sequences a value is -4611686018427387903.
CYCLE
Specifies that the sequence continues to generate values after reaching either its maximum or
minimum value. After an ascending sequence reaches its maximum value, it generates its
minimum value. After a descending sequence reaches its minimum value, it generates its
maximum value.
NOCYCLE
Specifies that the sequence cannot generate more values after reaching either its maximum or
minimum value. This is the default value.
RESET BY
Specifies that when restarting, it does the same task as START WITH in sequence. The result of
the query must have one row, one column, and a numeric type.

82

SAP In-Memory Database: SQL Reference Manual


Description:
The CREATE SEQUENCE statement is used to create a sequence.
A sequence is a database object from which multiple users may generate unique integers. It is
commonly used to generate primary key values.
If a sequence is created, then its values can be accessed in SQL statements with the CURRVAL
pseudocolumn, which returns the current value of the sequence, or the NEXTVAL pseudocolumn,
which increments the sequence and returns the new value. When you use these two pseudocolumns,
the name of the sequence has to be specified in front of the pseudocolumn.
Example 1:

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

SAP In-Memory Database: SQL Reference Manual


DROP SEQUENCE
SQL Syntax:
DROP SEQUENCE sequence_name [ drop_option ]
Parameters:
drop_option ::= CASCADE | RESTRICT
Default:
Non-cascaded drop
For drop USER, SCHEMA is RESTRICT
For drop TABLE, VIEW, PROCEDURE, SEQUENCE, SYNONYM, QUERY is non-cascaded drop.
Cascaded drop drops the object and dependent objects. When CASCADE option is not specified, noncascaded drop behavior drops the object and does not drop the dependent objects, but invalidates the
dependent objects (VIEW, PROCEDURE).
The invalidated object can be revalidated when an object that has same schema and object name is
created. Object ID, schema name, and object name pair will be reserved for revalidating dependent
objects.
Restrict drop behavior will drop the object when there is no dependent object. If there is a dependent
object, an error will be thrown. The default option for drop USER, SCHEMA is RESTRICT.
Description:
The DROP SEQUENCE statement removes a sequence.

84

SAP In-Memory Database: SQL Reference Manual


CREATE SYNONYM
SQL Syntax:
CREATE PUBLIC SYNONYM synonym_name FOR name
Description:
The CREATE SYNONYM statement is used to generate a synonym.
Specify PUBLIC to create a public synonym. A synonym is an alternative name for a table, view, or
sequence. When a synonym is generated, it allows the user to approach the tables and views.

85

SAP In-Memory Database: SQL Reference Manual


DROP SYNONYM
SQL Syntax:
DROP SYNONYM synonym_name [ drop_option ]
Parameters:
drop_option ::= CASCADE | RESTRICT
Default:
Non-cascaded drop
For drop USER, SCHEMA is RESTRICT
For drop TABLE, VIEW, PROCEDURE, SEQUENCE, SYNONYM, QUERY is non-cascaded drop.
Cascaded drop drops the object and dependent objects. When CASCADE option is not specified, noncascaded drop behavior drops the object and does not drop the dependent objects, but invalidates the
dependent objects (VIEW, PROCEDURE).
The invalidated object can be revalidated when an object that has same schema and object name is
created. Object ID, schema name, and object name pair will be reserved for revalidating dependent
objects.
Restrict drop behavior will drop the object when there is no dependent object. If there is a dependent
object, an error will be thrown. The default option for drop USER, SCHEMA is RESTRICT.
Description:
The DROP SYNONYM statement removes a synonym.

86

SAP In-Memory Database: SQL Reference Manual


CREATE SCHEMA
SQL Syntax:
CREATE SCHEMA schema_name [OWNED BY ] name
Parameters:
OWNED BY
Specifies the name of the schema owner.
Description:
The CREATE SCHEMA statement creates a schema (namespace for the user) in the current database.

87

SAP In-Memory Database: SQL Reference Manual


DROP SCHEMA
SQL Syntax:
DROP SCHEMA schema_name [ drop_option ]
Parameters:
drop_option ::= CASCADE | RESTRICT
Default:
Non-cascaded drop
For drop USER, SCHEMA is RESTRICT
For drop TABLE, VIEW, PROCEDURE, SEQUENCE, SYNONYM, QUERY is non-cascaded drop.
Cascaded drop drops the object and dependent objects. When CASCADE option is not specified, noncascaded drop behavior drops the object and does not drop the dependent objects, but invalidates the
dependent objects (VIEW, PROCEDURE).
The invalidated object can be revalidated when an object that has same schema and object name is
created. Object ID, schema name, and object name pair will be reserved for revalidating dependent
objects.
Restrict drop behavior will drop the object when there is no dependent object. If there is a dependent
object, an error will be thrown. The default option for drop USER, SCHEMA is RESTRICT.
Description:
The DROP SCHEMA statement removes a schema.

88

SAP In-Memory Database: SQL Reference Manual


CREATE TYPE
SQL Syntax:
CREATE TYPE type_name AS TABLE ( <table_element> ... )
Description:
The CREATE TYPE statement creates a user-defined table type.
A user can create tables that have the same specifications as a user-defined table type.

89

SAP In-Memory Database: SQL Reference Manual


DROP TYPE
SQL Syntax:
DROP TYPE type_name [ drop_option ]
Parameters:
drop_option ::= CASCADE | RESTRICT
Default:
Non-cascaded drop
For drop USER, SCHEMA is RESTRICT
For drop TABLE, VIEW, PROCEDURE, SEQUENCE, SYNONYM, QUERY is non-cascaded drop.
Cascaded drop drops the object and dependent objects. When CASCADE option is not specified, noncascaded drop behavior drops the object and does not drop the dependent objects, but invalidates the
dependent objects (VIEW, PROCEDURE). When a table type is dropped with non-cascaded drop option,
the dependent SQLScript procedure will be invalidated but will not be dropped. When the underlying
object of SQLScript procedure is recreated, the validity of the procedure is checked again and
revalidated.
The invalidated object can be revalidated when an object that has same schema and object name is
created. Object ID, schema name, and object name pair will be reserved for revalidating dependent
objects.
Restrict drop behavior will drop the object when there is no dependent object. If there is a dependent
object, an error will be thrown. The default option for drop USER, SCHEMA is RESTRICT.
Description:
The DROP TYPE statement removes a user-defined table type.

90

SAP In-Memory Database: SQL Reference Manual


CREATE CALCULATION SCENARIO
SQL Syntax:
CREATE CALCULATION SCENARIO name USING xml [ WITH PARAMETERS
( <parameter_key_value>, ... ) ]
Parameters:
xml ::= str_const
parameter_key_value ::=
'DEFAULT_SCHEMA' = <schema> |
'INMEMORY_SCENARIO' = '0' |
'INMEMORY_SCENARIO' = '1' |
'EXPOSE_NODE' = ( <node_name>, <view_name> ) |
'EXPOSE_NODE' = ( <node_name>, <schema>, <view_name> )
schema ::= str_const
node_name ::= str_const
view_name ::= str_const
Description:
The CREATE CALCULATION SCENARIO statement creates a calculation scenario.
Please note that a calculation scenario is not a default catalog object, so it cannot be accessed via a
SELECT statement after its creation. A column view of type calculation is required on top of the
scenario to query it.
As it is not a catalog object, it is also not linked to a catalog schema. The first part of the name can be
rather seen as a package in which the scenario is created. This implies that a drop of a (database)
schema does not drop the calculation scenarios.
The scenario is defined with the used XML-string which has to be formatted as described in the XSD.
The default schema defines on the one hand the package in which the scenario is created (if not
defined explicitly), and the schema for the views on top listed in the expose nodes on the other.
It can be either in-memory only (set optional parameter value 'INMEMORY_SCENARIO' = '1') or
persistent.
The default scenario is persistent and stored in the repository. With an expose node item it is possible
to directly create a column view of type calculation on top of a specified node on top of the scenario.
The view name is defined in 'view_name'. The referenced node has to be specified in 'node_name'.
Note that sub-transactions have started (and committed) in order to create the views.
Note: For application development, do not use these expose node items. Instead, create the column
views of type calculation manually.
Example
DROP TABLE TEST1;
CREATE INSERT ONLY COLUMN TABLE TEST1(A INTEGER, B DOUBLE);
insert into test1 values ( 1, 2);
insert into test1 values ( 11, 22);
insert into test1 values ( 111, 222);
DROP CALCULATION SCENARIO SYSTEM.DEMO_PROJECTION_OP cascade;
CREATE CALCULATION SCENARIO SYSTEM.DEMO_PROJECTION_OP USING '

91

SAP In-Memory Database: SQL Reference Manual


<?xml version="1.0" encoding="utf-8"?>
<cubeSchema version="2" operation="createCalculationScenario">
<calculationScenario schema="SYSTEM" name="DEMO_PROJECTION_OP">
<dataSources>
<tableDataSource name="demo_projection_datasource" schema="SYSTEM"
table="TEST1">
<attributes>
<allAttribute/>
</attributes>
</tableDataSource>
</dataSources>
<calculationViews>
<projection name="demo_projection" defaultViewFlag="true">
<inputs>
<input name="demo_projection_datasource" />
</inputs>
<attributes>
<allAttribute />
<calculatedAttribute name="C" datatype="double" isViewAttribute="true">
<formula>"A" * "B"</formula>
</calculatedAttribute>
</attributes>
<filter>"C" &gt; 1</filter>
</projection>
</calculationViews>
</calculationScenario>
</cubeSchema>'
;
DROP VIEW SYSTEM.MYCALCVIEW;
CREATE COLUMN VIEW SYSTEM.MYCALCVIEW TYPE CALCULATION
WITH PARAMETERS
('PARENTCALCINDEXPACKAGE'='SYSTEM',
'PARENTCALCINDEX'='DEMO_PROJECTION_OP',
'PARENTCALCNODE'='demo_projection');
SELECT * FROM SYSTEM.MYCALCVIEW;
DROP CALCULATION SCENARIO SYSTEM.DEMO_PROJECTION_OP CASCADE;
Result
C
2.0

A
1

B
2.0

242.0

11

22.0

24642.0

111

222.0

92

SAP In-Memory Database: SQL Reference Manual


DROP CALCULATION SCENARIO
SQL Syntax:
DROP CALCULATION SCENARIO name [ drop_option ]
Parameters:
drop_option ::= CASCADE
Default:
Non-cascaded drop
For drop USER, SCHEMA is RESTRICT
For drop TABLE, VIEW, PROCEDURE, SEQUENCE, SYNONYM, QUERY is non-cascaded drop.
Cascaded drop drops the calculation scenario and dependent column views (of type calculation).
Non-cascaded drop behavior prevents dropping the scenario if there are any column views (of type
calculation) referencing the scenario.
Description:
The DROP CALCULATION SCENARIO statement deletes a calculation scenario.

93

SAP In-Memory Database: SQL Reference Manual


CREATE USER
SQL Syntax:
CREATE USER user_name IDENTIFIED BY password
CREATE USER user_name IDENTIFIED EXTERNALLY AS [external_identity]
CREATE USER user_name IDENTIFIED GLOBALLY
Parameters:
IDENTIFIED EXTERNALLY
The external authentication is the external identity of the user specified in the active directory.
For information about external identities, contact your domain administrator.
Description:
The CREATE USER statement creates a new user.
The specified user name must not be identical to the name of an existing user, role, or schema.

94

SAP In-Memory Database: SQL Reference Manual


DROP USER
SQL Syntax:
DROP USER user_name [ drop_option ]
Parameters:
drop_option ::= CASCADE | RESTRICT
Default:
Non-cascaded drop
For drop USER, SCHEMA is RESTRICT
For drop TABLE, VIEW, PROCEDURE, SEQUENCE, SYNONYM, QUERY is non-cascaded drop.
CASCADE| RESTRICT
If CASCADE or RESTRICT are not specified, or if CASCADE is specified, all schemas, synonyms
and tables of the user to be dropped, including indexes, privileges, view tables and so on
based on these objects, are deleted along with the user.
If RESTRICT is specified, and the user to be dropped is the owner of synonyms or tables, then
the DROP USER statement will fail.
Description:
The DROP USER statement deletes a database user. The schema with the user's name and the
schemas belonging to the user, together with all objects in them (even if they are created by different
users), are deleted. Objects owned by the user even if they are part of another schema are deleted.
Objects that are dependent on deleted objects are deleted. Privileges on these deleted objects are
deleted. It is possible to delete a user even if a session exists to which the user is connected.

95

SAP In-Memory Database: SQL Reference Manual


ALTER USER
SQL Syntax:
ALTER USER user_name IDENTIFIED BY password
ALTER USER user_name IDENTIFIED EXTERNALLY AS external_identity
ALTER USER user_name IDENTIFIED GLOBALLY
Parameters:
IDENTIFIED EXTERNALLY
You can change the external authentication. For information about external identities, contact your
system administrator.
Description:
The ALTER USER statement modifies the database user.

96

SAP In-Memory Database: SQL Reference Manual


CREATE ROLE
SQL Syntax:
CREATE ROLE role_name [IDENTIFIED GLOBALLY AS identity]
Parameters:
IDENTIFIED GLOBALLY AS identity
Description:
A role is a named collection of privileges. If you want to allow several database users to perform the
same actions, you can create a role, grant the needed privileges to this role, and grant the role to the
different database users. The default role is PUBLIC, every database user has been granted this role
implicitly. Users who have system privilege ROLE ADMIN can CREATE, ALTER, or DROP roles. You can
modify the identity (the external role name for the global user) of the role.
IDENTIFIED GLOBALLY AS identity
You can define that the role should be available globally by specifying an identity, the external role
name for the global user.

97

SAP In-Memory Database: SQL Reference Manual


ALTER ROLE
SQL Syntax:
ALTER ROLE role_name IDENTIFIED GLOBALLY AS identity
Parameters:
IDENTIFIED GLOBALLY AS identity
Description:
A role is named collection of privileges. If you want to allow several database users to perform the
same actions, you can create a role, grant the needed privileges to this role, and grant the role to the
different database users. The default role is PUBLIC, every database user has been granted this role
implicitly. Users who have system privilege ROLE ADMIN can CREATE, ALTER, or DROP roles. You can
modify the identity (the external role name for the global user) of the role.
IDENTIFIED GLOBALLY AS identity
You can define that the role should be available globally by specifying the identity, the external role
name for the global user.

98

SAP In-Memory Database: SQL Reference Manual


DROP ROLE
SQL Syntax:
DROP ROLE role_name
Description:
Users with system privilege ROLE ADMIN can CREATE, ALTER, or DROP roles.
If a role was granted to a grantee (either a user or a role) and it has not been revoked, it is revoked
when the role is dropped. Revoking the role may lead to making some views inaccessible if a view
depends on any privilege that the role has.

99

SAP In-Memory Database: SQL Reference Manual


ALTER SYSTEM
SQL Syntax:
ALTER SYSTEM alter_system_options
Parameters:
Parameters for ALTER SYSTEM:
alter_system_options ::=
ADD SCENARIO <xml_string> WITH PARAMETERS ('flags' = '<flags>', 'default schema' =
'schema name')
| ADD STRUCTURED PRIVILEGE <structured_privilege_name>
| CHECKPOINT
| CLEAR TRACES (<trace_file_name>, ...)
| COLLECT VERSION GARBAGE
| DELETE TRACES (<trace_file_name>)
| DISABLE LOG FLUSH
| DISCONNECT SESSION <session_id>
| DROP STRUCTURED PRIVILEGE <structured_privilege_name>
| ENABLE LOG FLUSH
| INIFILE(<ini_set_parameter>, ...) REMOVE (<set_parameter_value>) [WITH RECONFIGURE]
| INIFILE(<ini_set_parameter>, ...) SET (<set_parameter_value>) [WITH RECONFIGURE]
| KILL SERVICE (<service_name>, <host_name>, <port_no>) [WITH COREFILE]
| KILL SESSION <session_id>
| QUERY CACHE FLUSH
| RECONFIGURE SERVICE (<service_name>, <host_name>, <port_no>)
| REMOVE STRUCTURED PRIVILEGE <structured_privilege_name>
| SET MONITOR LEVEL <monitor_level>
| STOP SERVICE (<service_name>, <host_name>, <port_no>)
Parameters for ADD SCENARIO:
xml_string ::= str_const
flags :: = bitmast defining creation flags
default_schema ::= str_const
Description:
ADD SCENARIO
The ALTER SYSTEM ADD SCENARIO command creates a column view of type OLAP and is
dependent on the XML additional tables. The call parses the XML and translates it into one or
multiple SQL statements which are then executed in order to create the appropriate objects.
The default schema defines on the one hand the schema in which the view/tables are created
if not defined explicitly, and the schema for the tables used in the XML if not defined explicitly
on the other. With flags = 2, a validation of the XML can be triggered without creating the
tables/view.
ADD|DROP|REMOVE STRUCTURED PRIVILEGE
An analytical privilege (based on a generic structured privilege) is uniquely identified by its
name and contains a collection of relevant restrictions to restrict user access from different
perspectives, such as accessible cubes and an accessible value range of dimension attributes.

100

SAP In-Memory Database: SQL Reference Manual


You can grant or revoke these restrictions to the system using the ALTER SYSTEM
ADD/DROP/REMOVE STRUCTURED PRIVILEGE statements. As the owner (creator) of an
analytical privilege, you can also grant or revoke the analytical privilege to or from another
user to restrict user access to analytic data (cubes) using the GRANT statement or REVOKE
statement.
CHECKPOINT
Performs a checkpoint. A checkpoint is a point in time when a complete consistent image of
the database is persisted on the disk. The consistent image can be used to restart the
database.
CLEAR|DELETE TRACES
CLEAR TRACES clears trace contents from trace files. DELETE TRACES deletes the trace files.
COLLECT VERSION GARBAGE
Performs an MVCC version garbage collection.
DISABLE|ENABLE LOG FLUSH
Enables or sets a log flush.
INIFILE REMOVE|SET
Removes or sets configuration parameters in the ini file. Ini file configuration is used for the
layered configuration for DEFAULT, SYSTEM, HOST, TENANT layers. The following is an
example of ini file locations.
/usr/sap/<SYSTEMNAME>/HDB<INSTANCENUMBER>/exe/config/indexserver.ini -> DEFAULT
/usr/sap/<SYSTEMNAME>/SYS/global/hdb/custom/config/indexserver.ini-> SYSTEM
/usr/sap/<SYSTEMNAME>/ HDB<INSTANCENUMBER>/<HOSTNAME>/indexserver.ini ->
HOST
The priority of configuration is defined as DEFAULT < SYSTEM < HOST < TENANT, meaning
the priority of TENANT layer has the highest priority. Configuration with the available highest
priority will be applied to the running environment. If the highest priority level configuration is
removed, then the configuration with the next highest priority will be applied. DEFAULT layer
configuration cannot be changed or removed. You can configure remote host configurations if
you use HOST layer. Currently available configuration is available in M_INIFILE_CONTENTS.
Example syntax to change system layer configuration is as follows:
alter system inifile ( 'filename', 'layer' ) set ('section1', 'key1') = 'value1', ('section2', 'key2') =
'value2', ... [with reconfigure];
alter system inifile ( 'filename', 'layer', 'layer_name' ) remove ('section1', 'key1'),
('section2'), ...[with reconfigure];
'layer' can be 'SYSTEM', 'HOST' or 'TENANT'. In case of HOST or TENANT layer, 'layer_name' is
either its target tenant name or target host name; for example, '000' for tenant 000 and
'selxeon12' for host.
'filename' is 'indexserver.ini' in case of row-store engine configuration. 'filename' must be one
of the ini files located on the 'default' layer. The set command will update the value of a key if
the key already exists, but insert it otherwise. If 'filename' does not exist on the 'layer', the
'filename' file will be created first.
Row-Store Engine Configurations

101

SAP In-Memory Database: SQL Reference Manual


Row-store Engine Configuration items reside in indexserver.ini under the 'row_engine',
'transaction', 'sql', 'session', 'sqltrace' section. Parameters that are reconfigurable online can
be reconfigured using the with reconfigure command. Without with reconfigure, the new
configuration is written to the ini file, but the new value is not applied to runtime on the fly
and will be applied at the next startup of the server. This means that there could be
inconsistencies between the ini file contents and the actual configuration value in memory.
The list of configuration parameters for row-store is the following:
Section
Name

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

all, ddl, dml

yes

user

all

all, username

yes

object

all

all, object name

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

num cores by default

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

SAP In-Memory Database: SQL Reference Manual


ALTER SESSION
SQL Syntax:
ALTER SESSION RESTORE <alter_session_restore_options>
| ALTER SESSION SET CURRENT_SCHEMA = <schema_name>
| ALTER SESSION SET TRACE_COMPONENT = string_constant TRACE_LEVEL=string_constant
| ALTER SESSION [session_id] SET str_const '=' str_const
| ALTER SESSION [session_id] UNSET str_const
| ALTER SESSION DDL AUTOCOMMIT ON|OFF
Parameters:
<alter_session_restore_options> ::=
NOW
| WITH CID = <commit_id>| WITH TIMESTAMP = <timestamp>
Description:
RESTORE
The session will restore the transaction snapshot to the point in time corresponding to the provided
option to allow a history search.
NOW Session will restore the snapshot to the current time from the history search.
CID Session will restore the snapshot corresponding to the specified commit ID (CID).
TIMESTAMP Session will restore the snapshot of the specified timestamp.
SET CURRENT_SCHEMA
You can change the current schema of the session. The current schema is used when database object
names such as table names are not prefixed with the schema name.
SET|UNSET
You can set session variables by providing key and value pairs. If you have session administration
privileges, you can change session variables of other sessions by specifying the session ID.
SET TRACE_COMPONENT
You can use this command to set session-specific trace options.
TRACE_COMPONENT Component name to be traced for the current session.
TRACE_LEVEL Level of the trace.
DDL AUTOCOMMIT
You can specify the auto commit property for DDL statements specific to the session.

103

SAP In-Memory Database: SQL Reference Manual


SET TRANSACTION
SQL Syntax:
SET TRANSACTION ISOLATION LEVEL <isolation_level>
Parameters:
<isolation_level> ::=READ COMMITTED| REPEATABLE READ| SERIALIZABLE
READ COMMITTED
Default.
This isolation level corresponds to the statement level read consistency.
With statement level snapshot isolation, different statements in a transaction may see
different snapshots of the system. The statement in a transaction sees consistent snapshots of
the system. Each statement sees the changes that were committed when the execution of the
statement started.
Reading a row does not set any locks. When rows are inserted, updated or deleted, the
system sets exclusive locks on the affected rows for the duration of the transaction. The
system releases these locks at the end of the transaction. When rows are inserted, updated or
deleted, the system also sets shared locks on the affected tables for the duration of the
transaction. This guarantees that the table is not dropped or altered while some rows of the
table are being updated.
REPEATABLE READ/ SERIALIZABLE
This isolation level corresponds to transaction level snapshot isolation.
All statements of a transaction see the same snapshot of the database. This snapshot contains
all changes that were committed at the time the transaction started with the changes made by
the transaction itself.
Reading a row does not set any locks. When rows are inserted, updated or deleted, the
system sets exclusive locks on the affected rows for the duration of the transaction. The
system releases these locks at the end of the transaction. When rows are inserted, updated or
deleted, the system also sets shared locks on the affected tables for the duration of the
transaction. This guarantees that the table is not dropped or altered while some rows of the
table are being updated.
Description:
The system uses multi-version concurrency control (MVCC) to ensure consistent read operations.
Concurrent read operations see a consistent view of the system without blocking concurrent write
operations. Updates are implemented not by overwriting existing records, but by inserting new
versions.
The isolation level specification determines the lock operation type. The system supports both
statement level snapshot isolation and transaction level snapshot isolation.
For statement snapshot isolation use level READ COMMITTED.
For transaction snapshot isolation use REPEATABLE READ or SERIALIZABLE.
DDL statements always run in READ COMMITTED isolation level.

104

SAP In-Memory Database: SQL Reference Manual

DCL (Data Control Language) Statements


GRANT
SQL Syntax:
GRANT <system_privilege>,... TO grantee [WITH ADMIN OPTION]
| GRANT <schema_privilege> ,... ON SCHEMA grantee TO grantee [WITH GRANT OPTION]
| GRANT <object_privilege>,... ON object TO grantee [WITH GRANT OPTION]
| GRANT <column_privilege>,... (column_name,... ) ON object TO grantee [WITH GRANT OPTION]
| GRANT role_name,... TO grantee [WITH ADMIN OPTION]
| GRANT STRUCTURED PRIVILEGE privilege_name TO grantee
Parameters:
system_privilege ::= CREATE SCHEMA | DATA ADMIN | ROLE ADMIN | USER ADMIN |
BACKUP ADMIN | CHECKPOINT ADMIN | CHECKPOINT EXEC | CREATE SCENARIO | CREATE
STRUCTURED PRIVILEGE | INIFILE ADMIN | LOGFLUSH ADMIN | MONITOR ADMIN | OPTIMIZER
ADMIN | RESOURCE ADMIN | SESSION ADMIN |SERVICE ADMIN | TENANT ADMIN | TRACE ADMIN |
VERSION ADMIN
schema_privilege ::= CREATE ANY | DELETE | DROP | EXECUTE | INSERT | SELECT | UPDATE
object_privilege ::= ALL PRIVILEGES | ALTER | DELETE | DROP | EXECUTE | INDEX | INSERT |
SELECT |UPDATE
column_privilege ::= INSERT | SELECT | UPDATE
grantee :: = user_name | role_name
structured_privilege_add ::= ALTER SYSTEM ADD STRUCTURED PRIVILEGE xml_string
xml_string ::= 'xml'
structured_privilege_drop ::= ALTER SYSTEM DROP STRUCTURED PRIVILEGE
Description:
A number of privileges are available to control the authorization of SQL commands. Following the
least-privileged principle, users should be given only the smallest set of privileges that they require for
their role. Thus, this document gives a complete overview of the privileges supported at the SQL level,
so that they can be assigned appropriately to database users in application development.
The SQL privileges can be divided into system and object privileges:
System privileges: These are system-wide privileges and control some general system
activities such as creating schemas, creating or changing users and roles.
Object privileges: These privileges are bound to an object and control activities which are
possible on this particular object, such as select/update/delete on database tables.
The following information describes all supported privileges in the two groups, together with the list of
the SQL commands they authorize.
System Privileges
User and Roles
USER ADMIN: This privilege authorizes the creation/changing of users via the SQL commands
CREATE USER, ALTER USER, and DROP USER.

105

SAP In-Memory Database: SQL Reference Manual


ROLE ADMIN: This privilege authorizes the creation and deletion of roles via the SQL
commands CREATE ROLE and DROP ROLE.
Catalog/Schema Management
CREATE SCHEMA: This privilege authorizes the creation of database schemas via the SQL
command CREATE SCHEMA.
DATA ADMIN: This is a very powerful privilege as it authorizes users a) to perform SELECT on
all catalog tables and views (in the SYS schema) and b) to execute ALL DDLs (and only DDLs)
commands in NewDB, in particular:
o For schemas: CREATE SCHEMA, DROP SCHEMA,
o For tables: CREATE (COLUMN) TABLE, DROP TABLE, ALTER TABLE,
o For views: CREATE (COLUMN) VIEW, DROP VIEW, ALTER VIEW,
o For indexes: CREATE INDEX, ALTER INDEX, DROP INDEX,
o For sequences: CREATE SEQUENCE, DROP SEQUENCE,
o For synonyms: CREATE SYNONYM, DROP SYNONYM,
o For table types: CREATE TABLE TYPE, DROP TABLE TYPE,
o For functions: CREATE FUNCTION, DROP FUNCTION.
CATALOG READ: This privilege authorizes users to perform SELECT on all catalog tables and
views (in the SYS schema)
Analytics
CREATE SCENARIO: This privilege controls the creation of calculation scenarios and cubes
(CalcEngine) via the following SQL commands:
o ALTER SYSTEM ADD SCENARIO,
o CREATE CALCULATION SCENARIO.
SCENARIO ADMIN: This privilege authorizes all calculation scenario-related activities (including
creation), which can be performed using the following SQL commands:
o ALTER SYSTEM ADD SCENARIO, ALTER SYSTEM FLATTEN SCENARIO
o CREATE CALCULATION SCENARIO, DROP CALCULATION SCENARIO, ALTER
CALCULATION SCENARIO.
CREATE STRUCTURED PRIVILEGE: This privilege authorizes the creation of structured
privileges (analytical privileges) via the SQL command ALTER SYSTEM ADD STRUCTURED
PRIVILEGE. Note that currently, only the owner of an analytical privilege can drop it. Therefore,
there is no addition privilege for dropping structured privileges.
Auditing
AUDIT
o
o
o

ADMIN: This privilege controls the execution of auditing-related SQL commands:


CREATE AUDIT POLICY
DROP AUDIT POLICY
ALTER AUDIT POLICY

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

SAP In-Memory Database: SQL Reference Manual


INIFILE ADMIN: This privilege authorizes different methods to change system settings, in
particular ALTER SYSTEM INIFILE.
LOGFLUSH ADMIN: This privilege authorizes the commands ALTER SYSTEM [ENABLE|DISABLE]
LOG FLUSH for enabling/disabling the log flush mechanism.
MONITOR ADMIN: This privilege authorizes all monitoring activities done using the various
ALTER SYSTEM MONITOR commands as well as the command ALTER SYSTEM SET MONITOR
LEVEL <level>.
RESOURCE ADMIN: This privilege authorizes the utilization of the management_console in SQL
via the command ALTER SYSTEM RESOURCES.
OPTIMIZER ADMIN: This privilege authorizes the commands ALTER SYSTEM QUERY CACHE
FLUSH and ALTER SYSTEM UPDATE STATISTICS SKIP, which influence the behavior of the
query optimizer.
SERVICE ADMIN: This privilege authorizes the commands ALTER SYSTEM
[START|KILL|RECONFIGURE], intended for administering system services of the database
engine.
SESSION ADMIN: This privilege authorizes the commands ALTER SYSTEM [KILL|DISCONNECT]
SESSION to stop or disconnect a user session.
TENANT ADMIN: This privilege authorizes the tenant operations performed by the commands
ALTER SYSTEM [\RESUME|SUSPEND] TENANT.
TRACE ADMIN: This privilege authorizes the ALTER SYSTEM [CLEAR|DELETE] TRACES
commands for operations on engine trace files.
VERSION ADMIN: This privilege authorizes the commands ALTER SYSTEM COLLECT VERSION
GARBAGE and ALTER SYSTEM CLEAR ALL VERSIONS of the MVCC mechanism.
Data Import and Export
Two system privileges are available for authorization of the data import/export in the database:
IMPORT: This privilege authorizes the import activity in the database via the commands
IMPORT or LOAD TABLE. Note that beside this privilege, the user still needs the INSERT
privilege on the target tables to be imported.
EXPORT: This privilege authorizes the export activity in the database via the commands
EXPORT or LOAD TABLE. Note that beside this privilege, the user still needs the INSERT
privilege on the source tables to be exported
Special-Purpose Privileges
Two system privileges have been currently included to support authorization in the repository. These
privileges are only intended for the utilization by the repository and thus must not be granted to a
normal database user:
REPO.IMPORT: This privilege authorizes the import activity in the repository.
REPO.EXPORT: This privilege authorizes the export activity in the repository.
Obsolete Privileges
ALTER SYSTEM: The universal ALTER SYSTEM privilege was used to authorize all ALTER
SYSTEM commands. As these commands are now authorized under individual privileges, the
ALTER SYSTEM privilege must no longer be used.
ALTER DATABASE: This privilege was used to authorize all ALTER DATABASE commands.
However, all these commands have been removed from NewDB. The ALTER DATABASE
privilege is now invalid and also must no longer be used.
Object Privileges
Object privileges are bound to objects they provide authorization for. The following table lists the
different object privileges supported by NewDB and the object types for which the privileges can be
employed (OK: applicable, -: not applicable, ?: dynamically evaluated - see Notes):

107

SAP In-Memory Database: SQL Reference Manual


Table 16: Object privileges supported by NewDB
Privilege

Schema Table View Table Type

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

SAP In-Memory Database: SQL Reference Manual


REVOKE
SQL Syntax:
REVOKE <system_privilege>,... FROM grantee
| REVOKE <schema_privilege>,... ON SCHEMA schema_name FROM grantee
| REVOKE <object_privilege>,... ON object FROM grantee
| REVOKE <column_privilege>,... ( column_name,... ) ON object FROM grantee
| REVOKE role_name,... FROM grantee
| REVOKE STRUCTURED PRIVILEGE <structured_privilege_name> FROM grantee
system_privilege ::= CREATE SCHEMA | DATA ADMIN | ROLE ADMIN | USER ADMIN |
BACKUP ADMIN | CHECKPOINT ADMIN | CHECKPOINT EXEC | CREATE SCENARIO | CREATE
STRUCTURED PRIVILEGE | INIFILE ADMIN | LOGFLUSH ADMIN | MONITOR ADMIN | OPTIMIZER
ADMIN | RESOURCE ADMIN | SESSION ADMIN |SERVICE ADMIN | TENANT ADMIN | TRACE ADMIN |
VERSION ADMIN
schema_privilege ::= CREATE ANY | DELETE | DROP | EXECUTE | INSERT | SELECT | UPDATE
object_privilege ::= ALL PRIVILEGES | ALTER | DELETE | DROP | EXECUTE | INDEX | INSERT |
SELECT |
UPDATE
column_privilege ::= INSERT | SELECT | UPDATE
grantee :: = user_name | role_name
structured_privilege_add ::= ALTER SYSTEM ADD STRUCTURED PRIVILEGE xml_string
xml_string ::= 'xml'
structured_privilege_drop ::= ALTER SYSTEM DROP STRUCTURED PRIVILEGE
structured_privilege_name
Description:
The REVOKE statement revokes all system privileges.

109

SAP In-Memory Database: SQL Reference Manual

DML (Data Manipulation Language)


INSERT
SQL Syntax:
INSERT [ INTO ] table_name [ ( column_name, ... ) ] { { VALUES (expr, ... ) } | subquery }
[ WITH PARAMETERS ( <parameter_key_value>, ... ) ]
Parameters:
parameter_key_value::=
<string_literal> = <string_literal> |
<identifier> = <string_literal> |
<string_literal> = (<string_literal>, ... )
Description:
The INSERT statement adds records to a table.
A subquery that returns records can be used to insert records into the table. If the subquery returns
no records, then the database does not insert any records into the table.
The column list can be specified with the INSERT statement. If the column list is omitted, the database
inserts all columns in the table.

110

SAP In-Memory Database: SQL Reference Manual


DELETE
SQL Syntax:
DELETE FROM table_name [ WHERE condition ] [ WITH PARAMETERS <parameter_key_value>, ... ) ]
Parameters:
parameter_key_value ::=
<string_literal> = <string_literal> | <identifier> = <string_literal> | <string_literal> =
(<string_literal>, ... )
Description:
The DELETE statement deletes records from a table where the conditions are met. If the WHERE
clause is omitted, then it removes all records from a table.

111

SAP In-Memory Database: SQL Reference Manual


UPDATE
SQL Syntax:
UPDATE table_ref [ [ AS ] name ] <set_clause> [WHERE condition] [ WITH PARAMETERS '('
parameter_key_value_list ')' ]
Parameters:
set_clause::= SET { {column_name = expr}, }
parameter_key_value ::=<string_literal> = <string_literal> |<identifier> = <string_literal> |
<string_literal> = (<string_literal>, ... )
Description:
The UPDATE statement changes the values of the records from a table where the condition is met.
If the WHERE clause condition is true, the value of that column is assigned to the result of expr.
If the WHERE clause is omitted, then it updates all records from a table.

112

SAP In-Memory Database: SQL Reference Manual


LOAD
SQL Syntax:
LOAD table_name <DELTA|ALL| column_list>
Description:
The LOAD statement loads the column store table data to memory.
DELTA - DELTA part of the column store table is loaded.
ALL ALL data of the column store table is loaded.
Column_list Columns specified in the column list are loaded into memory.

113

SAP In-Memory Database: SQL Reference Manual


UNLOAD
SQL Syntax:
UNLOAD table_name
Description
The UNLOAD statement unloads the column store table data from memory to disk.

114

SAP In-Memory Database: SQL Reference Manual


UPSERT / REPLACE
SQL Syntax:
UPSERT table_name [ ( column_name, ... ) ] { values_list_clause | subquery }
REPLACE table_name [ ( column_name, ... ) ] { values_list_clause | subquery }
values_list_clause ::= VALUES { ( expr, ... ) } [ WHERE condition | WITH PRIMARY KEY ]
Description:
The UPSERT/REPLACE statement without a subquery is similar to the UPDATE statement. The only
difference is when the WHERE clause condition is false, it adds a new record to the table like the
INSERT statement.
In case of a table which has a PRIMARY KEY, the PRIMARY KEY column must be included in the
columns list because there is a chance the record is inserted.
The UPSERT/REPLACE statement with a subquery works like the INSERT statement, except that if an
old row in the table has the same value as a new row for a PRIMARY KEY, then the old row is changed
by values of the returned record from a subquery. Unless the table has a PRIMARY KEY, it becomes
equivalent to INSERT because there is no index to be used to determine whether or not a new row
duplicates another.
The UPSERT/REPLACE statement with a 'WITH PRIMARY KEY' is same as one with the subquery. It
works based on the PRIMARY KEY.
Note: an UPSERT without both a WHERE clause and a 'WITH PRIMARY KEY' is not based on the primary
key, but does affect all rows in the table. See last example
Example:
CREATE TABLE A(A INT PRIMARY KEY, B INT);
UPSERT A VALUES (1, 1);
Result:
AB
11
UPSERT A SELECT A + 1, B FROM A;
Result
A B
2 1

115

SAP In-Memory Database: SQL Reference Manual


SELECT
SQL Syntax:

subquery [ order_by_clause ] [ limit_clause ] [ FOR UPDATE [OF column_name_list] ] WITH


PARAMETERS '(' parameter_key_value_list ')' ]
subquery ::= select_clause from_clause [ where_clause ] [group_by_clause] [ having_clause ]
{[ set_operator subquery] }
select_clause ::= SELECT [ TOP expr ] [ ALL | DISTINCT ] select_list
select_list ::= * | { { expr [ AS ] column_alias }, ... }
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
where_clause MISSING GIVE INFO
group_by_clause::=GROUP BY <group_by_item_list>
group_by_item_list::=[{ROLLUP | CUBE | GROUPING_SETS} [grouping_set_option]
[grouping_set_text_filter_option][grouping_set_structured_option]]
<simple_group_by_item>
simple_group_by_item::=<expression_list>
having_clause::=HAVING condition
set_operator::= {UNION [ALL]} | INTERSECT | EXCEPT | MINUS
order_by_clause::=ORDER BY {{ expr | position } [ASC | DESC] }, ...
limit_clause::=LIMIT expr [OFFSET expr]

FOR UPDATE [OF column_name_list]


WITH PARAMETERS '(' parameter_key_value_list ')'
parameter_key_value_list ::= (<string_literal> = <string_literal> |<identifier> =
<string_literal> |<string_literal> = (<string_literal>, ... )
Description:
select_clause ::= SELECT [ TOP expr ] [ ALL | DISTINCT ] select_list
select_list ::= * | { { expr [ AS ] column_alias }, ... }

116

SAP In-Memory Database: SQL Reference Manual


The SELECT statement retrieves data from one or more tables in the database.
TOP

Returns the fist expr records from the SQL statement.

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

SAP In-Memory Database: SQL Reference Manual


set_operator::= {UNION [ALL]} | INTERSECT | EXCEPT | MINUS
Set operators enable more than one select statement to be combined, but only one result set
is returned.
UNION ALL Selects all rows from all select statements.
UNION Selects all unique rows from all select statements by removing duplicate rows found
from different select statements.
INTERSECT Returns the rows that exist in all select statements in common.
EXCEPT Returns the rows from the first select statements after removing the duplicates in
the following select statements.
MINUS Returns the rows from the first select statements after removing the duplicates in the
following select statements.
FOR UPDATE
The FOR UPDATE keyword locks the selected rows so that other users cannot lock or update
the rows until end of this transaction.
limit_clause::=LIMIT expr [OFFSET expr]
LIMIT
Returns the fist expr records from the SQL statement. When OFFSET number is specified, the
database skips that many rows (number) before returning the results set.
group_by_clause::=GROUP BY <group_by_item_list>
group_by_item_list::=[{ROLLUP | CUBE | GROUPING_SETS} [grouping_set_option]
[grouping_set_text_filter_option][grouping_set_structured_option]] <simple_group_by_item>
simple_group_by_item::=<expression_list>
The GROUP BY keyword groups the selected rows based on the special value of column.
ROLLUP
Generates simple GROUP BY aggregate rows. It also generates rows with subtotals for
groupings generated from the given columns; one row with a subtotal is generated for each
unique combination of values in given columns and subset of given columns. A grand total row
is also calculated. For example, given three columns in ROLLUP (column1, column2, column3),
it can generate the following groupings: 0, column1, column1 and column2, column1 and
column2 and column3.
CUBE
Generates rows generated from ROLLUP aggregates, and cross-tabulation rows. For example,
given three columns in CUBE(column1, column2, column3), it can generate the following
groupings: 0, column1, column2, column3, column1 and column2, column1 and column3,
column2 and column3, column1 and column2 and column3.
GROUPING_SETS
Generates rows with specified multiple groupings of data in one query. Only specified groups
are considered instead of all the combinations calculated by ROLLUP or CUBE. The result is the
same as UNION ALL of the aggregation of each specified group.

118

SAP In-Memory Database: SQL Reference Manual


EXPLAIN PLAN
SQL Syntax:
EXPLAIN PLAN [ SET PLAN_ID = plan_id ] FOR dml_stmt
Parameters:
SET PLAN_ID=constant statement is used to identify the name of a specific execution plan in the
output table for a given SQL statement.
It is set to NULL if the SET PLAN_ID is not specified.
The FOR clause is followed by the execution plan for a SQL statement.
Description:
The EXPLAIN PLAN statement is used to determine the execution plan SAP IMDB follows to execute a
specified SQL statement. The EXPLAIN PLAN statement inserts a record describing each step of the
execution plan into a specified table. This specified table is called QUERY_PLANS.
The SQL statement is a data manipulation language (DML) statement, thus a data definition language
(DDL) statement cannot be used in the EXPLAIN PLAN statement.
You can get the query plan from QUERY_PLANS view. The view is shared by all users.
Here is an example of reading a query plan from the view.
SELECT lpad(' ', level) || operator_name AS operator_name,
operator_details,
object_name,
subtree_cost,
input_cardinality,
output_cardinality,
operator_id,
parent_operator_id,
level,
position
FROM query_plans
ORDER BY operator_id;
Columns in QUERY_PLANS view:
Columns in QUERY_PLANS view is as follows:
Table 17: Column name and description
Column Name
PLAN_ID

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

Name of database tables and views accessed by an operator.

119

SAP In-Memory Database: SQL Reference Manual


Column Name

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

Unique ID of an operator. IDs are integers starting from 1.

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.

OPERATOR_NAME column in QUERY_PLANS view:


Table 18. List of column engine operators shown in the OPERATOR_NAME column.
Operator Name
COLUMN SEARCH

Description

LIMIT

Starting position of column engine operators. OPERATOR_DETAILS lists projected


columns.
Operator for limiting the number of output rows

ORDER BY

Operator for sorting output rows

HAVING

Operator for filtering with predicates on top of grouping and aggregation

GROUP BY

Operator for grouping and aggregation

DISTINCT

Operator for duplicate elimination

FILTER

Operator for filtering with predicates

JOIN

Operator for joining input relations

COLUMN TABLE

Information about accessed column table

MULTIPROVIDER

Operator for producing union-all of multiple grouping and aggregations

Table 19. List of row engine operators shown in the OPERATOR_NAME column.
Operator Name

Description

ROW SEARCH

Starting position of row engine operators. OPERATOR_DETAILS lists projected


columns.

LIMIT

Operator for limiting number of output rows

ORDER BY

Operator for sorting output rows

HAVING

Operator for filtering with predicates on top of grouping and aggregation

GROUP BY

Operator for grouping and aggregation

MERGE AGGREGATION

Operator for merging the results of multiple parallel grouping and aggregations

120

SAP In-Memory Database: SQL Reference Manual


Operator Name

Description

DISTINCT

Operator for duplicate elimination

FILTER

Operator for filtering with predicates

UNION ALL

Operator for producing union-all of input relations

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.

CPBTREE INDEX 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.

NESTED LOOP JOIN

Operator for joining input relations through nested looping. Join type suffix can be
added.

BTREE INDEX SEARCH

Table access through B-Tree index search

CPBTREE INDEX SEARCH

Table access through CPB-Tree index search

TABLE SCAN

Table access through scanning

AGGR TABLE

Operator for aggregating base table directly

MONITOR SEARCH

Monitoring view access through search

MONITOR SCAN

Monitoring view access through scanning

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

SAP In-Memory Database: SQL Reference Manual


operator_name
BTREE INDEX JOIN
COLUMN SEARCH
FILTER
COLUMN TABLE

operator_id

parent_operator_id

level

position

10

11

10

10

12

11

11

Example of query plan explanation


Here is an example of query plan explanation of TPC-H Q10. In the example, all tables are located on
the row store.
DELETE FROM query_plans WHERE plan_id = 'TPC-H Q10';
EXPLAIN PLAN SET plan_id = 'TPC-H Q10' FOR
SELECT TOP 20
c_custkey,
c_name,
SUM(l_extendedprice * (1 - l_discount)) AS revenue,
c_acctbal,
n_name,
c_address,
c_phone,
c_comment
FROM
customer,
orders,
lineitem,
nation
WHERE c_custkey = o_custkey
AND l_orderkey = o_orderkey
AND o_orderdate >= TO_DATE('1993-10-01')
AND o_orderdate < ADD_MONTHS(TO_DATE('1993-10-01'),3)
AND l_returnflag = 'R'
AND c_nationkey = n_nationkey
GROUP BY
c_custkey,
c_name,
c_acctbal,
c_phone,
n_name,
c_address,
c_comment
ORDER BY
3 DESC;
SELECT lpad(' ', level) || operator_name AS operator_name,
operator_details, object_name, subtree_cost, input_cardinality,
output_cardinality, operator_id,
parent_operator_id, level, position
FROM query_plans
WHERE plan_id = 'TPC-H Q10'
ORDER BY operator_id;
The following is the plan explanation of the above query.

122

SAP In-Memory Database: SQL Reference Manual


operator_n
ame
ROW
SEARCH

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

SAP In-Memory Database: SQL Reference Manual


operator_n
ame

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

BTRE INDEX NAME:


_SYS_TREE_978_#
0_#P0, INDEX
CONDITION:
N_NATIONKEY =
CAST(CUSTOMER.C
_NATIONKEY AS
BIGINT)
INDEX NAME:
BT
_SYS_TREE_974_#
REE INDEX
0_#P0, INDEX
JOIN
CONDITION:
C_CUSTKEY =
CAST(ORDERS.O_C
USTKEY AS
BIGINT)
T
FILTER
ABLE SCAN
CONDITION:
(ORDERS.O_ORDE
RDATE < 1994-0101 AND
ORDERS.O_ORDER
DATE >= 1993-1001)

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

This means that:


1. TABLE SCAN will be executed on R_ORDERS with the FILTER CONDITION.
2. BTREE INDEX JOIN will be executed with the btree index of R_CUSTOMER and the result of
the below TABLE SCAN.
3. BTREE INDEX JOIN will be executed with the btree index of R_NATION and the result of
the below BTREE INDEX JOIN.
4. CPBTREE INDEX JOIN will be executed with the cptree index of R_LINEITEM and the result
of the below BTREE INDEX JOIN.
5. GROUP BY will be executed with the result of the below CPBTREE INDEX JOIN, with 4
threads.
6. MERGE AGGREGATION will be executed with the result of the below GROUP BY.

124

SAP In-Memory Database: SQL Reference Manual

SQL Commands for Export/Import Data


DUMP TABLE
SQL Syntax:
DUMP TABLE [TABLE] INTO '[filename]'
Description:
The DUMP TABLE statement exports all [TABLE] data to the [filename].csv file and [filename].ctl file.
.csv file has the dumped data that is separated by ',' and .ctl file is a control file which contains
commands to import data into tables.
The content of .csv file is as follows:
1000001,"That
1000002,"That
1000003,"That
1000004,"That

is:
is:
is:
is:

correct!","31323334353637383930"
correct!","31323334353637383930"
correct!","31323334353637383930"
correct!","31323334353637383930"

The content of the .ctl file is as follows:


load data
into table "DDLOB3"
infile '/home/jyk/ddlob3.data.csv' "STR '\n'"
fields terminated by ','
optionally enclosed by '"'
badfile '/home/jyk/ddlob3.data.bad'
The DUMP TABLE statement dumps the column table [TABLE] data to '[export_path]'.
The data file format is not in csv format, but column table data format.

125

SAP In-Memory Database: SQL Reference Manual


LOAD FROM
SQL Syntax:
LOAD FROM '[control filename]' THREADS [nthreads] BATCH [batchsize]
Parameters:
Control filename: A control file which contains commands to import data into tables.
Nthreads: The number of loading threads.
Batchsize: The number of records that is a unit of transaction commit.
Description:
The LOAD FROM statement imports all data that is referenced by [control filename] with [nthreads] threads
and [batchsize].

126

SAP In-Memory Database: SQL Reference Manual


EXPORT
SQL Syntax:
EXPORT <table_name_list> AS BINARY INTO '<path>' [WITH <option_list>] [THREADS N]
<table_name_list> := <table_name>, <table_name_list> | <table_name> | ALL
<option_list> := <option_name>, <option_name_list> | <option_name>
<option_name> := REPLACE | CATALOG ONLY
Description:
The EXPORT statement exports column views and tables.
These commands support all types of column tables & views (including BWA720 data).
To export/import all tables you should use the keyword ALL.
If you want to export/import tables of a specific schema, you should use the schema name with the
asterisk:
EXPORT "SCHEMA"."*" AS BINARY INTO '<path>' [WITH <option_list>] [THREADS N]
You can monitor the progress of the export/import using M_EXPORT_BINARY_STATUS system views.
Also, you can abort the export/import session using the connection ID from the corresponding view in
the following command:
ALTER SYSTEM KILL SESSION 'connectionId'
The detailed result of the export/import is stored in session-local temporary tables.
#EXPORT_BINARY_RESULT.

127

SAP In-Memory Database: SQL Reference Manual


IMPORT
SQL Syntax:
IMPORT <table_name_list> AS BINARY FROM '<path>' [WITH <option_list>] [THREADS N]
<table_name_list> := <table_name>, <table_name_list> | <table_name> | ALL
<option_list> := <option_name>, <option_name_list> | <option_name>
<option_name> := REPLACE | CATALOG ONLY
Description:
The IMPORT statement imports column views and tables.
These commands support all types of column tables & views.
To import all tables you should use the keyword ALL.
If you want to import tables of a specific schema, you should use the schema name with the asterisk:
IMPORT "SCHEMA"."*" AS BINARY FROM '<path>' [WITH <option_list>] [THREADS N]
You can monitor the progress of the export/import using M_IMPORT_BINARY_STATUS system views.
Also, you can abort the import session using the connection ID from the corresponding view in the
following command:
ALTER SYSTEM KILL SESSION 'connectionId'
The detailed result of the export/import is stored in session-local temporary tables.
#IMPORT_BINARY_RESULT.

128

SAP In-Memory Database: SQL Reference Manual

Appendix
Restrictions for SQL Statements
Database
Maximum number of schemas
Maximum number of Users

Database size limit

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

Maximum number of locks


Maximum number of maximum sessions

Tables and Views


Maximum number of columns in a table
Maximum number of columns in a view
Maximum number of rows in each table
Maximum length of a row
Maximum size of a non-partitioned table
Indexes and Constraints
Maximum number of indexes for each table
Maximum number of primary key columns in each table
Maximum number of columns in an index
Maximum number of columns in a UNIQUE constraint
Maximum size of sum of primary key, index, UNIQUE
constraint

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

Maximum number of columns that can be used for grouping


or aggregation

1,000,000

Maximum number of columns in an ORDER or GROUP

Approximately 2^31
129

SAP In-Memory Database: SQL Reference Manual


clause
Maximum number of columns in an SELECT statement
Maximum number of columns in a results table

Approximately 2^31
Approximately 2^31

Maximum number of join tables in a SELECT statement

Approximately 2^31

Maximum number of JOIN predicates in a search condition

Unlimited
Approximately 2^31
Approximately 2^31

Maximum number of base tables in a view


Maximum number of tables in a FROM clause
Maximum number of rows that can be inserted with a single
INSERT statement with Batch option
Maximum number of predicates in a WHERE or HAVING
clause

2^31
2^64

Maximum number of correlated columns in an SQL


statement

Approximately 2^31

Maximum number of correlated tables in an SQL statement

Approximately 2^31

Maximum number of parameters in an SQL statement

Unlimited
Maximum number of SET clauses in a single update operation Approximately 2^31
SQLScript
Maximum size of all stored procedures

Limited by RS storage size ( 1TB )

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

SAP In-Memory Database: SQL Reference Manual


Language Name

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

SAP In-Memory Database: SQL Reference Manual


Language Name

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

SAP In-Memory Database: SQL Reference Manual


Language Name

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

SAP In-Memory Database: SQL Reference Manual


Language Name

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

SAP In-Memory Database: SQL Reference Manual


Language Name

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

SAP In-Memory Database: SQL Reference Manual


Language Name

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

ANTIGUA AND BARBUDA

AG

ARGENTINA

AR

ARMENIA

AM

ARUBA

AW

AUSTRALIA

AU

136

SAP In-Memory Database: SQL Reference Manual


Country Name

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

BOSNIA AND HERZEGOVINA

BA

BOTSWANA

BW

BOUVET ISLAND

BV

BRAZIL

BR

BRITISH INDIAN OCEAN TERRITORY

IO

BRUNEI DARUSSALAM

BN

BULGARIA

BG

BURKINA FASO

BF

BURUNDI

BI

CAMBODIA

KH

CAMEROON

CM

CANADA

CA

CAPE VERDE

CV

137

SAP In-Memory Database: SQL Reference Manual


Country Name

Country Code

CAYMANISLANDS

KY

CENTRALAFRICANREPUBLIC

CF

CHAD

TD

CHILE

CL

CHINA

CN

CHRISTMAS ISLAND

CX

COCOS (KEELING) ISLANDS

CC

COLOMBIA

CO

COMOROS

KM

CONGO

CG

CONGO, THE DEMOCRATIC REPUBLIC OF THE

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

SAP In-Memory Database: SQL Reference Manual


Country Name

Country Code

ERITREA

ER

ESTONIA

EE

ETHIOPIA

ET

FALKLAND ISLANDS (MALVINAS)

FK

FAROE ISLANDS

FO

FIJI

FJ

FINLAND

FI

FRANCE

FR

FRENCH GUIANA

GF

FRENCH POLYNESIA

PF

FRENCH SOUTHERN TERRITORIES

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

SAP In-Memory Database: SQL Reference Manual


Country Name

Country Code

GUYANA

GY

HAITI

HT

HEARD ISLAND AND MCDONALDISLANDS

HM

HOLY SEE (VATICAN CITYSTATE)

VA

HONDURAS

HN

HONG KONG

HK

HUNGARY

HU

ICELAND

IS

INDIA

IN

INDONESIA

ID

IRAN, ISLAMIC REPUBLIC OF

IR

IRAQ

IQ

IRELAND

IE

ISRAEL

IL

ITALY

IT

JAMAICA

JM

JAPAN

JP

JORDAN

JO

KAZAKHSTAN

KZ

KENYA

KE

KIRIBATI

KI

KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF

KP

KOREA, REPUBLIC OF

KR

KUWAIT

KW

KYRGYZSTAN

KG

LAO PEOPLE'S DEMOCRATIC REPUBLIC

LA

140

SAP In-Memory Database: SQL Reference Manual


Country Name

Country Code

LATVIA

LV

LEBANON

LB

LESOTHO

LS

LIBERIA

LR

LIBYAN ARAB JAMAHIRIYA

LY

LIECHTENSTEIN

LI

LITHUANIA

LT

LUXEMBOURG

LU

MACAO

MO

MACEDONIA, THE FORMERYUGOSLAVREPUBLIC OF

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

MICRONESIA, FEDERATED STATES OF

FM

MOLDOVA, REPUBLIC OF

MD

MONACO

MC

MONGOLIA

MN

141

SAP In-Memory Database: SQL Reference Manual


Country Name

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

NORTHERN MARIANA ISLANDS

MP

NORWAY

NO

OMAN

OM

PAKISTAN

PK

PALAU

PW

PALESTINIANTERRITORY, OCCUPIED

PS

PANAMA

PA

PAPUA NEW GUINEA

PG

PARAGUAY

PY

PERU

PE

142

SAP In-Memory Database: SQL Reference Manual


Country Name

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

SAINT KITTS AND NEVIS

KN

SAINT LUCIA

LC

SAINT PIERRE AND MIQUELON

PM

SAINT VINCENT AND THE GRENADINES

VC

SAMOA

WS

SAN MARINO

SM

SAO TOME AND PRINCIPE

ST

SAUDI ARABIA

SA

SENEGAL

SN

SERBIA AND MONTENEGRO

CS

SEYCHELLES

SC

SIERRA LEONE

SL

SINGAPORE

SG

SLOVAKIA

SK

SLOVENIA

SI

143

SAP In-Memory Database: SQL Reference Manual


Country Name

Country Code

SOLOMON ISLANDS

SB

SOMALIA

SO

SOUTH AFRICA

ZA

SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS

GS

SPAIN

ES

SRI LANKA

LK

SUDAN

SD

SURINAME

SR

SVALBARD AND JAN MAYEN

SJ

SWAZILAND

SZ

SWEDEN

SE

SWITZERLAND

CH

SYRIANARABREPUBLIC

SY

TAIWAN, PROVINCEOFCHINA

TW

TAJIKISTAN

TJ

TANZANIA, UNITED REPUBLIC OF

TZ

THAILAND

TH

TIMOR-LESTE

TL

TOGO

TG

TOKELAU

TK

TONGA

TO

TRINIDAD AND TOBAGO

TT

TUNISIA

TN

TURKEY

TR

TURKMENISTAN

TM

TURKS AND CAICOS ISLANDS

TC

144

SAP In-Memory Database: SQL Reference Manual


Country Name

Country Code

TUVALU

TV

UGANDA

UG

UKRAINE

UA

UNITED ARAB EMIRATES

AE

UNITED KINGDOM

GB

UNITED STATES

US

UNITED STATES MINOR OUTLYING ISLANDS

UM

URUGUAY

UY

UZBEKISTAN

UZ

VANUATU

VU

Vatican City State see HOLY SEE


VENEZUELA

VE

VIET NAM

VN

VIRGINISLANDS, BRITISH

VG

VIRGIN ISLANDS,U.S.

VI

WALLIS AND FUTUNA

WF

WESTERN SAHARA

EH

YEMEN

YE

Zaire see CONGO, THE DEMOCRATIC REPUBLIC OF THE


ZAMBIA

ZM

ZIMBABWE

ZW

145

Potrebbero piacerti anche