Convert a date to character
1. Grammar
Default format DD-MON-RR
YY YYYY YEAR (English year)
MM MONTH (English Month)
DD DAY
HH24 HH12
MI SS
2. Examples
SQL>select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS')from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2017-07-02 11:40:14
SQL> select to_char(sysdate,'YYYY-MM-DD HH12:MI:SS') from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2017-07-0211:40:38
Convert two characters to date
1. Grammar
TO_DATE(char[,fmt[,params]])
params: the language used to make the date
Note: to_date() displays in the system default date format
2. Examples
SQL>select to_date('2017-7-2','YYYY-MM-DD')from dual;
TO_DATE('2017-
--------------
02-7月 -17
Convert three numbers to characters
1. Grammar
TO_CHAR(number[,fmt])
9: Display the number and ignore the leading 0
0: Display the number, if the number of digits is insufficient, fill it with 0
.or D: Display decimal point
, or G: display thousands
$: dollar sign
S: plus plus or minus sign (both before and after)
2. Examples
SQL>select to_date('2017-7-2','YYYY-MM-DD')from dual;
TO_DATE('2017-
--------------
02-7月 -17
SQL> select to_char(12345.678,'$99,999.999') from dual;
TO_CHAR(1234
------------
$12,345.678
SQL> select to_char(12345.678,'$99,999,999') from dual;
TO_CHAR(1234
------------
$12,346
SQL> select to_char(12345.678,'S99,999.999') from dual;
TO_CHAR(123
-----------
+12,345.678
Convert four characters to numbers
1. Grammar
TO_NUMBER(char[,fmt])
fmt is the converted format and can be omitted
2. Examples
SQL>select to_number('$1,000','$9999')from dual;
TO_NUMBER('$1,000','$9999')
---------------------------
1000