CAST function
The CAST function converts a value from one data type to another data type.
Syntax
CAST ( [ Expression | NULL | ? ] AS Datatype)
Note : CAST conversions among SQL-92 data types.
The flowing are SQL-92 data types
SELECT CAST (SYSDATE AS VARCHAR2 (12)) DATE_TO_VARCHAR FROM DUAL;
SELECT CAST ('12' AS INTEGER) STRING_TO_NUMBERIC FROM DUAL;
SELECT CAST (NULL AS VARCHAR2 (2)) NULL_TO_STRING FROM DUAL;
As CAST only convert among SQL-92 data types, we can not use for example RAW data type.
But there are some packages casts to RAW like utl_raw.cast_to_raw
SELECT UTL_RAW.CAST_TO_RAW('Mahmoud') FROM DUAL;
output is : "4D61686D6F7564"
The CAST function converts a value from one data type to another data type.
Syntax
CAST ( [ Expression | NULL | ? ] AS Datatype)
Note : CAST conversions among SQL-92 data types.
The flowing are SQL-92 data types
- BOOLEAN
- SMALLINT
- INTEGER
- BIGINT
- DECIMAL
- REAL
- DOUBLE
- FLOAT
- CHAR
- VARCHAR
- LONG VARCHAR
- CHAR
- VARCHAR
- LONG VARCHAR
- CLOB
- BLOB
- DATE
- TIME
- TIMESTAMP
- XML
SELECT CAST (SYSDATE AS VARCHAR2 (12)) DATE_TO_VARCHAR FROM DUAL;
SELECT CAST ('12' AS INTEGER) STRING_TO_NUMBERIC FROM DUAL;
SELECT CAST (NULL AS VARCHAR2 (2)) NULL_TO_STRING FROM DUAL;
As CAST only convert among SQL-92 data types, we can not use for example RAW data type.
But there are some packages casts to RAW like utl_raw.cast_to_raw
SELECT UTL_RAW.CAST_TO_RAW('Mahmoud') FROM DUAL;
output is : "4D61686D6F7564"