Professional Documents
Culture Documents
--> The function converts one data type to another data type.
--> Character data are always valid for oracle.
--> But problem with number and date data. They need conversions. So invalid state
of number & date should be
converted into valid state and vic versa.
Types Of Conversion:
--> These type of conversion work according to the conversion specified by oracle.
LIKE
--> Character to number conversion succeed only if the character strings represent
a valid no.
--> Character to date conversion succeed only if the character strings represent a
valid date.
--> SQL provides three functions to convert a value from one data type to another.
--> The explicit conversion functions are:
Syntax: to_char(number/col,'format','nls_params')
Ex:
Note: 9 stands for place holder, we need to provide same no of 9 (place holder)
which is equals to the length of actual number.
2) Decimal indicator: (D / .)
Ex:
SQL> select to_char(12000,'99999D99') from dual;
SQL> select to_char(12000,'99999.99') from dual;
Ex:
SQL> select to_char(12000,'L99999') from dual;
O/P: $12000
O/P: 12000$
O/P: Rs.12000
Ex:
O/P: Rs.12,000.00
--> It is used to convert a date value from original format to user format (Date
data type to Varchar2 data type).
Diffrent Format/Indicators:
Ex:
SQL> select to_char(sysdate,'AD') from dual;
O/P : AD
O/P : AD
2) AM or A.M. / PM or P.M.:
Ex:
O/P: PM
O/P: P.M.