ORACLE DATE TYPE CONVERSION
- TO_CHAR
- TO_DATE
TO_CHAR FUNCTION
The Oracle TO_CHAR() Function converts a number or Date to a String.
Input : Number or Date format
Output : It return a String.
Syntax:
TO_CHAR ( Value, [format])
Value : A Number or Date that will be converted to a string
Format : This is the format it will be used to convert value to a string.
SQL> select to_char(1210.93, '9999.99') from dual;
TO_CHAR(
--------
1210.93
SQL> select to_char(1210.93, '9999.99')ff from dual;
FF
--------
1210.93
SQL> select to_char(789.93, '$9999.99')ff from dual;
FF
---------
$789.93
SQL> select to_char(789.93, '999.9')ff from dual;
FF
------
789.9
SQL> select to_char(789.93, '999.9') from dual;
TO_CHA
------
789.9
SQL> select to_char(sysdate) from dual;
TO_CHAR(SYSDATE)
------------------
23-AUG-17
SQL> select to_char(sysdate,'mon dd yy') from dual;
TO_CHAR(SYSDATE,'M
------------------
aug 23 17
SQL> select to_char(sysdate,'Mon dd yy') from dual;
TO_CHAR(SYSDATE,'M
------------------
Aug 23 17
SQL> select to_char(sysdate,'Mon dd yy')today_date from dual;
TODAY_DATE
------------------
Aug 23 17
SQL> select to_char(sysdate,'Mon dd yy')today_date from dual;
TODAY_DATE
------------------
Aug 23 17
TO_DATE FUNCTION
The TO_DATE function converts a string into Date Format.
Input : String
Output : Date Format
Syntax
TO_DATE( string, format)
String : The string that will be converted to a date.
Format : The format that will be used to convert string to date.
SQL> select to_date('feb 08,2014','month DD,YYYY')from dual;
TO_DATE('
---------
08-FEB-14