CAST
Enables 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 data type. CAST is not needed to convert a NULL literal to the desired target type.
The following conversions are supported:
-
Numeric value to numeric or BCD (Binary Coded Decimal)
-
NCHARtoNCHAR -
CHARstring toBINARYstring orDATE,TIMEorTIMESTAMP -
BINARYstring toBINARYorCHARstring -
DATE,TIMEorTIMESTAMPtoCHAR
SQL syntax
CAST
( {Expression | NULL} AS DataType )Parameters
CAST has the parameters:
| Parameter | Description |
|---|---|
|
|
Specifies the value to be converted. |
|
|
Specifies the resulting data type. |
Description
-
CASTto a domain name is not supported. -
Casting a selected value may cause the
SELECTstatement to take more time and memory than aSELECTstatement without aCASTexpression.
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);