Oracle® TimesTen In-Memory Database SQL Reference Release 11.2.1 Part Number E13070-03 |
|
|
View PDF |
Allows you to convert data of one type to another type. CAST can be used wherever a constant can be used. CAST is useful in specifying the exact data type for an argument. This is especially true for unary operators like '-' or functions with one operand like TO_CHAR or TO_DATE.
A value can only be CAST to a compatible data type, with the exception of NULL. NULL can be cast to any other data type. CAST is not needed to convert a NULL to the desired target type in an insert select.
The following conversions are supported:
Numeric value to numeric or BCD (Binary Coded Decimal)
NCHAR to NCHAR
CHAR string to BINARY string or DATE, TIME or TIMESTAMP
BINARY string to BINARY or CHAR string
DATE, TIME or TIMESTAMP to CHAR
SQL syntax
CAST ( {Expression | NULL} AS DataType )
Parameters
CAST has the parameters:
Parameter | Description |
---|---|
Expression |
Specifies the value to be converted. |
AS DataType |
Specifies the resulting data type. |
Description
CAST to a domain name is not supported.
Casting a selected value may cause the SELECT statement to take more time and memory than a SELECT statement without a CAST expression.
Examples
INSERT INTO t1 VALUES(TO_CHAR(CAST(? AS REAL))); SELECT CONCAT(x1, CAST (? AS CHAR(10))) FROM t1; SELECT * FROM t1 WHERE CAST (? AS INT)=CAST(? AS INT);