Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Reference » SQL Functions » Alphabetical list of functions

BYTE_SUBSTR function [String] Next Page

CAST function [Data type conversion]


Returns the value of an expression converted to a supplied data type.

Syntax

CAST( expression AS datatype )

Parameters

expression    The expression to be converted.

data type    The target data type.

Remarks

If you do not indicate a length for character string types, the database server chooses an appropriate length. If neither precision nor scale is specified for a DECIMAL conversion, the database server selects appropriate values.

If you use the CAST function to truncate strings, the string_rtruncation database option must be set to OFF; otherwise, there will be an error. It is recommended that you use the LEFT function to truncate strings.

See also
Standards and compatibility
Example

The following function ensures a string is used as a date:

SELECT CAST( '2000-10-31' AS DATE );

The value of the expression 1 + 2 is calculated, and the result is then cast into a single-character string.

SELECT CAST( 1 + 2 AS CHAR );