This shows you the differences between two versions of the page.
cast [2015/09/23 20:26] |
cast [2015/09/23 20:26] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== CAST Function - PL/HQL Reference====== | ||
+ | |||
+ | CAST function converts an expression to the specified data type. | ||
+ | |||
+ | **Syntax**: | ||
+ | |||
+ | <code language="sql"> | ||
+ | CAST(expression AS datatype[(length)]); | ||
+ | </code> | ||
+ | |||
+ | Notes: | ||
+ | |||
+ | * If //length// is specified for CAST as CHAR or VARCHAR function, the resulting string is truncated to this length. | ||
+ | |||
+ | **Example 1:** | ||
+ | |||
+ | Convert to a string with the specified length: | ||
+ | |||
+ | <code language="sql"> | ||
+ | CAST('Abc' AS CHAR(1)); | ||
+ | -- | ||
+ | A | ||
+ | </code> | ||
+ | |||
+ | **Example 2:** | ||
+ | |||
+ | Truncate a timestamp string: | ||
+ | |||
+ | <code language="sql"> | ||
+ | CAST(TIMESTAMP '2015-03-12 10:58:34.111' AS CHAR(10)); | ||
+ | -- | ||
+ | 2015-03-12 | ||
+ | </code> | ||
+ | |||
+ | **Compatibility**: Oracle, Microsoft SQL Server, IBM DB2, Teradata, PostgreSQL, MySQL and Netezza | ||
+ | |||
+ | **Version**: PL/HQL 0.03 | ||