hana1 dev sql en
TRANSCRIPT
-
8/16/2019 Hana1 Dev SQL En
1/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)
-
8/16/2019 Hana1 Dev SQL En
2/146
SAP AGDietmar-Hopp-Allee 1669190 Walldorf GermanyT +49/18 05/34 34 34F +49/18 05/34 34 20www.sap.com
Copyright 2011 SAP AG. All rights reserved.
o part of this publication may be reproduced or transmitted in any
rm or for any purpose without the express permission of SAP AG.
he information contained herein may be changed without prior notice.
ome software products marketed by SAP AG and its distributors
ntain proprietary software components of other software vendors.
icrosoft, Windows, Excel, Outlook, and PowerPoint are registered
ademarks of Microsoft Corporation.
BM, DB2, DB2 Universal Database, System i, System i5, System p,
ystem p5, System x, System z, System z10, System z9, z10, z9,
eries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390,
S/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM,
ower Architecture, POWER6+, POWER6, POWER5+, POWER5,
OWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System
orage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks,
S/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere,etfinity, Tivoli and Informix are trademarks or registered trademarks
IBM Corporation.
nux is the registered trademark of Linus Torvalds in the U.S. and
her countries.
dobe, the Adobe logo, Acrobat, PostScript, and Reader are either
ademarks or registered trademarks of Adobe Systems Incorporated in
e United States and/or other countries.
racle is a registered trademark of Oracle Corporation.
NIX, X/Open, OSF/1, and Motif are registered trademarks of the Open
roup.
trix, ICA, Program Neighborhood, MetaFrame, WinFrame,
ideoFrame, and MultiWin are trademarks or registered trademarks of
trix Systems, Inc.
TML, XML, XHTML and W3C are trademarks or registered
ademarks of W3C®, World Wide Web Consortium, Massachusetts
stitute of Technology.
va is a registered trademark of Sun Microsystems, Inc
JavaScript is a registered trademark of Sun Microsystems, Inc., used
under license for technology invented and implemented by Netscape.
SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, PartnerEdge,
ByDesign, SAP Business ByDesign, and other SAP products and
services mentioned herein as well as their respective logos are
trademarks or registered trademarks of SAP AG in Germany and in
several other countries all over the world. All other product and servic
names mentioned are the trademarks of their respective companies. Da
contained in this document serves informational purposes only. Nation
product specifications may vary.
These materials are subject to change without notice. These materials
are provided by SAP AG and its affiliated companies ("SAP Group")
for informational purposes only, without representation or warranty of
any kind, and SAP Group shall not be liable for errors or omissions w
respect to the materials. The only warranties for SAP Group products
and services are those that are set forth in the express warranty
statements accompanying such products and services, if any. Nothingherein should be construed as constituting an additional warranty.
Disclaimer
Some components of this product are based on Java™. Any code
change in these components may cause unpredictable and severe
malfunctions and is therefore expressively prohibited, as is any
decompilation of these components.
Any Java™ Source Code delivered with this product is only to be used
by SAP’s Support Services and may not be modified or altered in any
way.
Documentation in the SAP Service Marketplace
You can find this documentation at the following Internet address:
service.sap.com/hana
-
8/16/2019 Hana1 Dev SQL En
3/146
SAP In-Memory Database: SQL Reference Manual
2
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
-
8/16/2019 Hana1 Dev SQL En
4/146
SAP In-Memory Database: SQL Reference Manual
3
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
-
8/16/2019 Hana1 Dev SQL En
5/146
SAP In-Memory Database: SQL Reference Manual
4
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
-
8/16/2019 Hana1 Dev SQL En
6/146
SAP In-Memory Database: SQL Reference Manual
5
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
-
8/16/2019 Hana1 Dev SQL En
7/146
SAP In-Memory Database: SQL Reference Manual
6
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
-
8/16/2019 Hana1 Dev SQL En
8/146
SAP In-Memory Database: SQL Reference Manual
7
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
-
8/16/2019 Hana1 Dev SQL En
9/146
SAP In-Memory Database: SQL Reference Manual
8
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
-
8/16/2019 Hana1 Dev SQL En
10/146
SAP In-Memory Database: SQL Reference Manual
9
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 1.0 Master Guide
SAP HANA 1.0 Installation Guide
SAP HANA
Administration &
Security
SAP HANA Knowledge
Center on SAP Help
Portal
http://help.sap.com/hana
SAP HANA 1.0 Technical Operations Manual
SAP HANA 1.0 Security Guide
https://service.sap.com/hanahttps://service.sap.com/~sapidb/011000358700000604552011https://service.sap.com/~sapidb/011000358700000604562011http://help.sap.com/hanahttp://help.sap.com/hanahttps://service.sap.com/~sapidb/011000358700000604562011https://service.sap.com/~sapidb/011000358700000604552011https://service.sap.com/hana
-
8/16/2019 Hana1 Dev SQL En
11/146
SAP In-Memory Database: SQL Reference Manual
10
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 arelational database and you can use it to retrieve or store information in the database. You can embedSQL 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 ormanipulate data within a table. Such data management capabilities and quality assurance are themajor 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 theend of the line is part of the comment.
Comments are delimited by "/*" and "*/". Everything from the open comment pair "/*" to theclose comment pair "*/" is considered part of the comment. These comment characters are usedfor a multiple line comment.
Note:In SAP IMDB SQL, comments are ignored when SQL statements are executed.
LanguageSAP IMDB supports 8 bits ASCII, and Unicode.
SQL Reserved WordsThis 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. Reservedwords are usually used for commands or functions and cannot be used for identifier names such asdatabases, tables, or fields. The following table lists the reserved words in SAP IMDB. However, SAPIMDB allows the use of reserved words as identifiers as long as the SQL grammar does not contain afragment 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
-
8/16/2019 Hana1 Dev SQL En
12/146
SAP In-Memory Database: SQL Reference Manual
11
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.
-
8/16/2019 Hana1 Dev SQL En
13/146
SAP In-Memory Database: SQL Reference Manual
12
Data TypesThis 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 includethe null value, which is a special value and indicates the absence of a value. Although all data typesinclude 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 TypesIn 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, SSrepresents 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-MM-DD HH24:MI:SS.SSS' or 'YYYY/MM/DD, HH:MI:SS.SSS'.
-
8/16/2019 Hana1 Dev SQL En
14/146
SAP In-Memory Database: SQL Reference Manual
13
Format TIMESTAMP
Example timestamp_value TIMESTAMP
Numeric Types
TINYINTThe TINYINT data type stores an 8-bit unsigned integer. The minimum value is 0 and themaximum value is 255 for TINYINT.
Format TINYINT
Example tinyint_value TINYINT
SMALLINTThe SMALLINT data type stores a 16-bit signed integer. The minimum value is -32,768 and themaximum value is 32,767 for SMALLINT.
Format SMALLINT
Example small int_value SMALLINT
INTEGER
The INTEGER data type stores a 32-bit signed integer. The minimum value is -2,147,483,648 andthe maximum value is 2,147,483,647 for INTEGER.
Format INT or INTEGER
Example int_value INT
BIGINTThe 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 thenumber 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 thiscase, 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.
-
8/16/2019 Hana1 Dev SQL En
15/146
SAP In-Memory Database: SQL Reference Manual
14
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
DOUBLEThe DOUBLE data type specifies a single-precision 64-bit floating-point number. The minimumvalue is -1.79769 x 10308 and the maximum value is 1.79769x10308 . The smallest positiveDOUBLE value is 2.2207x10-308 and the largest negative DOUBLE value is -2.2207x10-308.
Format DOUBLE or DOUBLE PRECISION
Example doub le_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 TypesThe character string data types are used to store values that contain character strings. WhileVARCHAR data types contain ASCII character strings, NVARCHAR are used for storing Unicodecharacter strings.
VARCHAR
The VARCHAR(n) data type specifies a variable-length ASCII character string, where n indicatesthe maximum length and is an integer between 1 and 5000. When n is not specified, it defaults tothe maximum or 5000. An attempt to store a longer string into a column of this type will truncatethe string to the specified maximum length.
Format VARCHAR(size)
Example varchar_name VARCHAR(10)
NVARCHARThe NVARCHAR(n) data type specifies a variable-length Unicode character set string.
-
8/16/2019 Hana1 Dev SQL En
16/146
SAP In-Memory Database: SQL Reference Manual
15
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 datasuch 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 followingoperations. 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 andconverting a date/time type value into a string value. Refer to the TO_DATE, TO_TIME,TO_TIMESTAMP, TO_CHAR and TO_NCHAR functions.
-
8/16/2019 Hana1 Dev SQL En
17/146
SAP In-Memory Database: SQL Reference Manual
16
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 FFto specify the number of digits in the fractionalsecond portion of the date time value returned.
If a digit is not specified, the default value is used.
Example: 'HH:MI:SS.FF' SELECTTO_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
YY
Y
Last 3, 2, or 1 digit(s) of year.
The following date/time format elements can additionally be used when converting a date/time typevalue into a string value. Refer to the TO_CHAR and TO_NCHAR functions.
Table 4: Additional date/time format elements
Element Description
-
8/16/2019 Hana1 Dev SQL En
18/146
SAP In-Memory Database: SQL Reference Manual
17
Element Description
D Day of week (1-7).
DAY Name of day (MONDAY - SUNDAY).
DY Abbreviated name of day(MONDAY=MON, ... , SUNDAY=SUN).
Q Quarter of year (1, 2, 3, 4; JANMAR = 1).
W 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 canbe 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 performedby implicitly converting VARCHAR to BIGINT. The entire explicit conversions can be used forimplicit conversion except for the TIME and TIMESTAMP data types. TIME and TIMESTAMP can beconverted 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
-
8/16/2019 Hana1 Dev SQL En
19/146
SAP In-Memory Database: SQL Reference Manual
18
Target
Timestamp Date Time
Source Timestamp - OK OK
Date OK - ERRORTime 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('2011-06-13')
Comparable (converted as'2011-06-13 00:00:00')
TIMESTAMP != '2001-06-1312:00:00'
TIMESTAMP != TIMESTAMP('2011-06-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-1312:00:00'
DATE != DATE('2011-06-1312:00:00')
Comparable because onlythe date part iscompared.
TIME != '12:00:00' TIME != TIME('12:00:00') Comparable
TIME != '2001-06-13' TIME != TIME('2011-06-13') Error because the datetype is not comparablewith the time type.
TIME != '2001-06-1312:00:00'
TIME != TIME('2011-06-1312:00:00')
Comparable because thedate part is ignored bytimestamp.
-
8/16/2019 Hana1 Dev SQL En
20/146
SAP In-Memory Database: SQL Reference Manual
19
In the table below, a green box with “OK” means data type conversions are allowed without anychecks. 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 andexplicit conversion except for Time to Timestamp conversion. Only explicit conversion is allowed forconverting the Time data type to Timestamp using the TO_TIMESTAMP or CAST function.
Table 7. Data type conversion table
Target Data
Type T I NYI NT
S MAL L I NT
I NT E GE R
BI GI NT
RE AL
D O UBL E
DE C I MAL
DE C I MAL ( P , S )
DAT E
T I ME
T I ME S T AMP
VAR C HAR
NVAR C HAR
VARBI NARY
SourceData
Type
TINYINTOK OK OK OK OK OK
SMALLINTOK OK OK OK OK
INTEGER OK OK OK OK
BIGINTOK
REALOK OK
DOUBLEOK
DECIMAL
DECIMAL(P,S)
DATEOK
TIME
TIMESTAMP OK OK
VARCHAR
NVARCHAR
VARBINARY
Data Type Precedence
This section describes the data type precedence provided by SAP IMDB. Data type precedencespecifies that the data type with lower precedence is converted to the data type with higherprecedence.
Highest TIMESTAMP
DATE
TIME
DOUBLE
-
8/16/2019 Hana1 Dev SQL En
21/146
SAP In-Memory Database: SQL Reference Manual
20
REAL
DECIMAL
BIGINT
INTEGERSMALLINT
TINYINT
NCLOB
NVARCHAR
CLOB
VARCHAR
BLOB
Lowest VARBINARY
-
8/16/2019 Hana1 Dev SQL En
22/146
SAP In-Memory Database: SQL Reference Manual
21
ConditionsA condition is specified by combining one more expressions or Boolean (logical) operators. Thespecified condition then returns one of the following logical or truth values: TRUE, FALSE, orUNKNOWN. 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 { = | != | | > | < | >= |
-
8/16/2019 Hana1 Dev SQL En
23/146
SAP In-Memory Database: SQL Reference Manual
22
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 andsecond 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
-
8/16/2019 Hana1 Dev SQL En
24/146
SAP In-Memory Database: SQL Reference Manual
23
OperatorsBy using operators in expressions, you can perform arithmetic computation, compare values, or assignvalues to each data item. This section describes the operators that are supported by SAP IMDB.
Unary and Binary OperatorsTable 8. Unary and binary operators
Operator Operation Format Description
Unary A unary operatorapplies to oneoperand or a singlevalue expression.
operator operand unary plus operator(+)
unary negation operator(-)
logical negation(NOT)
Binary A binary operatorapplies to twooperands or twovalues expressions.
operand1 operator operand2 multiplicative operators ( *, / ,% )
additive operators ( +,- )
comparison operators( =,!=,,=,IS NULL, LIKE,BETWEEN )
logical operators ( AND, OR )
Operator PrecedenceAn 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 decidewhich one to use first. For example, SAP IMDB evaluates operators with a higher precedence beforeevaluating those with a lower precedence, and evaluates operators with equal precedence from left toright 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
-
8/16/2019 Hana1 Dev SQL En
25/146
SAP In-Memory Database: SQL Reference Manual
24
Parentheses can be used to override the order of precedence and to force some parts of an expressionto be evaluated before others. Operations within parentheses are always performed before thoseoutside the parentheses.
Arithmetic OperatorsArithmetic 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 itsnumeric argument unchanged andthe unary - (minus) operator yieldsthe negation of its numeric argument.When they add or subtract, they arebinary operators. The operatorsreturn the result of numeric
calculation.
SELECT * FROM students WHERE score = -1;
SELECT * FROM students WHERE –absent_days < 5;
*, / These are binary operators used formultiplication or division and returnthe result of numeric calculation. UPDATE students SET score = score * 1.2;
Concatenation OperatorsA concatenation operator combines two items such as strings, expressions, or constants into one.
Table 11. Concatenation operators
Operator Description Example
|| The concatenation operatorreturns the concatenation of itsright 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, theresult has data type NVARCHAR and is limited to 5000 characters.
Comparison OperatorsComparison operators check whether two expressions are the same and return one of these threevalues: 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;
-
8/16/2019 Hana1 Dev SQL En
26/146
SAP In-Memory Database: SQL Reference Manual
25
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;
-
8/16/2019 Hana1 Dev SQL En
27/146
SAP In-Memory Database: SQL Reference Manual
26
ESCAPE Clause Example
The "%" or "_" character can be included in the pattern by using the escape character. If the escapecharacter appears in the pattern before the character "%" or "_", then SAP IMDB interprets thischaracter 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, orto invert the result of a single condition.
The following table lists the SAP IMDB logical operators.
Table 13. Logical operators
Operator Operation Example
NOT The result of NOT(TRUE) is FALSE.
The result of NOT(FALSE) is TRUE.
The result of NOT(UNKNOWN) ISUNKNOWN.
SELECT * FROM students WHERE NOT (student_id
< 0 );
AND Returns TRUE if the following twoconditions are both TRUE.
Returns FALSE if one of thecondition is FALSE.
Otherwise, returns UNKNOWN.
SELECT * FROM students WHERE student_id ='0123' AND address = ‘some address’;
OR Returns TRUE if one of the following
condition is TRUE.
Returns FALSE if the two conditionsare both FALSE.
Otherwise, returns UNKNOWN.
SELECT * FROM studentsWHERE student_id= ’0123’ OR address = ‘some address’;
Set OperatorsThe 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 combinesthem into a distinct result set.
UNION ALL Takes output from two queries, including allduplicate rows.
-
8/16/2019 Hana1 Dev SQL En
28/146
SAP In-Memory Database: SQL Reference Manual
27
Operator Returned Value
INTERSECT Takes output from two queries, and returns allcommon rows.
MINUS, EXCEPT Takes output from the first query and then
removes rows selected by the second query.
-
8/16/2019 Hana1 Dev SQL En
29/146
SAP In-Memory Database: SQL Reference Manual
28
ExpressionsAn expression is the result evaluated from one or more values, operators, and SQL functions.
Simple ExpressionsA simple expression defines a constant, a column, a sequence number, or null.
Syntax:
simple_expression ::= NULL | column_reference | constant | sequence_name.{ CURRVAL | NEXTVAL }
Compound ExpressionsA compound expression combines other expressions and returns a single valued result.
Syntax:
compound_expression ::= ( expr ) | - expr | expr { * | / | + | - | || } expr
Case ExpressionsA case expression allows the user to use IF ... THEN ... ELSE logic without using procedures in SQLstatements.
Syntax:
case_expression ::= CASE { simple_case | searched_case } [ else_case ] ENDsimple_case ::= expr { { WHEN comparison_expr THEN return_expr } ... }searched_case ::= { WHEN condition THEN return_expr } ...else_case ::= ELSE expr
Function ExpressionsSQL 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 ExpressionsA scalar subquery expression is a subquery that returns a single row consisting of a single value. If thesubquery does not return a row, then the result of this expression is NULL. If the subquery returnsmore than one row, an error occurs.
Syntax:
scalar_subquery_expression ::= ( subquery )
-
8/16/2019 Hana1 Dev SQL En
30/146
SAP In-Memory Database: SQL Reference Manual
29
FunctionsSimilar to an operator, a function manipulates data items and returns a result. Functions differ fromoperators in the format of their arguments. Functions can take zero, one, or more arguments. Thischapter 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. SQLfunctions are used to calculate data, display the group result of the data items conversion, or toconvert 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:
functi on (argument, argument, ... )
-
8/16/2019 Hana1 Dev SQL En
31/146
SAP In-Memory Database: SQL Reference Manual
30
Number FunctionsNumber functions take numeric values or strings with numeric characters as inputs and returnsnumeric values. When strings with numeric characters are given as inputs, implicit conversion fromstring 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) "absol ut e" FROM dual ;
Retrieves:
absol ut e
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 piexpressed in radians.
Example:
SELECT ACOS(0.5) "acos" FROM dual;Retrieves:acos1. 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:asi n0. 5235987755982989
-
8/16/2019 Hana1 Dev SQL En
32/146
SAP In-Memory Database: SQL Reference Manual
31
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 inradians. The argument is a number and the range of n is unlimited.
Example:
SELECT ATAN(0.5) "atan" FROM dual;
Retrieves:at an0. 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:atan20. 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-negativeintegers: an integer is returned then.
Example:
SELECT BITAND(255, 123) "bitand" FROM dual;
Retrieves:bi t and and123
CEIL / CEILING Function
Syntax :
CEIL ( n )
Description:
Calculates the smallest integer value which is greater than or equal to n.
-
8/16/2019 Hana1 Dev SQL En
33/146
SAP In-Memory Database: SQL Reference Manual
32
Example:
SELECT CEIL(14.5) "ceiling" FROM dual;
Retrieves:cei l i ng15
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:cos1. 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:Cot1. 5423510453569202
EXP Function
Syntax:
EXP ( n )
-
8/16/2019 Hana1 Dev SQL En
34/146
SAP In-Memory Database: SQL Reference Manual
33
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:
exp2. 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:f l oor14
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:gr eat estbb
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:l eastaa
-
8/16/2019 Hana1 Dev SQL En
35/146
SAP In-Memory Database: SQL Reference Manual
34
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:l n1. 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 mustbe any positive value.
Example:
SELECT LOG(10, 2) "log" FROM dual;
Retrieves:l og0. 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 thereturned remainder from MOD is less than 0, and if m is greater than 0, then the returnedremainder from MOD is greater than zero.
Example:
SELECT MOD(15, 4) "modulus" FROM dual;
Retrieves:modul us3
-
8/16/2019 Hana1 Dev SQL En
36/146
SAP In-Memory Database: SQL Reference Manual
35
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:power1024. 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 isrounded to the nearest number without a decimal point.
Example:
SELECT ROUND(16.16, 1) "round" FROM dual;
Retrieves:r ound16. 2
SELECT ROUND(16.56) "round" FROM dual;
Retrieves:r ound17
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 anegative value, and 0 if n is equal to zero.
Example:
SELECT SIGN(-15) "sign" FROM dual;
Retrieves:si gn- 1
-
8/16/2019 Hana1 Dev SQL En
37/146
SAP In-Memory Database: SQL Reference Manual
36
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:si ne1. 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:si nh0. 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:sqrt1. 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:t an0. 0
-
8/16/2019 Hana1 Dev SQL En
38/146
SAP In-Memory Database: SQL Reference Manual
37
TANH Function
Syntax:
TANH ( n )
Description:
Computes the hyperbolic tangent of n.
Example:
SELECT TANH(1.0) "tanh" FROM dual;
Retrieves:t anh0. 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:asci i65
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:charact erAnt
CONCAT Function
Syntax :
CONCAT(str1, str2)
Description:Returns a combined string which consists of str1 followed by str2. The concatenation operator (||) isidentical to this function.
-
8/16/2019 Hana1 Dev SQL En
39/146
SAP In-Memory Database: SQL Reference Manual
38
Example:
SELECT CONCAT('C', 'at') "concat" FROM dual;
Retrieves:concatCat
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:i n s t r i ng11
LEFT Function
Syntax :
LEFT(str, n)
Description:Returns the first n character from str.
Example:SELECT LEFT('Hello', 3) "left" FROM dual;
Retrieves:l ef tHel
LCASE Function
Syntax:
LCASE(c)
Description:Returns c with all lowercase letters.
Example:
SELECT LCASE('Cat') "lcase” FROM dual;
Retrieves:l casecat
-
8/16/2019 Hana1 Dev SQL En
40/146
SAP In-Memory Database: SQL Reference Manual
39
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:l engt h14
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:Locate11
LOWER Function
Syntax
LOWER(c)
DescriptionReturns c with all lowercase letters
Example
SELECT LOWER('Ant') "lower" FROM dual;
Retrieves:l owerant
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;
-
8/16/2019 Hana1 Dev SQL En
41/146
SAP In-Memory Database: SQL Reference Manual
40
Retrieves:l pad123451234512end
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 instr 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:l t r i mAabend
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:nchrA
REPLACE Function
Syntax:
REPLACE (target, pattern, replace)
Description:
Returns a string value created by replacing every non-overlapping occurrence of the pattern in targetwith 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:r epl aceUPGRADE UPWARD
-
8/16/2019 Hana1 Dev SQL En
42/146
SAP In-Memory Database: SQL Reference Manual
41
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:r i ght789
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:r i ght paddedend123451234512
RTRIM Function
Syntax:
RTRIM (c [, str])
Description:Similar to a LTRIM function, but RTRIM removes from the rightmost of c all of the characters thatappear in str .
Example:
SELECT RTRIM ('endabAabbabab','ab') "rtrim" FROM dual;
Retrieves:r i ght t r i mmedendabA
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 lengthnumber 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.
-
8/16/2019 Hana1 Dev SQL En
43/146
SAP In-Memory Database: SQL Reference Manual
42
Example:
SELECT SUBSTR('abcdefgh',3,4) "substring" FROM dual;
Retrieves:subst r i ngcdef
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:subst r af t erFri end
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:subst r bef or eHel l o
TRIM Function
Syntax:
TRIM ( [ [LEADING | TRAILING | BOTH] trim_char FROM] trim_source])
-
8/16/2019 Hana1 Dev SQL En
44/146
SAP In-Memory Database: SQL Reference Manual
43
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 fromtrim_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:t r i mboth123456789
SELECT TRIM (LEADING 0 FROM 00012345678900) "trim leading" FROM dual;
Retrieves:
t r i ml eadi ng12345678900
UCASE Function
Syntax :
UCASE(c)
Description:Returns c with all uppercase letters.
Example:
SELECT UCASE('Ant') "ucase" FROM dual;
Retrieves:ucaseANT
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:uni code54620
UPPER Function
Syntax:
UPPER(c)
-
8/16/2019 Hana1 Dev SQL En
45/146
SAP In-Memory Database: SQL Reference Manual
44
Description:
Returns a string, c, after converting all characters to upper case.
Example:
SELECT UPPER('Ant') "uppercase" FROM dual;
Retrieves:upper caseANT
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 days2010- 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 mont hs2010- 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 years2010- 12- 05
-
8/16/2019 Hana1 Dev SQL En
46/146
SAP In-Memory Database: SQL Reference Manual
45
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 seconds00: 00: 45. 000
CURDATE Function
Syntax:
CURDATE()
Description:
Returns SYSDATE value.
Example:
SELECT CURDATE() FROM dual;
Retrieves:SYSDATE2011- 06- 03
CURTIME Function
Syntax:
CURTIME()
Description:
Returns SYSTIME value.
Example:
SELECT CURTIME() FROM dual;
Retrieves:SYSTI ME’ 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', 'YYYYMM-DD')) "days between" FROM dual;
-
8/16/2019 Hana1 Dev SQL En
47/146
SAP In-Memory Database: SQL Reference Manual
46
Retrieves:days bet ween31
DAYNAME Function
Syntax:
DAYNAME(expr)
Description:
Returns the name of the weekday in English.
Example:
SELECT DAYNAME('2011-05-30') "dayname" FROM dual;
Retrieves:daynameMONDAY
DAYOFMONTH Function
Syntax:
DAYOFMONTH(expr)
Description:
Returns the day of the month in integer.
Example:
SELECT DAYOFMONTH ('2011-05-30') "dayofmonth" FROM dual;
Retrieves:dayof month30
DAYOFYEAR Function
Syntax:
DAYOFYEAR(expr)
Description:
Returns the day of the year in integer.
Example:
SELECT DAYOFYEAR ('2011-05-30') "dayofyear" FROM dual;
Retrieves:dayof year150
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;
-
8/16/2019 Hana1 Dev SQL En
48/146
SAP In-Memory Database: SQL Reference Manual
47
Retrieves:ext r act2010
HOUR Function
Syntax:
HOUR(expr)
Description:
Extract hour from expr .
Example:
SELECT HOUR ('12:34:56’) "hour" FROM dual;
Retrieves:hour12
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:l ast day2010- 01- 31
MINUTE Function
Syntax:
MINUTE(expr)
Description:
Extract minute from expr .
Example:
SELECT MINUTE ('12:34:56’) "minute" FROM dual;
Retrieves:mi nut e34
MONTH Function
Syntax:
MONTH(expr)
Description:
Returns the number of the month from a given date.
-
8/16/2019 Hana1 Dev SQL En
49/146
SAP In-Memory Database: SQL Reference Manual
48
Example:
SELECT MONTH ('2011-05-30’) "month" FROM dual;
Retrieves:mont h5
MONTHNAME Function
Syntax:
MONTHNAME(expr)
Description:
Returns the name of the month in English.
Example:
SELECT MONTHNAME ('2011-05-30’) "monthname" FROM dual;
Retrieves:mont hname
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 day2010- 01- 01
NOW Function
Syntax:
NOW()
Description:
Returns the current timestamp.
Example:
SELECT NOW() "now" FROM dual;
Retrieves:now2010- 01- 01 16: 34: 19
SECOND Function
Syntax:
SECOND(t)
-
8/16/2019 Hana1 Dev SQL En
50/146
SAP In-Memory Database: SQL Reference Manual
49
Description:
Returns the second number of a given time t .
Example:
SELECT SECOND(’12:34:56’) "second" FROM dual;
Retrieves:
second56
SECONDS_BETWEEN Function
Syntax: