5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
■ ■ ■
http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
1/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
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.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of
No part of this publication may be reproduced or transmitted in any
Citrix Systems, Inc.
form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts
Some software products marketed by SAP AG and its distributors
Institute of Technology.
contain proprietary software components of other software vendors. Java is a registered trademark of Sun Microsystems, Inc © Copyright 2011 Sybase, Inc. All rights reserved. Unpublished rights reserved under U.S. copyright laws.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.
Sybase, the Sybase logo, Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere and other Sybase products and services mentioned
SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, PartnerEdge,
herein as well as their respective logos are trademarks or registered
ByDesign, SAP Business ByDesign, and other SAP products and
trademarks of Sybase, Inc. All other trademarks are the property of
services mentioned herein as well as their respective logos are
their respective owners.
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. Disclaimer Linux is the registered trademark of Linus Torvalds in the U.S. and
Some components of this product are based on Java™. Any code
other countries.
change in these components may cause unpredictable and severe malfunctions and is therefore expressively prohibited, as is any
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either
decompilation of these components.
trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.
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
Oracle is a registered trademark of Oracle Corporation.
way.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open
Documentation in the SAP Service Marketplace You can find this documentation at the following Internet address: service.sap.com/hana
Group.
http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
2/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Table of Contents SAP HANA Guides.................................................................................................................................... 9 Notation .............................................................................................................................................. 9 Introduction ..........................................................................................................................................10 SQL .................................................................................................................................................... 10 Supported Languages and Code Pages ............................................................................................. 10 Comment .......................................................................................................................................... 10 Identifiers ..........................................................................................................................................10 Single Quotation Mark ...................................................................................................................... 11 Double Quotation Mark .................................................................................................................... 12 SQL Reserved Words ......................................................................................................................... 12 Data Types ............................................................................................................................................. 13 Classification of Data Types .............................................................................................................. 13 Datetime Types ................................................................................................................................. 13 Numeric Types .................................................................................................................................. 13 Character String Types ...................................................................................................................... 15 Binary Types ...................................................................................................................................... 15 Large Object (LOB) Types .................................................................................................................. 15 Supported Formats for Date, Time and Timestamp ......................................................................... 17 Data Type Conversion ....................................................................................................................... 19 Predicates.............................................................................................................................................. 22 Comparison Predicates ..................................................................................................................... 22 Range Predicate ................................................................................................................................ 22 In Predicate ....................................................................................................................................... 22 Exists Predicate ................................................................................................................................. 22 LIKE Predicate ................................................................................................................................... 22 NULL Predicate .................................................................................................................................. 23 Operators .............................................................................................................................................. 24 Unary and Binary Operators ............................................................................................................. 24 Operator Precedence ........................................................................................................................ 24 Arithmetic Operators ........................................................................................................................ 25
2 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
3/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual String Operator ................................................................................................................................. 25 Comparison Operators......................................................................................................................25 Logical Operators .............................................................................................................................. 26 Set Operators .................................................................................................................................... 26 Expressions............................................................................................................................................ 27 Case Expressions ............................................................................................................................... 27 Function Expressions ........................................................................................................................ 28 Aggregate Expressions ...................................................................................................................... 28 Subqueries in expressions................................................................................................................. 29 Functions............................................................................................................................................... 30 Data type conversion functions ........................................................................................................ 30 CAST Function ............................................................................................................................... 30 TO_ALPHANUM Function ............................................................................................................. 30 TO_BIGINT Function ...................................................................................................................... 30 TO_BLOB Function ........................................................................................................................ 31 TO_CLOB Function ........................................................................................................................ 31 TO_DATE Function ........................................................................................................................ 31 TO_DATS Function ........................................................................................................................ 31 TO_DECIMAL Function .................................................................................................................. 31 TO_DOUBLE Function ................................................................................................................... 32 TO_INT Function ........................................................................................................................... 32 TO_INTEGER Function ................................................................................................................... 32 TO_NCLOB Function ...................................................................................................................... 32 TO_NVARCHAR Function .............................................................................................................. 33 TO_REAL Function ......................................................................................................................... 33 TO_SMALLINT Function ................................................................................................................ 33 TO_TINYINT Function .................................................................................................................... 34 TO_TIME Function......................................................................................................................... 34 TO_TIMESTAMP Function ............................................................................................................. 34 TO_VARCHAR Function ................................................................................................................. 34 DateTime Functions .......................................................................................................................... 36 ADD_DAYS Function ...................................................................................................................... 36 ADD_MONTHS Function ............................................................................................................... 36 ADD_YEARS Function .................................................................................................................... 36 3 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
4/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual ADD_SECONDS Function ............................................................................................................... 36 DAYS_BETWEEN Function ............................................................................................................. 37 DAYNAME Function ...................................................................................................................... 37 DAYOFMONTH Function ............................................................................................................... 37 DAYOFYEAR Function .................................................................................................................... 37 EXTRACT Function ......................................................................................................................... 38 HOUR Function.............................................................................................................................. 38 LAST_DAY Function ....................................................................................................................... 38 MINUTE Function .......................................................................................................................... 38 MONTH Function .......................................................................................................................... 38 MONTHNAME Function ................................................................................................................ 39 NEXT_DAY Function ...................................................................................................................... 39 NOW Function ............................................................................................................................... 39 SECOND Function .......................................................................................................................... 40 SECONDS_BETWEEN Function ...................................................................................................... 40 CURRENT_DATE Function ............................................................................................................. 40 CURRENT_TIME Function .............................................................................................................. 40 CURRENT_TIMESTAMP Function .................................................................................................. 41 CURRENT_UTCDATE Function.......................................................................................................41 CURRENT_UTCTIME Function ....................................................................................................... 41 CURRENT_UTCTIMESTAMP Function............................................................................................41 WEEK Function .............................................................................................................................. 42 WEEKDAY Function ....................................................................................................................... 42 YEAR Function ............................................................................................................................... 42 Number Functions............................................................................................................................. 43 ABS Function ................................................................................................................................. 43 ACOS Function............................................................................................................................... 43 ASIN Function ................................................................................................................................ 43 ATAN Function .............................................................................................................................. 43 ATAN2 Function ............................................................................................................................ 44 BITAND Function ........................................................................................................................... 44 CEIL / CEILING Function ................................................................................................................ 44 COS Function ................................................................................................................................. 44 COSH Function .............................................................................................................................. 45 4 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
5/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual COT Function ................................................................................................................................. 45 EXP Function ................................................................................................................................. 45 FLOOR Function ............................................................................................................................ 45 GREATEST Function ....................................................................................................................... 46 LEAST Function .............................................................................................................................. 46 LN Function ................................................................................................................................... 46 LOG Function ................................................................................................................................. 46 MOD Function ............................................................................................................................... 47 POWER Function ........................................................................................................................... 47 ROUND Function ........................................................................................................................... 47 SIGN Function................................................................................................................................ 48 SIN Function .................................................................................................................................. 48 SINH Function................................................................................................................................ 48 SQRT Function ............................................................................................................................... 48 TAN Function ................................................................................................................................. 49 TANH Function .............................................................................................................................. 49 String Functions ................................................................................................................................ 50 ASCII Function ............................................................................................................................... 50 CHAR Function .............................................................................................................................. 50 CONCAT Function .......................................................................................................................... 50 LEFT Function ................................................................................................................................ 50 LCASE Function.............................................................................................................................. 51 LENGTH Function .......................................................................................................................... 51 LOCATE Function ........................................................................................................................... 51 LOWER Function ........................................................................................................................... 51 LPAD Function ............................................................................................................................... 52 LTRIM Function ............................................................................................................................. 52 NCHAR Function ............................................................................................................................ 52 REPLACE Function ......................................................................................................................... 52 RIGHT Function ............................................................................................................................. 53 RPAD Function .............................................................................................................................. 53 RTRIM Function ............................................................................................................................. 53 SUBSTRING Function ..................................................................................................................... 54 SUBSTR_AFTER Function ............................................................................................................... 54 5 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
6/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual SUBSTR_BEFORE Function ............................................................................................................ 54 TRIM Function ............................................................................................................................... 55 UCASE Function ............................................................................................................................. 55 UNICODE Function ........................................................................................................................ 55 UPPER Function ............................................................................................................................. 55 Miscellaneous Functions ................................................................................................................... 57 BINTOHEX Function.......................................................................................................................57 COALESCE Function ....................................................................................................................... 57 HASANYPRIVILEGES Function........................................................................................................ 57 HASSYSTEMPRIVILEGE Function ................................................................................................... 58 HEXTOBIN Function.......................................................................................................................58 ISAUTHORIZED Function ............................................................................................................... 58 IFNULL Function ............................................................................................................................ 59 NULLIF Function ............................................................................................................................ 59 CURRENT_CONNECTION Function................................................................................................59 CURRENT_SCHEMA Function ........................................................................................................ 60 CURRENT_USER Function ............................................................................................................. 60 GROUPING_ID Function ................................................................................................................ 60 SESSION_CONTEXT Function......................................................................................................... 61 SYSUUID Function ......................................................................................................................... 62 SQL Statements ..................................................................................................................................... 63 ALTER AUDIT POLICY ..................................................................................................................... 63 ALTER SYSTEM ............................................................................................................................... 64 ALTER TABLE.................................................................................................................................. 69 ALTER USER ................................................................................................................................... 74 CONNECT....................................................................................................................................... 76 CREATE AUDIT POLICY................................................................................................................... 77 CREATE CALCULATION SCENARIO................................................................................................. 78 CREATE INDEX ............................................................................................................................... 80 CREATE ROLE ................................................................................................................................. 81 CREATE SCHEMA ........................................................................................................................... 82 CREATE SEQUENCE........................................................................................................................ 83 CREATE SYNONYM ........................................................................................................................ 86 CREATE TABLE ............................................................................................................................... 87 6 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
7/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual CREATE TYPE ................................................................................................................................. 93 CREATE USER ................................................................................................................................. 94 CREATE VIEW ................................................................................................................................ 95 DELETE........................................................................................................................................... 96 DROP AUDIT POLICY...................................................................................................................... 97 DROP CALCULATION SCENARIO.................................................................................................... 98 DROP INDEX .................................................................................................................................. 99 DROP ROLE .................................................................................................................................. 100 DROP SCHEMA ............................................................................................................................ 101 DROP SEQUENCE.........................................................................................................................102 DROP SYNONYM ......................................................................................................................... 104 DROP TABLE ................................................................................................................................ 105 DROP TYPE .................................................................................................................................. 106 DROP USER .................................................................................................................................. 107 DROP VIEW.................................................................................................................................. 108 EXPLAIN PLAN ............................................................................................................................. 109 EXPORT........................................................................................................................................ 114 GRANT .........................................................................................................................................115 IMPORT .......................................................................................................................................120 IMPORT FROM ............................................................................................................................ 121 INSERT .........................................................................................................................................123 LOAD ........................................................................................................................................... 124 MERGE DELTA ............................................................................................................................. 125 RENAME COLUMN ...................................................................................................................... 126 RENAME INDEX ........................................................................................................................... 127 RENAME TABLE ........................................................................................................................... 128 REVOKE ....................................................................................................................................... 129 SELECT .........................................................................................................................................130 SET [SESSION] .............................................................................................................................. 141 SET HISTORY SESSION TO ............................................................................................................ 142 SET SCHEMA ................................................................................................................................ 143 SET TRANSACTION AUTOCOMMIT DDL ..................................................................................... 144 SET TRANSACTION ...................................................................................................................... 145 TRUNCATE TABLE ........................................................................................................................ 147 7 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
8/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual UNLOAD ......................................................................................................................................148 UNSET [SESSION].........................................................................................................................149 UPDATE .......................................................................................................................................150 UPSERT| REPLACE ....................................................................................................................... 151 Appendix ............................................................................................................................................. 152 Restrictions for SQL Statements ..................................................................................................... 152 SQL Error Codes .............................................................................................................................. 153
8 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
9/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA 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 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
Notation This reference use BNF (Backus Naur Form) which is the notation technique used to define programming languages, to describe SQL. BNF describes the syntax of a grammar using a set of production rules using a set of symbols. Symbols used in BNF Symbol
Description
<>
Angle brackets are used to surround the name of a syntactic element (BNF nonterminal) of the SQL language.
::=
The definition operator is used to provide definitions of the element appeared on the left side of the operator in a production rule.
[]
Square brackets are used to indicate optional elements in a formula. Optional elements may be specified or omitted.
{}
Braces group elements in a formula. Repetitive elements (zero or more elements) can be specified within brace symbols.
|
The alternative operator indicates that the portion of the formula following the bar is an alternative to the portion preceding the bar.
...
The ellipsis indicates that the element may be repeated any number of times. If ellipsis appears after grouped elements specifying that the grouped elements enclosed with braces are repeated. If ellipsis appears after a single element, only that element is repeated.
!!
Introduces normal English text. This is used when the definition of a syntactic element is not expressed in BNF.
9 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
10/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Introduction This chapter describes the SAP HANA Database implementation of Structured Query Language (SQL). It explains the characteristics of SQL, also how to manage comments and reserve words.
SQL SQL stands for Structured Query Language. It is a standardized language for communicating with a relational database. It is used to retrieve, store or manipulate information in the database. SAP HANA Database manages tables using SQL statements to create or modify a table and to add or manipulate data within a table. SQL statements can perform the following tasks:
Schema definition and manipulation Data manipulation System management Session management Transaction management
Supported Languages and Code Pages The SAP HANA Database supports Unicode to allow use of all languages in the Unicode Standard and 7 Bit ASCII code page without restriction.
Comment You can add comments to improve readability and maintainability of your SQL statements. Comments are delimited in SQL statements as follows: Double hyphens ―—―. Everything after the double hyphen until the end of a line is considered by the SQL parser to be a comment "/*" and "*/". This style of commenting is used to place comments on multiple lines. All text between the opening "/*" and closing "*/" is ignored by the SQL parser.
Identifiers Syntax:
::= | ::= [{|}, ...] ::= A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S |T|U|V|W |X|Y|Z|a |b|c|d|e |f|g|h|i| j|k|l|m |n|o|p|q|r|s|t|u|v|w|x|y|z digit < > ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
::= | ::= _ ::= " ::= any character Identifiers are used to represent names used in SQL statement including table name, view name, synonym name, column name, index name, function name, procedure name, user name, role name, and so on. There are two kinds of identifiers; undelimited identifiers and delimited identifiers.
Undelimited table and column names must start with a letter and cannot contain any symbols other than digits or an underscore "_". Delimited identifiers are enclosed in the delimiter, double quotes, then the identifier can
contain any character including special characters. For example, ―AB$%CD‖ is a valid identifier name. Limitations
10 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
11/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual o o o
"_SYS_" is reserved exclusively for database engine, hence not allowed at the beginning of schema object names. Role name and user name must be specified as undelimited identifiers. Maximum length for the identifiers is 127 characters.
Single Quotation Mark Single quotation marks are used to delimit string literals and single quotation mark itself can be represented using two single quotation marks.
11 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
12/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Double Quotation Mark Double quotation marks are used to delimit identifiers and double quotation mark itself can be represented using two double quotation marks.
SQL Reserved Words Reserved words are words which have a special meaning to the SQL parser in the SAP HANA Database that cannot be used as a user-defined name. Reserved words should not be used in SQL statements for schema object names. If necessary, you can work around this limitation by delimiting a table or column name with double quotation marks. The following table lists all the current and future reserved words for the SAP HANA Database. Table 1. Reserved Words ALL
ALTER
AS
BEFORE
BEGIN
BOTH
CASE
CHAR
CONDITION
CONNECT
CROSS
CUBE
CURRENT_CONNECTION CURRENT_TIMESTAMP CURRENT_UTCTIMESTAMP DISTINCT END FOR HAVING INOUT JOIN
CURRENT_DATE CURRENT_USER CURRVAL ELSE EXCEPT FROM IF INTERSECT LEADING
CURRENT_SCHEMA CURRENT_UTCDATE CURSOR ELSEIF EXCEPTION FULL IN INTO LEFT
CURRENT_TIME CURRENT_UTCTIME DECLARE ELSIF EXEC GROUP INNER IS LIMIT
LOOP NULL PRIOR RIGHT SET SYSTIME TRAILING UTCTIME WHERE
MINUS ON RETURN ROLLUP SQL SYSTIMESTAMP UNION UTCTIMESTAMP WHILE
NATURAL ORDER RETURNS ROWID START SYSUUID USING VALUES WITH
NEXTVAL OUT REVERSE SELECT SYSDATE TOP UTCDATE WHEN
Undelimited table and column names must start with a letter and cannot contain any symbols other than digits or an underscore "_". If the identifier is enclosed in the delimiter, double quotes, then the identifier can contain any character including special characters. For example, ―AB$%CD‖ is a valid identifier name. However, "_SYS_" is reserved exclusively for database engine, hence not allowed at the beginning of schema object names.
12 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
13/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Data Types This section describes the data types used in the SAP HANA Database. Data type specifies the characteristics of a data value. A special value of NULL is included in every data type to indicate the absence of a value. The following table shows the built-in data types in SAP HANA Database.
Classification of Data Types In the SAP HANA Database each data type can be classified by its characteristic as follows: Table 2. Classification of data types Classification
Data Type
Datetime types
DATE, TIME, SECONDDATE, TIMESTAMP
Numeric types
TINYINT, SMALLINT, INTEGER, BIGINT, SMALLDECIMAL, DECIMAL, REAL, DOUBLE, FLOAT
Character string types
VARCHAR, NVARCHAR, ALPHANUM
Binary types
VARBINARY
Large Object types
BLOB, CLOB, NCLOB
Datetime Types DATE
The DATE data type consists of year, month, and day information to represent a date value. 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.
TIME
The TIME data type consists of hour, minute, and second to represent a time value. The default format for the TIME data type is 'HH24:MI:SS'. HH24 represents the hour from 0 to 24, MI represents the minute from 0 to 59, SS represents the second from 0 to 59.
SECONDDATE
The SECONDDATE data type consists of year, month, day, hour, minute and second information to represent a date with time value. The default format for the SECONDDATE data type is 'YYYY-MM-DD HH24:MI:SS'. YYYY represents the year, MM represents the month, DD represents the day, HH24 represents hour, MI represents minute, and SS represents seconds. The range of date value is 0001-01-01 00:00:01 through 9999-12-31 24:00:00.
TIMESTAMP
The TIMESTAMP data type consists of date and time information. Its default format is 'YYYYMM-DD HH24:MI:SS.FF7'. FFn represents the fractional seconds where n indicates the number of digits in fractional part. . The range of the timestamp value is 0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999. For details on supported formats for datetime types, refer to Table 4, Table 5, Table 6 and Table 7.
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. 13 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
14/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
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.
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.
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.
DECIMAL(precision, scale) or DEC(p,s)
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 digits from the decimal point to the least significant digit and can range from -6,111 to 6,176 which means scale specifies the range of the exponent in the decimal number from 10-6111 to 106176. If the scale is not specified, it defaults to 0. Scale is positive when the number has significant digits to the right of the decimal point and negative when the number has significant digits to the left of the decimal point. Examples: 0.0000001234 (1234 x 10-10) has the precision 4 and the scale 10. 1.0000001234 (10000001234 x 10-10) has the precision 11 and scale 10. 1234000000 (1234x106) has the precision 4 and scale -6. When precision and scale are not specified, DECIMAL becomes a floating-point decimal number. In this case, precision and scale can vary within the range described above, 1~34 for precision and -6,111~6,176 for scale depending on the stored value.
SMALLDECIMAL
The SMALLDECIMAL is a floating-point decimal number. The precision and scale can vary within the range, 1~16 for precision and -369~368 for scale depending on the stored value. SMALLDECIMAL is supported only on column store. DECIMAL and SMALLDECIMAL are floating-point types. For instance, a decimal column can store any of 3.14, 3.1415, 3.141592 keeping their precisions. DECIMAL(p, s) is the SQL standard notation for fixed-point decimal. For instance, 3.14, 3.1415, 3.141592 are stored in a decimal(5, 4) column as 3.1400, 3.1415, 3.1416, respectively keeping the specified precision(5) and scale(4).
REAL
The REAL data type specifies a single-precision 32-bit floating-point number.
DOUBLE
The DOUBLE data type specifies a single-precision 64-bit floating-point number. The minimum value is -1.79769 x 10 308 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.
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.
14 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
15/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual 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 greater 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.
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.
NVARCHAR
The NVARCHAR(n) data type specifies a variable-length Unicode character set string, where n indicates the maximum length and is an integer between 1 and 5000.
ALPHANUM The ALPHANUM(n) data type specifies a variable-length character string which contains alpha-numeric characters, where n indicates the maximum length and is an integer between 1 and 127.
Binary Types Binary types are used to store bytes of binary data.
VARBINARY
The VARBINARY(n) data type is used to store binary data of a specified maximum length in bytes, where n indicates the maximum length and is an integer between 1 and 5000.
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 2 GB.
BLOB
The BLOB data type is used to store large binary data.
CLOB
The CLOB data type is used to store large ASCII character data.
NCLOB
The NCLOB data type is used to store a large Unicode character object. LOB types are provided for storing and retrieving such large data. LOB types support the following operations. The length () function returns the LOB length in bytes. LIKE 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 predicate. LOB columns cannot appear in WHERE clauses as a predicate except LIKE, CONTAINS, =, or <>. LOB columns cannot appear in SELECT clauses as an aggregate function argument. LOB columns cannot appear in SELECT DISTINCT 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.
15 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
16/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
LOB columns cannot be used in CREATE INDEX statements. LOB columns cannot be used in statistics update statements.
Table 3: Mapping between SQL Data Type and Column Store Data Type
Integer Types Approximate Types
Decimal Types
Character Types
Binary Types Date/Time Types
SQL Type TINYINT, SMALLINT, INT
Column Store Type CS_INT
BIGINT
CS_FIXED(18,0)
REAL
CS_FLOAT
DOUBLE
CS_DOUBLE
FLOAT
CS_DOUBLE
FLOAT(p)
CS_FLOAT, CS_DOUBLE
DECIMAL
CS_DECIMAL_FLOAT
DECIMAL(p,s)
CS_FIXED(p-s,s)
SMALLDECIMAL
CS_SDFLOAT
VARCHAR
CS_STRING,CS_ALPHANUM,CS_UNITDECFLOAT, CS_DATE,CS_TIME
NVARCHAR
CS_STRING,CS_ALPHANUM,CS_UNITDECFLOAT
CLOB, NCLOB
CS_STRING
ALPHANUM
CS_ALPHANUM
BLOB
CS_RAW
VARBINARY
CS_RAW
DATE
CS_DAYDATE, CS_DATE
TIME
CS_SECONDTIME, CS_TIME
TIMESTAMP SECONDDATE
CS_LONGDATE, CS_DATE, CS_SECONDDATE CS_SECONDDATE
16 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
17/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Supported Formats for Date, Time and Timestamp The following date/time formats can be used when parsing a string into a date/time type and converting a date/time type value into a string value. Please note that format for Timestamp is the combination of Date and Time with the additional support for fractional seconds. Table 4: Supported formats for Date Format
Description
Examples
YYYY-MM-DD
Default format
INSERT INTO TBL VALUES ('1957-06-13');
YYYY/MM/DD
YYYY from 0001 to 9999, MM from 1 to 12, DD from 1 to 31.
INSERT INTO TBL VALUES ('1957-06-13'); INSERT INTO TBL VALUES ('1957/06/13');
YYYY/MM-DD YYYY-MM/DD
If year has less than four digits, month has less than two digits, or
INSERT INTO TBL VALUES ('1957/06-13');
day has less than two digits, then values will be padded by one or more zeros. For example, a two digit year 45 will be saved as year 0045, a one digit month 9 will be saved as 09, and a one digit day 2 will be saved as 02.
INSERT INTO TBL VALUES ('1957-06/13');
YYYYMMDD
ABAP Data Type, DATS format
INSERT INTO TBL VALUES ('19570613');
MON
Abbreviated name of month. (JAN. ~ DEC.)
INSERT INTO TBL VALUES (TO_DATE('2040Jan-10', 'YYYY-MON-DD')); INSERT INTO TBL VALUES (TO_DATE('Jan10', 'MON-DD'));
MONTH
Name of month. (JANUARY DECEMBER).
INSERT INTO TBL VALUES (TO_DATE('2040January-10', 'YYYY-MONTH-DD')); INSERT INTO TBL VALUES (TO_DATE('January-10', 'MONTH-DD'));
RM
Roman numeral month (I-XII; JAN = I).
INSERT INTO TBL VALUES (TO_DATE('2040I-10', 'YYYY-RM-DD')); INSERT INTO TBL VALUES (TO_DATE('I-10', 'RM-DD'));
DDD
Day of year (1-366).
INSERT INTO TBL VALUES (TO_DATE('204', 'DDD')); INSERT INTO TBL VALUES (TO_DATE( ‗2001204‘ ,‘ YYYY-DDD‘ ));
17 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
18/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Table 5: Supported formats for Time Format
Description
HH24:MI:SS
Default format
HH:MI[:SS][AM|PM]
HH from 0 to 23. MI from 0 to 59. SS from 0 to 59. FFF from 0 to 999.
INSERT INTO TBL VALUES ('23:59:59');
If one digit hour, minute, second is specified, then 0 will be inserted into the value. For example, 9:9:9 will be saved as 09:09:09.
INSERT INTO TBL VALUES ('3:47:39 AM');
HH12:MI[:SS][AM|PM ] HH24:MI[:SS]
Examples
HH12 indicates 12 hour clock and HH24 indicates 24 hour clock. AM or PM can be specified as a suffix to indicate the time value is before or after noon. SSSSS
Seconds past midnight (0-86399).
INSERT INTO TBL VALUES ('9:9:9 AM'); INSERT INTO TBL VALUES (TO_TIME('11:59:59','HH1 2:MI:SS');
INSERT INTO TBL VALUES (TO_TIME('12345', 'SSSSS'));
Table 6: Supported formats for Timestamp Format
Description
YYYY-MM-DD HH24:MI:SS.FF7
Default format
FF [1..7]
Fractional seconds has the range 1 to 7 after the FF parameter to specify the number of digits in the fractional second portion of the date time value returned.
Examples
INSERT INTO TBL VALUES (TO_TIMESTAMP('2011-05-11 12:59.999','YYYY-MM-DD HH:SS.FF3'));
If a digit is not specified, the default value is used.
The following date/time formats can additionally be used when converting a date/time type value into a string value. The following functions can be used when selecting a date/time values with a specific format. Table 7: Additional date/time formats Format
Description
Example
D
Day of week (1-7).
TO_CHAR(CURRENT_TIMESTAMP,‘ D‘ )
DAY
Name of day (MONDAY - SUNDAY).
TO_CHAR(CURRENT_TIMESTAMP,‘ DAY‘ )
DY
Abbreviated name of day (MON - SUN).
TO_CHAR(CURRENT_TIMESTAMP,‘ DY‘ )
18 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
19/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Format
Description
Example
MON
Abbreviated month name (JAN - DEC)
TO_CHAR(CURRENT_TIMESTAMP,‘ MON‘ )
MONTH
Full month name (JANUARY - DECEMBER)
TO_CHAR(CURRENT_TIMESTAMP,‘ MONTH‘ )
RM
Roman numeral month (I – XII; I is for January)
TO_CHAR(CURRENT_TIMESTAMP,‘ RM‘ )
Q
Quarter of year (1, 2, 3, 4)
TO_CHAR(CURRENT_TIMESTAMP,‘ Q‘ )
W
Week of month (1-5).
TO_CHAR(CURRENT_TIMESTAMP,‘ W‘ )
WW
Week of year (1-53).
TO_CHAR(CURRENT_TIMESTAMP,‘ WW‘ )
Data Type Conversion This section describes the data type conversion allowed in SAP HANA Database.
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, TO_ALPHANUM, TO_BIGINT, TO_VARBINARY, TO_BLOB, TO_CLOB, TO_DATE, TO_DATS, TO_DECIMAL, TO_DOUBLE, TO_INTEGER, TO_INT, TO_NCLOB, TO_NVARCHAR, TO_REAL, TO_SECONDDATE, TO_SMALLINT, TO_TINYINT, TO_TIME, TO_TIMESTAMP, TO_VARCHAR.
Implicit type conversion
When a given set of operand/argument types does not match what an operator/function expects, type conversion is carried out by the SAP HANA Database. This conversion only occurs if a relevant 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
Table 8. Implicit Type conversion Examples Input Expression
Transformed Expression with Implicit Conversion
BIGINT > VARCHAR BIGINT > BIGINT(VARCHAR) BIGINT > DECIMAL
DECIMAL(BIGINT) > DECIMAL
TIMESTAMP > DATE TIMESTAMP > TIMESTAMP(DATE) DATE > TIME
Error because there is no conversion available between DATE and TIME
In the table below, Boxes with ―OK‖ mean data type conversions are allowed without any checks.
19 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
20/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Boxes with ―CK‖ mean the data type can be converted if the data is valid for the target type. Boxes with ―- ― 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 9. Data type conversion table ti m
s
in
b
t
in
e
t
n
Target in
a ll t
d
d im
im
ig te
y
g r
s
re m
e
e c
a
a
d a
l
e l( ,s )
n
b h
rc
a v rc le
c p
v a
u l
ll
d o a
c
in
im
a
h r a r
a l
Source OK
OK OK
OK OK
OK OK
OK OK
OK OK
OK OK
OK OK
OK OK
OK OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
CK
CK
CK
OK
OK
OK
CK
CK
CK
OK
OK
OK
CK
Ck
CK
CK
CK
OK
OK
CK
OK
CK
CK
CK
OK
OK
CK
CK
OK
CK
CK
OK
OK
OK
CK
CK
CK
CK
CK
CK
CK
OK
OK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
CK
tinyint smallint
CK
integer
CK
CK
bigint
CK
CK
CK
decimal
CK
CK
CK
CK
decimal(p,s)
CK
CK
CK
CK
smalldecimal
CK
CK
CK
real
CK
CK
double
CK
varchar nvarchar
OK CK
Target Source
time
time
date
seconddate
timestamp
varchar
nvarchar
-
-
-
OK
OK
OK
OK
OK
OK
timestamp
OK
OK
OK
OK OK
date
-
seconddate
time
date
timestamp varchar
time CK
date CK
seconddate CK
CK
nvarchar
CK
CK
CK
CK
CK
Target Source
varbinary
varbinary
alphanum
varchar
nvarchar
-
-
-
OK
OK
alphanum
-
varchar
OK
OK
nvarchar
OK
OK
OK CK
20 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
21/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Data Type Precedence
This section describes the data type precedence provided by SAP HANA Database. Data type precedence specifies that the data type with lower precedence is converted to the data type with higher precedence.
Highest
TIMESTAMP SECONDDATE DATE TIME DOUBLE REAL DECIMAL SMALLDECIMAL BIGINT INTEGER SMALLINT TINYINT NCLOB NVARCHAR CLOB VARCHAR BLOB
Lowest
VARBINARY
21 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
22/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Predicates A predicate is specified by combining one or more expressions or logical operators and returns one of the following logical or truth values: TRUE, FALSE, or UNKNOWN.
Comparison Predicates Two values can be compared using comparison predicates and returns true, false, or unknown. Syntax: ::= { = | != | <> | > | < | >= | <= } [ ANY | SOME| ALL ] { | } ::= , ...
Expressions can be a simple expression such as a character, date, or number. An expression can also be a scalar subquery. ANY, SOME – When ANY or SOME is specified, a comparison returns true if at least one value returned by subquery or expression_list is true. ALL - When ALL is specified, a comparison returns true if the comparison for all values returned by subquery or expression_list is true.
Range Predicate A value can be compared with the list of values within the provided range. Syntax: ::= [NOT] BETWEEN AND
BETWEEN … AND … – When a range predicate is used, it returns true if expression1 is within the range specified by expression2 and expression3. A true will only be returned if expression2 has a lesser value than expression3.
In Predicate A value can be compared with a specified set of values. True will be returned if the value of expression1 is found in the expression_list (or subquery). Syntax: ::= [NOT] IN { | }
Exists Predicate Returns true if the subquery returns a result set that is not empty and returns false if the subquery returns an empty result set. Syntax: ::= [NOT] EXISTS ( )
LIKE Predicate The LIKE predicate is used for string comparisons. A value, expression1, is tested for a pattern, expression2. characters ( %pattern ) and (specified _ ) may be in the comparison expression2. Wildcard LIKE returns true if the by used expression2 is found. string
22 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
23/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual The percentage sign (%) matches zero or more characters and underscore (_) matches exactly one character. To match a percent sign or underscore in the LIKE predicate, an escape character must be used. Using the optional argument, ESCAPE expression3, you can specify the escape character that will be used so that the underscore (_) or percentage sign (%) can be matched. Syntax: ::= [NOT] LIKE [ESCAPE ]
NULL Predicate When IS NULL predicate is specified, a value can be compared with NULL and returns true if a value is NULL. If the IS NOT NULL predicate is specified, it returns true if a value is not NULL. Syntax: ::= IS [NOT] NULL
23 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
24/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Operators You can perform arithmetic operations in expressions by using operators. Operators can be used for calculation, value comparison or to assign values.
Unary Binary Operators Table 10.and 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
operand1 operator operand2
Binary
unary negation operator(-) logical negation(NOT)
operands or two value expressions.
multiplicative operators ( *, / ) additive operators ( +,- ) comparison operators ( =,!=,<,>,<=,>=) logical operators ( AND, OR )
Operator Precedence An expression can use several operators, if the number of operators is greater than one, then the SAP HANA Database will evaluate them in order of operator precedence. You can change this ordering by using parentheses. The SAP HANA Database will always evaluate expressions contained within parentheses first. If parentheses are not used, the operators have the precedence indicated by the table below. Please note, the SAP HANA Database will evaluate operators with equal precedence from left to right within an expression.
Table 11. SQL operator precedence Precedence
Operator
Operation
Highest
()
parentheses
+, -
unary positive and negative operation
*, /
multiplication, division
+, -
addition, subtraction
||
concatenation
=, !=, <, >, <=, >=, IS NULL, LIKE, BETWEEN
comparison
NOT
logical negation
AND
conjunction
24 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
25/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Precedence
Operator
Operation
Lowest
OR
disjunction
Arithmetic Operators You use arithmetic operators to perform mathematical operations such as adding, subtracting, multiplying, dividing and negation of numeric values. Table 12. Arithmetic operators Operator
Description
-
Negation. If the expression is the NULL value, the result is NULL.
+ Addition. If either expression is the NULL value, the result is NULL. -
Subtraction. If either expression is the NULL value, the result is NULL.
*
Multiplication. If either expression is NULL, the result is NULL.
/
Division. If either expression is NULL or if the second expression is 0, an error is returned.
String Operator A concatenation operator combines two items such as strings, expressions, or constants into one. Table 13. Concatenation operators Operator
Description
||
String concatenation (two vertical bars). If either string is NULL, it returns NULL.
Two string concatenation results in another string. For VARCHAR or NVARCHAR type strings, leading or trailing spaces are kept. If either string is of data type NVARCHAR, the result has data type NVARCHAR and is limited to 5000 characters. The maximum length for VARCHAR concatenation is also limited to 5000 characters.
Comparison Operators Syntax: ::=
Table 14. Comparison operators Operator
Description
Example
=
Equal to
SELECT * FROM students WHERE id = 25;
>
Greater than
SELECT * FROM students WHERE id > 25;
<
Less than
SELECT * FROM students WHERE id < 25;
25 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
26/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Operator
Description
Example
>=
Greater than or equal to
SELECT * FROM students WHERE id >= 25;
<=
Less than or equal to
SELECT * FROM students WHERE id <= 25;
!=, <>
Not equal
SELECT * FROM students WHERE id != 25; SELECT * FROM students WHERE id <> 25;
Logical Operators Search conditions can be combined using AND or OR operators. You can also negate them using the NOT operator. Table 15. Logical operators Operator
syntax
Notes
AND
WHERE condition1 AND condition2
OR
WHERE condition1 OR condition2
NOT
WHERE NOT condition
When using AND, the combined condition is TRUE if both conditions are TRUE, FALSE if either condition is FALSE, and UNKNOWN otherwise. When using OR, the combined condition is TRUE if either condition is TRUE, FALSE if both conditions are FALSE, and UNKNOWN otherwise. The NOT operator is placed before a condition to negate the condition. The NOT condition is TRUE if condition is FALSE, FALSE if condition is TRUE, and UNKNOWN if condition is UNKNOWN.
Set Operators The operators described in this section perform set operations on the results of two or more queries. Table 16. Set operators Operator
Returned Value
UNION
Combines the results of two or more select statements or query expressions
UNION ALL
Combines the results of two or more select statements or query expressions, including all duplicate rows.
INTERSECT
Combines the results of two or more select statements or query expressions, and returns all common rows.
EXCEPT
Takes output from the first query and then removes rows selected by the second query.
26 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
27/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Expressions An expression is a clause that can be evaluated to return values.
Syntax: expression ::=
| | | ( ) | ( ) | - | | | | [.]
Case Expressions A case expression allows the user to use IF ... THEN ... ELSE logic without using procedures in SQL statements. Syntax: case_expression ::=
CASE WHEN THEN , ... [ ELSE ] { END | END CASE }
If the expression following the CASE statement is equal to the expression following the WHEN statement, then the expression following the THEN statement is returned. Otherwise the expression following the ELSE statement is returned, if it exists.
27 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
28/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Function Expressions SQL built-in functions can be used as an expression. Syntax: ::= ( , ... )
Aggregate Expressions An aggregate expression uses an aggregate function to calculate a single value from the values of multiple rows in a column. Syntax: ::= COUNT(*) | ( [ ALL | DISTINCT ] ) ::= COUNT | MIN | MAX | SUM | AVG | STDDEV | VAR
Aggregate name
Description
COUNT
Counts the number of rows returned by a query. COUNT(*) returns the number of rows, regardless of the value of those rows and including duplicate values.COUNT() returns the number of non-NULL values for that expression returned by the query.
MIN
Returns the minimum value of expression.
MAX
Returns the maximum value of expression.
SUM
Returns the sum of expression.
AVG
Returns the arithmetical mean of expression.
STDDEV
Returns the standard deviation of given expression as the square root of VARIANCE function.
VAR
Returns the variance of expression as the square of standard deviation.
28 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
29/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Subqueries in expressions A subquery is a SELECT statement enclosed in parentheses. The SELECT statement can contain one and only one select list item. When used as an expression, a scalar subquery is allowed to return only zero or one value. Syntax: ::= ()
Within the SELECT list of the top level SELECT, or in the SET clause of an UPDATE statement, you can use a scalar subquery anywhere that you can use a column name. However, scalar_subquery cannot be used inside GROUP BY clause. Example: For example, the following statement returns the number of employees in each department, grouped by department name: SELECT DepartmentName, COUNT(*), ‗out of‘, (SELECT COUNT(*) FROM Employees) FROM Departments AS D, Employees AS E WHERE D.DepartmentID = E.DepartmentID GROUP BY DepartmentName;
29 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
30/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Functions Functions are used to return information from the database. They are allowed anywhere an expression is allowed. Functions use the same syntax conventions used by SQL statements.
Data type conversion functions Data type conversion functions are used to convert arguments from one data type to another, or to test whether they can be converted.
CAST Function Syntax: CAST (expression AS data_type) Description: Returns the value of an expression converted to a supplied data type. Parameters: expression - The expression to be converted. data type - The target data type.
TINYINT | SMALLINT | INTEGER | BIGINT | DECIMAL | SMALLDECIMAL | REAL | DOUBLE | ALPHANUM | VARCHAR | NVARCHAR | DAYDATE | DATE | TIME | SECONDDATE | TIMESTAMP Example: SELECT CAST (7 AS VARCHAR) "cast" FROM DUMMY;
Retrieves:
cast 7
TO_ALPHANUM Function Syntax: TO_ALPHANUM (expression) Description: Converts the expression of a data type into a value of alphanum data type. Example: SELECT TO_ALPHANUM ('10') "to alphanum" FROM DUMMY;
Retrieves:
to alphanum 10
TO_BIGINT Function Syntax: TO_BIGINT (expression) Description: Converts the expression of a data type into a value of bigint data type. Example: SELECT TO_BIGINT ('10') "to bigint" FROM DUMMY;
Retrieves:
to bigint 10
30 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
31/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual TO_BLOB Function Syntax: TO_BLOB (expression) Description:
Converts the expression of a data type into a value of blob type. expression must be a binary string. Example: SELECT TO_BLOB (TO_BINARY('abcde')) "to blob" FROM DUMMY;
Retrieves:
to blob abcde
TO_CLOB Function Syntax: TO_CLOB (expression) Description: Converts the expression 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 DUMMY;
Retrieves:
to clob TO_CLOB converts an expression into a value of CLOB data type
TO_DATE Function Syntax: TO_DATE (expression [, format]) Description: Converts the expression of a data type into a value of DATE data type. Example: SELECT TO_DATE('2010-01-12', 'YYYY-MM-DD') "to date" FROM DUMMY; Retrieves:
to date 2010-01-12
TO_DATS Function Syntax: TO_DATS (expression) Description: Converts the expression of a data type into a value of ABAP DATE string with format ‗YYYYMMDD‘ . Example: SELECT TO_DATS ('2010-01-12') "abap date" FROM DUMMY;
Retrieves:
abap date 20100112
TO_DECIMAL Function
31 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
32/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Syntax: TO_DECIMAL (expression [, precision, scale]) Description: Converts the expression of a data type into a value of DECIMAL ( precision, scale) data type. Example: SELECT TO_DECIMAL(7654321.89, 9, 2) "to decimal" FROM DUMMY;
Retrieves:
to decimal 7654321.89
TO_DOUBLE Function Syntax: TO_DOUBLE (expression) Description:
Converts the expression of a data type into a value of DOUBLE (double precision) data type. Example: SELECT 3*TO_DOUBLE ('15.12') "to double" FROM DUMMY;
Retrieves:
to double 45.36
TO_INT Function Syntax: TO_INT (expression) Description: Converts the expression of a data type into a value of INTEGER data type. Example: SELECT TO_INT('10') "to int" FROM DUMMY;
Retrieves:
to int 10
TO_INTEGER Function Syntax:
TO_INTEGER (expression) Description: Converts the expression of a data type into a value of INTEGER data type. Example: SELECT TO_INTEGER ('10') "to int" FROM DUMMY;
Retrieves:
to int 10
TO_NCLOB Function Syntax:
32 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
33/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual TO_NCLOB (expression) Description: Converts the expression 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 DUMMY;
Retrieves:
to nclob TO_NCLOB converts an expression into a value of NCLOB data type
TO_NVARCHAR Function Syntax: TO_NVARCHAR (expression [,format]) Description:
Converts the expression of a data type into a value of unicode character data type. If format is omitted, it converts to the corresponding format using the date format model. Example: SELECT TO_NVARCHAR(TO_DATE('2009/12/31'), 'YY-MM-DD') "to nchar" FROM DUMMY;
Retrieves:
to nchar 09-12-31
TO_REAL Function Syntax: TO_REAL (expression) Description: Converts the expression of a data type into the value of REAL (single precision) data type. Example: SELECT 3*TO_REAL ('15.12') "to real" FROM DUMMY;
Retrieves:
to real 45.36
TO_SMALLINT Function Syntax: TO_SMALLINT (expression) Description: Converts the expression of a data type into a value of SMALLINT data type. Example: SELECT TO_SMALLINT ('10') "to smallint" FROM DUMMY;
Retrieves:
to smallint 10
33 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
34/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual TO_TINYINT Function Syntax: TO_TINYINT (expression) Description:
Converts the expression of a data type into a value of TINYINT data type. Example: SELECT TO_TINYINT ('10') "to tinyint" FROM DUMMY;
Retrieves:
to tinyint 10
TO_TIME Function Syntax: TO_TIME (expression [, format]) Description: Converts the expression of a data type into a value of TIME data type. If format is omitted, it converts expression into the corresponding format using the date format model as explained in Table 5. Example: SELECT TO_TIME ('08:30 AM', ‗HH:MI AM‘ ) "to time" FROM DUMMY;
Retrieves:
to time 08:30:00
TO_TIMESTAMP Function Syntax: TO_TIMESTAMP (expression [, format]) Description: Converts the expression of a data type into the TIMESTAMP data type.
If format is omitted, it converts expression into the corresponding format using the date format model as explained in Table 5. Example: SELECT TO_TIMESTAMP ('2010-01-11 13:30:00', 'YYYY-MM-DD HH24:MI:SS') "to timestamp" FROM DUMMY;
Retrieves:
to timestamp 2010-01-11 13:30:00.0000000
TO_VARCHAR Function Syntax: TO_VARCHAR (expression [, format]) Description: Converts the expression of a data type into a value of character data type. Example: SELECT TO_VARCHAR (TO_DATE('2009-12-31'), 'YYYY/MM/DD') "to char" FROM DUMMY;
34 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
35/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Retrieves:
to char 2009/12/31
35 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
36/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
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 DUMMY;
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 DUMMY;
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 DUMMY;
Retrieves:
add years 2010-12-05
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 DUMMY;
Retrieves:
add seconds 00:00:45.000
36 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
37/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual 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 DUMMY;
Retrieves:
days between 31
DAYNAME Function Syntax: DAYNAME (expression) Description: Returns the name of the weekday in English. Example: SELECT DAYNAME ('2011-05-30') "dayname" FROM DUMMY;
Retrieves:
dayname MONDAY
DAYOFMONTH Function Syntax: DAYOFMONTH (expression) Description: Returns the day of the month in integer. Example: SELECT DAYOFMONTH ('2011-05-30') "dayofmonth" FROM DUMMY;
Retrieves:
dayofmonth 30
DAYOFYEAR Function Syntax: DAYOFYEAR (expression) Description: Returns the day of the year in integer. Example: SELECT DAYOFYEAR ('2011-05-30') "dayofyear" FROM DUMMY;
Retrieves:
dayofyear 150
37 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
38/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual EXTRACT Function Syntax: EXTRACT ({YEAR | MONTH | DAY | HOUR | MINUTE | SECOND} FROM datetime_value) Description:
Finds and returns the value of a specified datetime field from a datetime_value. Example: SELECT EXTRACT (YEAR FROM TO_DATE ('2010-01-04', 'YYYY-MM-DD')) "extract" FROM DUMMY;
Retrieves:
extract 2010
HOUR Function Syntax: HOUR (expression) Description: Extract hour from expression. Example: SELECT HOUR ('12:34:56‘ ) "hour" FROM DUMMY;
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 DUMMY;
Retrieves:
last day 2010-01-31
MINUTE Function Syntax: MINUTE (expression) Description: Extract minute from expression. Example: SELECT MINUTE ('12:34:56‘ ) "minute" FROM DUMMY;
Retrieves:
minute 34
MONTH Function
38 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
39/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Syntax: MONTH(expression) Description: Returns the number of the month from a given date. Example: SELECT MONTH ('2011-05-30‘ ) "month" FROM DUMMY;
Retrieves:
month 5
MONTHNAME Function Syntax: MONTHNAME(expression) Description:
Returns the name of the month in English. Example: SELECT MONTHNAME ('2011-05-30‘ ) "monthname" FROM DUMMY;
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 DUMMY;
Retrieves:
next day 2010-01-01
NOW Function Syntax:
NOW () Description: Returns the current timestamp. Example: SELECT NOW () "now" FROM DUMMY;
Retrieves:
now 2010-01-01 16:34:19
39 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
40/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual SECOND Function Syntax: SECOND (t)
Description: Returns the second number of a given time t . Example: SELECT SECOND (‘12:34:56‘ ) "second" FROM DUMMY;
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 DUMMY;
Retrieves:
Seconds between 2678400
CURRENT_DATE Function Syntax: CURRENT_DATE Description: Returns the current local system date. Example: SELECT CURRENT_DATE "current date" FROM DUMMY;
Retrieves:
current date 2010-01-11
CURRENT_TIME Function Syntax: CURRENT_TIME Description: Returns the current local system time. Example: SELECT CURRENT_TIME "current time" FROM DUMMY;
Retrieves:
current time 17:37:37.279
40 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
41/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual CURRENT_TIMESTAMP Function Syntax: CURRENT_TIMESTAMP Description:
Returns the current local system timestamp information. Example: SELECT CURRENT_TIMESTAMP "current timestamp" FROM DUMMY;
Retrieves: current timestamp
2010-01-11 17:38:48.802
CURRENT_UTCDATE Function Syntax:
CURRENT_UTCDATE Description: Returns the current UTC date. The UTC stands for Coordinated Universal Time, also known as Greenwich Mean Time (GMT). Example: SELECT CURRENT_UTCDATE "Coordinated Universal Date" FROM DUMMY;
Retrieves:
Coordinated Universal Time 2010-01-11
CURRENT_UTCTIME Function Syntax:
CURRENT_UTCTIME Description: Returns the current UTC time. Example: SELECT CURRENT_UTCTIME "Coordinated Universal Time" FROM DUMMY;
Retrieves:
Coordinated Universal Time 08:41:19.267
CURRENT_UTCTIMESTAMP Function Syntax: CURRENT_UTCTIMESTAMP Description: Returns the current UTC timestamp. Example: SELECT CURRENT_UTCTIMESTAMP "Coordinated Universal Timestamp" FROM DUMMY;
Retrieves:
Coordinated Universal Timestamp 2010-01-11 08:41:42.484
41 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
42/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual 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 DUMMY;
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 DUMMY;
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 DUMMY;
Retrieves:
year 2011
42 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
43/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA 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: Returns the absolute value of a numeric expression n. Example: SELECT ABS (-1) "absolute" FROM DUMMY; Retrieves:
absolute 1
ACOS Function Syntax: ACOS (n) Description: Returns the arc-cosine, in radians, of a numeric expression n between -1 and 1. Example: SELECT ACOS (0.5) "acos" FROM DUMMY;
Retrieves:
acos 1.0471975511965979
ASIN Function Syntax: ASIN (n) Description: Returns the arc-sine, in radians, of a number n between -1 and 1. Example: SELECT ASIN (0.5) "asin" FROM DUMMY;
Retrieves:
asin 0.5235987755982989
ATAN Function Syntax : ATAN (n) Description:
Returns the arc-tangent, in radians, of a number n. The argument is a number and the range of n is unlimited. Example:
43 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
44/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual SELECT ATAN (0.5) "atan" FROM DUMMY; Retrieves:
atan 0.4636476090008061
ATAN2 Function Syntax : ATAN2 (n, m) Description: Returns the arc-tangent, in radians, of the ratio of two numbers n and m. This is the same result as ATAN(n/m).
Example: SELECT ATAN2 (1.0, 2.0) "atan2" FROM DUMMY;
Retrieves:
atan2 0.4636476090008061
BITAND Function Syntax: BITAND (expression1, expression2) Description:
Calculates an AND operation on the bits of expression1 and expression2 . Both expression1 and expression2 must be non-negative integers. The BITAND function returns a result with BIGINT type. Example: SELECT BITAND (255, 123) "bitand" FROM DUMMY;
Retrieves:
bitand 123
CEIL / CEILING Function Syntax : CEIL (n) Description:
Returns the first integer that is greater or equal to a given value n. For positive numbers, this is known as rounding up. Example: SELECT CEIL (14.5) "ceiling" FROM DUMMY;
Retrieves:
ceiling 15
COS Function Syntax:
COS (n) Description:
44 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
45/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Returns the cosine of the angle in radians given by its argument n. Example: SELECT COS (0.0) "cos" FROM DUMMY;
Retrieves:
cos 1.0
COSH Function Syntax: COSH (n) Description: Computes the hyperbolic cosine of n. Example: SELECT COSH (0.5) "cosh" FROM DUMMY;
Retrieves:
cosh 1.1276259652063807
COT Function Syntax: COT (n) Description: Computes the cotangent of n. Example: SELECT COT (40) "cot" FROM DUMMY;
Retrieves:
Cot 1.5423510453569202
EXP Function Syntax: EXP (n) Description: Returns the result of the base of natural logarithms e raised to the power of the given argument n. Example: SELECT EXP (1.0) "exp" FROM DUMMY;
Retrieves:
exp 2.718281828459045
FLOOR Function Syntax: FLOOR (n) Description:
Returns the largest integer not greater than the given number n. Example:
45 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
46/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual SELECT FLOOR (14.5) "floor" FROM DUMMY; 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 DUMMY;
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 DUMMY;
Retrieves:
least aa
LN Function Syntax: LN (n) Description: Returns the natural logarithm of the specified number. Example: SELECT LN (9) "ln" FROM DUMMY;
Retrieves:
ln 2.1972245773362196
LOG Function Syntax : LOG (m, n) Description: Returns the natural logarithm of n base m. 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 DUMMY;
46 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
47/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Retrieves:
log 0.30102999566398114
MOD Function Syntax: MOD (n, d) Description: Returns the remainder of a number n divided by a divisor d.
When n is negative this function acts differently dto the standard computational modulo operation. The following explains example of what MOD functions returns as the result. If d is zero, then this function returns n. If n is greater than 0 and n is less than d, then this function returns n. If n is less than 0 and n is greater than d, then this function returns n. Otherwise, this function calculates the remainder of the absolute value of n divided by the absolute value of d to calculate the absolute value of the remainder. If m is less than 0, then the returned remainder from MOD is a negative number, and if m is greater than 0, then the returned remainder from MOD is a positive number.
Example: SELECT MOD (15, 4) "modulus" FROM DUMMY;
Retrieves:
modulus 3
POWER Function Syntax:
POWER (b, e) Description: Calculates the base number b raised to the power of an exponent e.
Example: SELECT POWER (2, 10) "power" FROM DUMMY;
Retrieves:
power 1024.0
ROUND Function Syntax: ROUND (n [, pos]) Description: Rounds n to the specified pos amount of places after the decimal point.
Example: SELECT ROUND (16.16, 1) "round" FROM DUMMY;
Retrieves:
round 16.2 SELECT ROUND (16.16, -1) "round" FROM DUMMY;
47 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
48/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Retrieves:
round 20
SIGN Function Syntax: SIGN (n) Description:
Returns the sign (positive or negative) of the given number.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 DUMMY;
Retrieves:
sign -1
SIN Function Syntax: SIN (n) Description: Returns the sine of n, where the argument is an angle expressed in radians.
Example: SELECT SIN ( 3.141592653589793/2) "sine" FROM DUMMY;
Retrieves:
sine 1.0
SINH Function Syntax: SINH (n) Description: Returns the hyperbolic sine of n, where the argument is an angle expressed in radians. Example: SELECT SINH (0.0) "sinh" FROM DUMMY;
Retrieves:
sinh 0.0
SQRT Function Syntax: SQRT (n) Description: Returns the square root of a number n.
48 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
49/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Example: SELECT SQRT (2) "sqrt" FROM DUMMY;
Retrieves:
sqrt 1.4142135623730951
TAN Function Syntax: TAN (n) Description: Returns the tangent of an angle in radians.
Example: SELECT TAN (0.0) "tan" FROM DUMMY;
Retrieves:
tan 0.0
TANH Function Syntax: TANH (n) Description: Returns the hyperbolic tangent of a number n. Example: SELECT TANH (1.0) "tanh" FROM DUMMY;
Retrieves:
tanh 0.7615941559557649
49 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
50/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
String Functions ASCII Function Syntax: ASCII(c) Description: Returns the integer ASCII value of the first byte in a string c. Example: SELECT ASCII('Ant') "ascii" FROM DUMMY;
Retrieves:
ascii 65
CHAR Function Syntax: CHAR (n)
Description: Returns the character with the ASCII value of a number n. Example: SELECT CHAR (65) || CHAR (110) || CHAR (116) "character" FROM DUMMY;
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.
Example: SELECT CONCAT ('C', 'at') "concat" FROM DUMMY;
Retrieves:
concat Cat
LEFT Function Syntax: LEFT (str, n) Description: Returns n characters from the beginning of a string str. Example: SELECT LEFT ('Hello', 3) "left" FROM DUMMY;
Retrieves:
left
50 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
51/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Hel
LCASE Function Syntax: LCASE(s) Description: Converts all characters in a string s to lowercase. The LCASE function is identical to the LOWER function. Example: SELECT LCASE ('Test') "lcase‖ FROM DUMMY;
Retrieves:
lcase test
LENGTH Function Syntax: LENGTH(s) Description: Returns the number of characters in the specified string.s. For LOB types, it returns the length in bytes. Example: SELECT LENGTH ('length in char') "length" FROM DUMMY;
Retrieves:
length 14
LOCATE Function Syntax: LOCATE (haystack, needle)
Description: Returns the position of sub-string needle within string haystack. Returns 0 if needle is not found from haystack. Example: SELECT LOCATE ('length in char', ‗char‘ ) "locate" FROM DUMMY;
Retrieves:
Locate 11
LOWER Function Syntax LOWER(s)
Description Converts all characters in a string s to lowercase. The LOWER function is identical to the LCASE function.
51 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
52/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Example SELECT LOWER ('Ant') "lower" FROM DUMMY;
Retrieves:
lower ant
LPAD Function Syntax: LPAD (target, n [, pattern]) Description: Pad the left side of a target string with spaces or pattern to make the target n characters in length.. Example: SELECT LPAD ('end', 15, '12345') "lpad" FROM DUMMY;
Retrieves:
lpad 123451234512end
LTRIM Function Syntax: LTRIM (target [, remove_set]) Description: Removes from the leftmost of target all of the characters that appear in remove_set until reaching a character not in remove_set and then returns the result. If remove_set is not specified, a single blank space is used. Please note that remove_set is treated as a set of characters and not a search string. Example: SELECT LTRIM ('babababAabend','ab') "ltrim" FROM DUMMY;
Retrieves:
ltrim Aabend
NCHAR Function Syntax: NCHAR (n) Description:
This function returns the Unicode character with the specified integer code number n. Example: SELECT NCHAR (65) "nchar" FROM DUMMY;
Retrieves:
nchar A
REPLACE Function Syntax: REPLACE (original_string, search_string, replace_string) Description:
52 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
53/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Searches in original_string for all occurrences of search_string and replaces them with replace_string.
If original_string is an empty string, then the result will also be an empty string. If two overlapping substrings match the search_string in the original_string, then only the first occurrence will be replaced with the replace_string.
If original_string does not contain any occurrencesearch_string, of search_string, then the function returns the original_string unchanged. If original_string, or replace_string is NULL, then the function returns NULL.
Example: SELECT REPLACE ('DOWNGRADE DOWNWARD','DOWN', 'UP') "replace" FROM DUMMY;
Retrieves:
replace UPGRADE UPWARD
RIGHT Function Syntax:
RIGHT(target, n) Description: Returns the rightmost n characters of a string target. Example: SELECT RIGHT('HI0123456789', 3) "right" FROM DUMMY;
Retrieves:
right 789
RPAD Function Syntax: RPAD (target, n [, pattern]) Description: Pad the right side of a target string with spaces or pattern to make the target n characters in length. Example: SELECT RPAD ('end', 15, '12345') "right padded" FROM DUMMY;
Retrieves:
right padded end123451234512
RTRIM Function Syntax: RTRIM (target [,remove_set ]) Description: Removes from the rightmost of target all of the characters that appear in remove_set until reaching a character not in remove_set and then returns the result. If remove_set is not specified, a single blank space is used. Please note that remove_set is treated as a set of characters and not a search string.
Example: SELECT RTRIM ('endabAabbabab','ab') "rtrim" FROM DUMMY;
Retrieves:
rtrim
53 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
54/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual endabA
SUBSTRING Function Syntax: SUBSTRING (target, start_position [, string_length]) Description: Returns a substring of a string target starting from the start_position of the string. SUBSTRING can either return the remaining part of a string from the start_position or, optionally, a number of characters set by the string_length parameter.
If start_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.
Example: SELECT SUBSTRING ('1234567890',4,2) "substring" FROM DUMMY;
Retrieves:
substring 45
SUBSTR_AFTER Function Syntax: SUBSTR_AFTER (target, pattern) Description: Returns a substring of the target string that follows the first occurrence of the pattern argument in the target string.
If target does not contain a substring which is the same as pattern, then an empty string is returned. If pattern is an emptyNULL, string,then thenNULL target returned. If target or pattern is is is returned.
Example: SELECT SUBSTR_AFTER ('Hello My Friend','My ') "substr after" FROM DUMMY;
Retrieves:
substr after Friend
SUBSTR_BEFORE Function Syntax: SUBSTR_BEFORE (target, pattern) Description: Returns a substring of the target string before the first occurrence of the pattern argument in the target string. 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 DUMMY;
Retrieves:
substr Hello before
54 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
55/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual TRIM Function Syntax: TRIM ([[LEADING | TRAILING | BOTH] trim_char FROM] target_string ) Description:
Returns a string trim_char from target_string string. The trimming is carried out eitherafter fromtrimming the starta(LEADING), end (TRAILING) or both(BOTH) ends of operation the target_string. If either target_string or trim_char is a null value, then a NULL is returned. If no option is specified, it removes both the leading and trailing substring trim_char from target_string string. If trim_char is not specified, then a single blank space will be used.
Example: SELECT TRIM ( ‗a‘ FROM ‗aaa123456789aa‘ ) "trim both" FROM DUMMY;
Retrieves:
trim both 123456789 SELECT TRIM (LEADING ‘ a‘ FROM ‗aaa123456789aa‘ ) "trim leading" FROM DUMMY; Retrieves:
trim leading 123456789aa
UCASE Function Syntax: UCASE (target) Description:
Converts all characters in the target string to uppercase. Example: SELECT UCASE ('Ant') "ucase" FROM DUMMY;
Retrieves:
ucase ANT
UNICODE Function Syntax : UNICODE(c) Description: Returns an integer containing the Unicode code point of the first character in the string, or NULL if the first character is not a valid encoding. Example: SELECT UNICODE ('#') "unicode" FROM DUMMY;
Retrieves:
unicode 54620
UPPER Function Syntax: UPPER (target)
55 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
56/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Description: Converts all characters in the target string to uppercase. Example: SELECT UPPER ('Ant') "uppercase" FROM DUMMY;
Retrieves:
uppercase ANT
56 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
57/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
Miscellaneous Functions BINTOHEX Function Syntax: BINTOHEX (expression) Description: Returns the hexidecimal string of expression. Example: SELECT BINTOHEX('AB') "bintohex" FROM DUMMY;
Retrieves:
bintohex 4142
COALESCE Function Syntax : COALESCE (expression_list) Description: Returns the first non-NULL expression from a list. At least two expressions must be passed into the function, and all expressions must be comparable. The result will be NULL if all the arguments are NULL. Example: SELECT * FROM tab;
Retrieves:
ID
A
B
1 2 3
100.0 NULL NULL
80.0 63.0 NULL
SELECT id, a, b, COALESCE (a, b*1.1, 50.0) "coalesce" FROM tab; Retrieves:
ID
A
B
coalesce
1 2 3
100.0 NULL NULL
80.0 63.0 NULL
100 69.3 50
HASANYPRIVILEGES Function Syntax: HASANYPRIVILEGES (, , , [, ]) Description: Returns 1 in case the given user has any privilege on the specified object. is for example: TABLE, VIEW, PROCEDURE Users having system privilege DATA ADMIN or CATALOG READ are allowed to use this function with any user given as first parameter. Other users are only allowed to use their own user_name
as first parameter.
57 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
58/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Example: SELECT HASANYPRIVILEGES (CURRENT_USER, 12345, ‗MY_SCHEMA‘, ‗TABLE‘) HAS_PRIV FROM
DUMMY; Retrieves:
HAS_PRIV 1
HASSYSTEMPRIVILEGE Function Syntax: HASSYSTEMPRIVILEGE (, ) Description: Returns 1 if the given user has the specified systemprivilege. is ‗CATALOG READ‘ for example
DATA ADMIN or CATALOG READ – With DATA ADMIN or CATALOG READ privilege, users are allowed to check for all users. Normal users are only allowed to check for themselves, if they do have any privilege on that object. Example: SELECT HASSYSTEMPRIVILEGE (CURRENT_USER, 'INIFILE ADMIN') HAS_INI_ADMIN FROM DUMMY;
Retrieves:
HAS_INI_ADMIN 0
HEXTOBIN Function Syntax:
HEXTBIN (expression) Description: Returns the binary value of expression where expression is a hexadecimal value. Example: SELECT HEXTOBIN ('1a') "hextobin" FROM DUMMY;
Retrieves:
hextobin 1A
ISAUTHORIZED Function Syntax: ISAUTHORIZED (, , , , [, ]) Description: Returns 1 if the given user has the specified SQL-privilege on the specified object. is ‗SELECT‘ or ‗EXECUTE‘ for example. is for example: TABLE, VIEW, PROCEDURE
Example: SELECT ISAUTHORIZED (CURRENT_USER, ‗SELECT‘, ‗MY_SCHEMA‘, ‗MY_TABLE‘, ‗TABLE‘)
HAS_PRIV FROM DUMMY;
58 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
59/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Retrieves:
HAS_PRIV 1
IFNULL Function Syntax: IFNULL (expression1, expression2) Description: Returns expression1 if expression1 is not NULL and expression2 if expression1 is NULL. Example: SELECT IFNULL ('diff', 'same') "ifnull" FROM DUMMY;
Retrieves:
ifnull diff
NULLIF Function Syntax: NULLIF (expression1, expression2) Description: NULLIF compares the values of the two expressions. If the first expression equals the second expression, NULLIF returns NULL. If the first expression does not equal the second expression, or if the second expression is NULL, NULLIF returns the first expression. The NULLIF function provides a short way to write some CASE expressions. Example:
SELECT NULLIF ('diff', 'same') "nullif" FROM DUMMY; Retrieves:
nullif Diff SELECT NULLIF('same', 'same') "nullif" FROM DUMMY; Retrieves:
nullif NULL
CURRENT_CONNECTION Function Syntax: CURRENT_CONNECTION Description: Returns the current connection id. Example: SELECT CURRENT_CONNECTION "current connection" FROM DUMMY;
Retrieves:
current connection 2
59 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
60/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual CURRENT_SCHEMA Function Syntax: CURRENT_SCHEMA Description:
Returns the current schema name in the string. Example: SELECT CURRENT_SCHEMA "current schema" FROM DUMMY;
Retrieves:
current schema SYSTEM
CURRENT_USER Function Syntax: CURRENT_USER Description: Returns the current user name in the string. Example: SELECT CURRENT_USER "current user" FROM DUMMY;
Retrieves:
current user 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 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
61/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual Retrieves:
CUSTOMER YEAR
PRODUCT SUM(SALES)
GROUPING_ID(CUSTOMER,YEAR,PRODUCT)
1
C1
2009 P1
100
0
2
C1
2010 P1
50
0
3 4
C2 C2
2009 P1 2010 P1
200 100
0 0
5
C1
2009 P2
200
0
6
C1
2010 P2
150
0
7
C2
2009 P2
300
0
8
C2
2010 P2
150
0
9
C1
2009 ?
300
1
10
C1
2010 ?
200
1
11
C2
2009 ?
500
1
12
C2
2010 ?
250
1
13
C1
?
P1
150
2
14
C2
?
P1
300
2
15
C1
?
P2
350
2
16
C2
?
P2
450
2
17
?
2009 P1
300
4
18
?
2010 P1
150
4
19
?
2009 P2
500
4
20
?
2010 P2
300
4
21
C1
?
?
500
3
22 23
C2 ?
?
? 2009 ?
750 800
3 5
24
?
2010 ?
450
5
25
?
?
P1
450
6
26
?
?
P2
800
6
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 can be set when the session is created. Currently available read only session variables are ‗locale‘ , ‗locale_sap‘ , ‗client‘ , ‗conn_id‘ , ‗applicationname‘ , ‗clientuser‘ , ‗clienthostname‘ . Example: SELECT SESSION_CONTEXT(‗conn_Id‘ ) ―session context‖ FROM DUMMY;
Retrieves:
session context 4
61 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
62/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual SYSUUID Function Syntax: SYSUUID Description:
Returns the SYSUUID. Example: SELECT SYSUUID FROM DUMMY;
Retrieves:
SYSUUID 4DE3CD576C79511BE10000000A3C2220
62 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
63/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
SQL Statements This chapter describes the SQL statements that are supported by the SAP HANA Database.
ALTER AUDIT POLICY SQL Syntax: ALTER AUDIT POLICY
Parameters: :: = ::= ENABLE | DISABLE
Description: Enables or disables an audit policy. Information on AUDIT POLICY is available in the system view, PUBLIC.AUDIT_POLICIES.
63 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
64/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual ALTER SYSTEM SQL Syntax: ALTER SYSTEM Parameters: Parameters for ALTER SYSTEM: alter_system_options ::= ALTER CONFIGURATION (, ...) SET | UNSET < parameter _key_value_list> [ WITH RECONFIGURE] | ALTER SESSION SET | UNSET = | CANCEL [WORK IN] SESSION | CLEAR SQL PLAN CACHE | CLEAR TRACES () | DELETE ALL HANDLED EVENTS | DELETE HANDLED EVENT [] | DISCONNECT SESSION | LOGGING | RECLAIM DATAVOLUME [SPACE] | RECLAIM LOG [] | RECLAIM VERSION SPACE | RECONFIGURE SERVICE (, , ) | REMOVE TRACES (, ) | RESET MONITORING VIEW < view_name> | SAVE PERFTRACE [INTO FILE ] | SAVEPOINT | SET EVENT HANDLED [] | START PERFTRACE [] [PLAN_EXECUTION] [DURATION ] | STOP PERFTRACE | STOP SERVICE (,,) [IMMEDIATE [WITH COREFILE]]
Description: ALTER CONFIGURATION Sets or Removes configuration parameters in the ini file. Ini file configuration is used for the layered configuration for DEFAULT, SYSTEM, HOST layers. The following is an example of ini file locations: DEFAULT: /usr/sap//HDB/exe/config/indexserver.ini SYSTEM: /usr/sap//SYS/global/hdb/custom/config/indexserver.ini HOST: /usr/sap// HDB//indexserver.ini The priority of configuration is defined as DEFAULT < SYSTEM < HOST, meaning the priority of HOST 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 ini files are listed in M_INIFILES and current configuration is available in M_INIFILE_CONTENTS. Syntax Elements: ::=
64 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
65/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual {(,) = },… ::= ::= ::= Example syntax to change system layer configuration is as follows: ALTER SYSTEM ALTER CONFIGURATION ('filename', 'layer') SET ('section1', 'key1') = 'value1', ('section2', 'key2') = 'value2', ... [WITH RECONFIGURE]; ALTER SYSTEM ALTER CONFIGURATION ('filename', 'layer', 'layer_name' ) UNSET ('section1', 'key1'), ('section2'), ...[WITH RECONFIGURE];
'layer' can be 'SYSTEM' or 'HOST'. In case of HOST layer, 'layer_name' is either its target tenant name or target host name; for example, '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. 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. ALTER SESSION SET|UNSET You can set session variables of any session 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. ::= connection ID number ::= ::= There are several available read-only session variables and they are LOCALE, LOCALE_SAP, CLIENT, CONN_ID, APPLICATIONNAME, CLIENTUSER, and CLIENTHOSTNAME. CANCEL [WORK IN] SESSION Cancels the currently executed operation by the specified session, however, the session is not disconnected. CLEAR SQL PLAN CACHE Resets sql plan cache. It tries to remove all the plans that are not currently running. CLEAR|REMOVE TRACES
65 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
66/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual CLEAR TRACES clears trace contents from trace files and all files that were opened by a service will be removed or reset to size 0. On distributed system, the command will clear all traces on all hosts. :: = , … ::= It can clear different types of files: Name
Files
ALERT
alert ...trc
CLIENT
localclient_....trc
CRASHDUMP
*.crashdump....trc
*
open *.trc files of all active services
INDEXSERVER,NAMESERVER,...,DAEMON
open *.trc files of a single service type
REMOVE TRACES deletes the trace files on specified hosts. When a service has a trace file open, then it cannot be deleted, so ―CLEAR‖ command should be used in that case. The trace files can be monitored using M_TRACEFILES and trace file contents can be monitored using M_TRACEFILE_CONTENTS. DELETE ALL HANDLED EVENTS Delete all events with status ―HANDLED‖.
DELETE HANDLED EVENT Delete the event with given ID. ::= ( ‗:‘ ) | (, ) ::= ::= Port Number ::= event ID number
DISCONNECT SESSION Disconnects the specified session from the database. The specified session will be disconnected but the current operation will be continued until it is completed. LOGGING Logging is enabled or disabled. ::= ON | OFF
RECLAIM DATA VOLUME Reduces data volume size to a N% of payload size; it works like defragmenting a hard disk, pages scattered around the data volume will be moved to the front of the data volume and the free space at the end of the data volume will be truncated. ::= ‗host:port‘ ::= % of payload size (should be > 110%) ::= either ―defragment‖ or ―sparsify‖, default value is ―defragment‖ RECLAIM LOG Reclaim disk space of unused log segments. ::= Log part number
66 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
67/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual RECLAIM VERSION SPACE Performs MVCC version garbage collection for resource reuse. RECLONFIGURE SERVICE RECONFIGURE SERVICE reconfigures the service with current parameters. Depending on service, host, port, different services can be reconfigured: Service
Host
port
n.a.
not empty
not 0
not empty
not empty
0 Reconfigure all services of type x on host y
not empty
empty
0 Reconfigure all services of type x
empty
empty
0 Reconfigure all services
Reconfigure single service on host y with port z
The information on service status is available at M_SERVICES.
RESET MONITORING VIEW Resets statistics data for the specified monitoring view. START|STOP|SAVE PERFTRACE ALTER SYSTEM START PERFTRACE [USER name] [APPLICATIONUSER name] [PLAN_EXECUTION] [FUNCTION_PROFILER] [DURATION seconds]
START Starts performance trace. It can be restricted to a specific SQL user by providing user_name. Also, plan execution details can be recorded with PLAN_EXECUTION option. If the duration is specified, then it automatically stops after the specified duration. ALTER SYSTEM STOP PERFTRACE
STOP Stops performance trace. ALTER SYSTEM SAVE PERFTRACE [INTO FILE 'filename']
67 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
68/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual SAVE Collect performance trace data and save the information into a file. The file is located on the server in the trace directory. If no file name is specified, then ‗perftrace.tpt' is used. The file can be downloaded from ‗SAP HANA Computing Studio‘ ->Diagnosis-Files and then the performance trace can be loaded and analyzed with HDBAdmin in any HDB instance. The status of performance trace can be monitored from M_PERFTRACE. SAVEPOINT Executes a savepoint on the persistence manager. A savepoint 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. SET EVENT HANDLED Set event with given ID and type to state ―HANDLED‖ STOP SERVCE STOP SERVICE stops the service. HOST and PORT information should be specified to stop a service. STOP SERVICE with IMMEDIATE option kills the running service. HOST and PORT information should be specified to kill a running service. Service
Host
port
n.a.
not empty
not 0
not empty
not empty
0 Reconfigure all services of type x on host y
not empty
empty
0 Reconfigure all services of type x
empty
empty
0 Reconfigure all services
Reconfigure single service on host y with port z
68 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
69/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual ALTER TABLE SQL Syntax: ALTER TABLE { | < drop_column_clause> | < alter_column_clause> | | < drop_primary_key_clause> | | | | < table_conversion_clause> | | | | | | | | } [WITH PARAMETERS ()]
Parameters: ::= [.] ::= ADD ( , ... ) ::=DROP ( , ... ) ::= ALTER ( , ... )
ALTER Increasing the length of a column can be done. When modifying column definition is tried in column store, no error is returned because no check is done inside the database yet. An error may be returned if the data does not fit in the new data type defined when selecting the column. ALTER does not follow data type conversion rules yet. ::= ADD [CONSTRAINT ] PRIMARY KEY (,... )
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 ::= PRELOAD ALL | PRELOAD ( ) | 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 TABLE_COLUMNS, column PRELOAD, possible values ('TRUE', 'FALSE'). ::= ADD STATISTICS FOR QUERY OPTIMIZER [ (,… ) ]
ADD STATISTICS FOR QUERY OPTIMIZER 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 FOR QUERY OPTIMIZER [(,… ) ]
UPDATE STATISTICS FOR QUERY OPTIMIZER Update statistics for the columns of a table. If a column list is not specified, the statistics for all columns of the table are updated. System view statistics has the statistics of columns of a table. Statistics are min, max, count, distinct count, null count values.
69 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
70/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual ::= DROP STATISTICS FOR QUERY OPTIMIZER [(,… ) ]
DROP STATISTICS FOR QUERY OPTIMIZER Drops statistics for the columns of a table. If a column list is not specified, all existing statistics of the table are dropped. ::= [ALTER TYPE] { ROW [THREADS ] | COLUMN [THREADS [BATCH ]]}
ALTER 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 for table conversion. The optimal value for number of threads should set to the number of available CPU cores. Default: The default value is TABLE_CONVERSION_PARALLELISM that is, the number of CPU cores specified in the indexserver.ini file. BATCH Specifies the number of rows inserted in batch, and the default value is 2,000,000 which is the optimal value. Insert into column table will be immediately committed after every int_const records insertion, which may reduce memory consumption. BATCH option can be used only when the table is converted from ROW to COLUMN. However, the batch size more than 2,000,000 might cause high memory consumption, thus it is not recommended to change this value. 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. ::= MOVE TO LOCATION
MOVE TO LOCATION A table can be moved to the specified location in a distributed environment. ::= ADD
ADD adds a partition for tables partitioned with RANGE, HASH RANGE, ROUNDROBIN RANGE. ::= PRTITION <= VALUES < < max_value> | PARTITION = | PARTITION OTHERS ::= | ::= | ::= | ::= MOVE PARTITION TO
MOVE PARTITION moves a partition to another host. The port number is the internal indexserver port number, 3xx03. ::= DROP PARTITION
DROP PARTITION drops a partition for tables partitioned with RANGE, HASH RANGE, ROUNDROBIN RANGE.
70 http://slidepdf.com/reader/full/sap-hana-database-sql-reference-manualpdf
71/182
5/19/2018
SAPHANADatabase-SQLReferenceManual.pdf-slidepdf.com
SAP HANA Database: SQL Reference Manual
::= PARTITION BY [, | ,] | PARTITION BY | PARTITION BY [,] ::= HASH ([, ...]) PARTITIONS { | GET_NUM_SERVERS()} ::= RANGE (