Oracle中關於處理小數點位元的幾個函數

來源:互聯網
上載者:User

關於處理小數點位元的幾個Oracle函數()
1. 取四捨五入的幾位小數
select round(1.2345, 3) from dual;
結果:1.235
2. 保留兩位小數,只舍
select trunc(1.2345, 2) from dual;
結果:1.23

select trunc(1.2399, 2) from dual;
結果:1.23
3.取整數
返回大於或等於x的最大整數: 
        SQL>         select         ceil(23.33)         from         dual; 
結果:   24 

返回等於或小於x的最大整數: 
        SQL>         select         floor(23.33)         from         dual; 
結果:   23 
  
返回舍入到小數點右邊y位的x值:rcund(x,[y]) 
        SQL>         select         round(23.33)         from         dual; 
結果:    23 
  
返回截尾到y位小數的x值:trunc(x,[y]) 
        SQL>         select         trunc(23.33)         from         dual; 
結果:   23 


格式化數字

 The following are number examples for the to_char function.


  to_char(1210.73, '9999.9') would return '1210.7'
  to_char(1210.73, '9,999.99') would return '1,210.73'
  to_char(1210.73, '$9,999.00') would return '$1,210.73'
  to_char(21, '000099') would return '000021'


to_char函數特殊用法
  to_char(sysdate,'d') 每周第幾天
  to_char(sysdate,'dd') 每月第幾天
  to_char(sysdate,'ddd') 每年第幾天
  to_char(sysdate,'ww') 每年第幾周
  to_char(sysdate,'mm') 每年第幾月
  to_char(sysdate,'q') 每年第幾季
  to_char(sysdate,'yyyy') 年
  比如要找某個時間為每周第幾天就可以
  SQL> select to_char(to_date('20070101','yyyymmdd'),'d') from dual;

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.