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(expr 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.
BIGINT | BINARY | BLOB | CHAR | CLOB | DATE | DECIMAL | DOUBLE | NCHAR |
NCLOB | REAL | TIME | TIMESTAMP
Example:
SELECT TOP 1 CAST(7 AS CHAR(10)) "cast" FROM users;
Retrieves:
cast
7
TO_BIGINT Function
Syntax:
TO_BIGINT(expr)
Description:
Converts the expr of a data type into a value of bigint data type.
Example:
SELECT TOP 1 TO_BIGINT('10') "to bigint" FROM users;
Retrieves:
to bigint
10
TO_BINARY Function
Syntax:
TO_BINARY(expr)
Description:
Converts the expr of a data type into a value of binary string type.
SAP In-Memory Database SQL Reference Manual
10
Example:
SELECT TOP 1 TO_BINARY('abcde') "to binary" FROM users;
Retrieves:
to binary
6162636465
TO_BLOB Function
Syntax:
TO_BLOB(expr)
Description:
Converts the expr of a data type into a value of blob type. expr must be a binary string.
Example:
SELECT TOP 1 TO_BLOB(TO_BINARY('abcde')) "to blob" FROM users;
Retrieves:
to blob
abcde
TO_CHAR Function
Syntax:
TO_CHAR(expr [,format])
Description:
Converts the expr of a data type into a value of character data type.
Example:
SELECT TOP 1 TO_CHAR(TO_DATE('2009-12-31'), 'YYYY/MM/DD') "to char" FROM users;
Retrieves:
to char
2009/12/31
TO_CLOB Function
Syntax:
TO_CLOB(expr)
Description:
Converts the expr of a data type into a value of CLOB data type.
Example:
SELECT TOP 1 TO_CLOB ('TO_CLOB converts an expression into a value of CLOB data type') "to clob"
FROM users;
Retrieves:
to clob
TO_CLOB converts an expression into a value of CLOB data type
TO_DATE Function
Syntax:
TO_DATE(expr [, format])
Description:
SAP In-Memory Database SQL Reference Manual
11
Converts the expr of a data type into a value of DATE data type.
Example:
SELECT TOP 1 TO_DATE('2010-01-12', 'YYYY-MM-DD') "to date" FROM users;
Retrieves:
to date
2010-01-12
TO_DATS Function
Syntax:
TO_DATS(expr)
Description:
Converts the expr of a data type into a value of ABAP DATE data type.
Example:
SELECT TOP 1 TO_DATS('2010-01-12') "abap date" FROM users;
Retrieves:
abap date
20100112
TO_DECIMAL Function
Syntax:
TO_DECIMAL(expr[, precision, scale])
Description:
Converts the expr of a data type into a value of DECIMAL(precision, scale) data type.
Example:
SELECT TOP 1 TO_DECIMAL(7654321.89, 9, 2) "to decimal" FROM users;
Retrieves:
to decimal
7654321.89
TO_DOUBLE Function
Syntax:
TO_DOUBLE(expr)
Description:
Converts the expr of a data type into a value of DOUBLE (double precision) data type.
Example:
SELECT TOP 1 3*TO_DOUBLE ('15.12') "to double" FROM users;
Retrieves:
to double
45.36