The CAST function is used to explicitly convert a value to another data type, with the syntax CAST(expression AS data_type). Usage examples include: convert numeric value to string, string to date, and string to number. Conversion options include numeric, character, date, and boolean types.
Usage of CAST function in Oracle
Introduction to CAST function
The CAST function is used to explicitly convert a value of one data type to another data type. The syntax is as follows:
<code>CAST(expression AS data_type)</code>
Where:
expression
: The value to be converted data_type
: To be converted To the data typeUsage example
Convert a numerical value to a string
<code>SELECT CAST(123.45 AS VARCHAR2(20)) FROM dual;</code>
Result: '123.45'
Convert string to date
<code>SELECT CAST('2023-01-01' AS DATE) FROM dual;</code>
Result: 2023-01-01
Convert string to number
<code>SELECT CAST('1,234.56' AS NUMBER) FROM dual;</code>
Result: 1234.56
Type conversion options
The CAST function supports multiple data type conversions, including:
Notes
The above is the detailed content of Usage of cast function in oracle. For more information, please follow other related articles on the PHP Chinese website!