1.ROUND(按照指定的精度進行四捨五入)
按照指定的小數位進行四捨五入之後返回一個數值,比如:
select round(31.1415) from dual; --返回 31 ,不傳參數,默認保留整數
select round(31.1415,2) from dual; --返回 31.14
select round(31.14155,3) from dual; --返回 31.142
2.TRUNC
按照指定的小數位進行截取之後返回一個數值,比如:
select trunc(0.23) from dual; -- 返回 33 ,不傳參數,默認取整
select trunc(33.841321,2) from dual; -- 返回 33.84
select trunc(33.8999,2) from dual; -- 返回 33.89
select trunc(3345.8999,-2) from dual; -- 返回 3300,傳負數表示小數點左邊指定位數後面的部分截去補0
trunc函數還可以用來處理日期
select trunc(sysdate,'yyyy') from dual; --截取到年(本年的第一天) 2019/1/1
select trunc(sysdate,'q') from dual; --截取到季度(本季度的第一天) 2019/10/1
select trunc(sysdate,'mm') from dual; --截取到月(本月的第一天) 2019/11/1
select trunc(sysdate) from dual; --截取到日(今天) 2019/11/6
--默認截取到日(當日的零點零分零秒)
select to_char(trunc(sysdate),'yyyy-mm-dd hh24:mi:ss') from dual; 2019-11-06 00:00:00
select trunc(sysdate,'d') from dual; --截取到周(本週第一天,即上週日) 2019/11/3
select trunc(sysdate,'iw') from dual; --本週第2天,即本週一 2019/11/4
select trunc(sysdate,'hh24') from dual; --截取到小時(當前小時,零分零秒)
select trunc(sysdate,'mi') from dual; --截取到分(當前分,零秒)
3.FLOOR
取小於等於數值n的最大整數
select floor(45.999) from dual;--返回45
select floor(45.001) from dual;--返回45
4.CEIL
取大於等於數值n的最小整數
select ceil(45.999) from dual;--返回46
select ceil(45.001) from dual;--返回46