Oracle data type conversion method: 1. Use the cast() function, the syntax "cast(x as type)"; 2. Use the to_char() function, the syntax "to_char(x[,f])" ;3. Use to_date() function, syntax "to_date(x[,f])", etc.
The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.
oracle’s data type conversion method
1. Use cast()
cast( ) is a data type conversion function. This function can convert x to the corresponding data type. It is basically used for numeric, character, and time types to install database rules for mutual conversion.
Syntax:
cast(x as type)
Example:
select cast('123' as number) num,cast(123 as varchar2(3)) as ch,cast(to_date('20211112','yyyymmdd') as varchar2(12)) as time from dual;
Result:
123 '123' 12-11月-21
2. Use to_char()
The to_char() function can format a string or time type x into a string according to format f.
Syntax:
to_char(x[,f])
Example:
select to_char(123.46,'999.9') from dual; select to_char(sysdate,'yyyy-mm-dd') from dual;
Result:
123.5 2021-11-13
3. Use to_date()
The to_date() function can format the string x according to format f and convert it into a time type result.
Syntax:
to_date(x[,f])
Example:
select to_date('2021-11-13','yyyy-mm-dd') from dual;
Result:
2021/11/13
4. Use to_number()
The to_number() function can format the string x according to format f and convert it into a numerical type result.
Grammar:
to_number(x[,f])
Example:
select to_number('123.74','999.99') from dual
Result:
123.74
Description: For the format f of the value, please refer to the following table
Parameters |
##Example |
illustrate |
9 |
##999 |
Return the number at the specified position |
. |
99.9 |
Specify the position of the decimal point |
, | ##99,9
|
|
$99.9 |
## Returns a dollar sign at the beginning |
|
EEEE |
##9.99EEEE
|
Specify scientific notation |
The above is the detailed content of How to convert Oracle data types. For more information, please follow other related articles on the PHP Chinese website!