標籤:tab strong nbsp -- 示範 cal 轉換 red 字串
轉換函式
字串、數值和日期三類資料之間是可以實現轉換的。
No. |
函數名 |
含義 |
1 |
字串 to_char(列 | 日期,格式) |
將日期或數字按格式轉為字串 |
2 |
日期 to_date(列 | 字串,格式) |
將字串按格式轉為日期 |
3 |
數字 to_number(列 | 字串) |
將字串轉為數字 |
to_char()
一、日期變為字串,必須指定轉換的格式。
日期:年yyyy月mm日dd
時間:時hh hh24分mi秒ss
數字:任一數字9,貨幣L
不可以直接顯示年月日 可以用||來實現
樣本1:將日期顯示格式化。
select to_char(sysdate,‘yyyy-mm-dd‘) from dual; select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘) from dual; |
樣本2:查詢所有在4月份僱傭的僱員。
select * from emp where to_char(hiredate,‘mm‘)=‘04‘; select * from emp where to_char(hiredate,‘mm‘)=4; --自動轉型 |
樣本3:將數字格式化顯示,使用貨幣格式化顯示。
select to_char(‘4758475847583‘,‘9,9999,9999,9999‘) from dual; select to_char(‘4758475847583‘,‘L9,999,999,999,999‘) from dual; |
二、將字串變為日期
樣本4:將指定字串按照格式轉化為日期
select to_date(‘2017-11-21‘,‘yyyy-mm-dd‘) from dual; |
三、將字串轉化為數字。
沒什麼意義
樣本5:to_number()示範。
select to_number(‘12‘)+to_number(‘1‘) from dual; select ‘12‘+‘1‘ from dual; |
oracle 轉換函式