轉換函數

--知識點一個
--轉換函數
--RR日期格式
--      RR:0-49代表本世紀,50及以上代表上世紀(默認)
--      YY:代表和當前時間所處的同一個世紀
--建議:儘量用四位的年

--例1(of用來分隔,fm去除空格)
select to_char(t.hiredate,'fmddspth"of"month YYYY fmHH24:MI:SS AM') hd from emp t where t.hiredate like '%87%';

--to_char
--to_char(number,'fmt')
--將數值轉換成字符串
--     0:強制顯示0來填充未滿數據位數
--     9:代表一個數字,未滿數據位數不會填充0或9
--     $:設置一個浮點型的美元符號
--     L:使用本地貨幣符號
--注意,逗號和小數點的使用區別


--例1
select to_char(t.sal,'0000.00') from emp t;
select to_char(t.sal,'000.00') from emp t;
select to_char(t.sal,'0000') from emp t;
select to_char(t.sal,'0000,00.00') from emp t;
--例2
select to_char(t.sal,'9999,99') from emp t;
--例三
select to_char(t.sal,'$9999,99') from emp t;
--例四
select to_char(t.sal,'L9999,99') from emp t;
select to_char(t.sal,'fmL9999,99') from emp t;
--如果設定的位數小於實際位數,則數據會全部用#代替
select to_char(t.sal,'999.99') from emp t;
select to_char(t.sal,'99999.99') from emp t;


--to_number
--to_number(char)
--將一個數值字符串轉換成數值

--例1
select to_number('23432') from dual;
發佈了43 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章