SQL Functions Reference

SAP Datasphere views support a subset of the SQL functions supported by SAP HANA Cloud.

Array Functions

SAP Datasphere supports the following array functions, which take arrays as input:
  • SUBARRAY

  • TRIM_ARRAY

For detailed documentation of these functions, see Array Functions in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

Data Type Conversion Functions

SAP Datasphere supports the following data type conversion functions, which convert data from one data type to another:
  • CAST

  • TO_BIGINT

  • TO_BINARY

  • TO_BLOB

  • TO_BOOLEAN

  • TO_CLOB

  • TO_DATE

  • TO_DATS

  • TO_DECIMAL (DECFLOAT)

  • TO_DOUBLE (DOUBLE)

  • TO_FIXEDCHAR

  • TO_INT (INT)

  • TO_INTEGER (INT)

  • TO_NCLOB

  • TO_NVARCHAR

  • TO_REAL (FLOAT)

  • TO_SECONDDATE

  • TO_SMALLDECIMAL

  • TO_SMALLINT

  • TO_TIME

  • TO_TIMESTAMP

  • TO_TINYINT

  • TO_VARBINARY

  • TO_VARCHAR

For detailed documentation of these functions, see Data Type Conversion Functions in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

Datetime Functions

SAP Datasphere supports the following datetime functions, which perform operations on date and time data types or return date or time information:
  • ADD_DAYS

  • ADD_MONTHS

  • ADD_MONTHS_LAST

  • ADD_NANO100

  • ADD_SECONDS

  • ADD_WORKDAYS

  • ADD_YEARS

  • CURRENT_DATE

  • CURRENT_DATE()

  • CURRENT_TIME

  • CURRENT_TIME()

  • CURRENT_TIMESTAMP

  • CURRENT_TIMESTAMP()

  • DAYNAME

  • DAYOFMONTH

  • DAYOFYEAR

  • DAYS_BETWEEN

  • HOUR

  • ISOWEEK

  • LAST_DAY

  • LOCALTOUTC

  • MINUTE

  • MONTH

  • MONTHNAME

  • MONTHS_BETWEEN

  • NEXT_DAY

  • NOW

  • QUARTER

  • SECOND

  • SECONDS_BETWEEN

  • UTCTOLOCAL

  • WEEK

  • WEEKDAY

  • WORKDAYS_BETWEEN

  • YEAR

  • YEARS_BETWEEN

For detailed documentation of these functions, see Datetime Functions in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

Fulltext Functions

SAP Datasphere supports the following fulltext functions, which perform operations on data that has a fulltext index:
  • SCORE

For detailed documentation of this function, see SCORE Function in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

Miscellaneous Functions

SAP Datasphere supports the following miscellaneous functions, which return system values and perform various operations on values, expressions, and return values of other functions: For detailed documentation of these functions, see Miscellaneous Functions in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

Numeric Functions

SAP Datasphere supports the following numeric functions, which perform mathematical operations on numerical data types or return numeric information:
  • ABS

  • ACOS

  • ASIN

  • ATAN

  • ATAN2

  • BITAND

  • BITCOUNT

  • BITNOT

  • BITOR

  • BITXOR

  • CEIL

  • COS

  • COSH

  • COT

  • EXP

  • FLOOR

  • LN (LOG)

  • LOG (LOG10)

  • MOD (%)

  • NDIV0

  • POWER (**)

  • RAND

  • ROUND

  • SIGN

  • SIN

  • SINH

  • SQRT

  • TAN

  • TANH

  • UMINUS

For detailed documentation of these functions, see Numeric Functions in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

Security Functions

SAP Datasphere supports the following security functions, which provide special functionality for security purposes:
  • ESCAPE_DOUBLE_QUOTES

  • ESCAPE_SINGLE_QUOTES

  • IS_SQL_INJECTION_SAFE

For detailed documentation of these functions, see Security Functions in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

String Functions

SAP Datasphere supports the following string functions, which perform extraction and manipulation on strings, or return information about strings:
  • ABAP_ALPHANUM

  • ABAP_LOWER

  • ABAP_NUMC

  • ABAP_UPPER

  • ASCII

  • BINTOHEX

  • BINTOSTR

  • CHAR

  • CONCAT

  • HEXTOBIN

  • LCASE

  • LEFT

  • LENGTH

  • LOCATE

  • LOWER

  • LPAD

  • LTRIM

  • NCHAR

  • REPLACE

  • REPLACE_REGEXPR *

  • RIGHT

  • RPAD

  • RTRIM

  • SOUNDEX

  • STRTOBIN

  • SUBSTR_AFTER

  • SUBSTR_BEFORE

  • SUBSTRING_REGEXPR *

  • SUBSTRING

  • UCASE

  • UNICODE

  • UPPER

* SQL views only.

For detailed documentation, see String Functions in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

Window Functions

SAP Datasphere supports the following window and window aggregation functions, which allow you to perform analytic operations over a set of input rows:
  • AVG

  • BINNING

  • CORR

  • CORR_SPEARMAN

  • COUNT

  • CUBIC_SPLINE_APPROX

  • CUME_DIST

  • DENSE_RANK

  • FIRST_VALUE

  • LAG

  • LAST_VALUE

  • LEAD

  • MAX

  • MEDIAN

  • MIN

  • NTH_VALUE

  • NTILE

  • PERCENT_RANK

  • RANDOM_PARTITION

  • RANK

  • ROW_NUMBER

  • SERIES_FILTER

  • STDDEV

  • SUM

  • VAR

  • WEIGHTED_AVG

For detailed documentation of these functions, see Window Functions and the Window Specification in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

Example: Converting Currency Values with CONVERT_CURRENCY

When using the CONVERT_CURRENCY function you must, as a minimum, complete the following parameters:
  • AMOUNT - Specify the column containing the currency value to be converted

  • CLIENT - Specify the three character string identifying the tenant in your SAP system

  • SOURCE_UNIT - Specify the column containing the source currency or enter the source currency code

  • TARGET_UNIT - Specify the column containing the target currency or enter the target currency code

  • REFERENCE_DATE - Specify the date to use when obtaining the conversion rate

  • SCHEMA - Specify the space name.

In our example, which is in a space named SALES, we are converting the value in the Sale_Amount column from Euros to US Dollars using the conversion rate from 30 September 2021:
CONVERT_CURRENCY(
    "AMOUNT" => "Sale_Amount",
"SOURCE_UNIT" => 'EUR',
"TARGET_UNIT" => 'USD',
"SCHEMA" => 'SALES',
"REFERENCE_DATE" => '2021-09-30',
"CLIENT" => '000'
)

For full documentation of this function, see CONVERT_CURRENCY in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.