Oracle - Trunc() 函數截取日期&截取數值


Oracle TRUNC函數可以截取數字和日期類型:

截取日期:

select
to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; --顯示當前時間 select trunc(sysdate,'year') from dual; --截取到年(本年的第一天) select trunc(sysdate,'q') from dual; --截取到季度(本季度的第一天) select trunc(sysdate,'month') from dual; --截取到月(本月的第一天) select trunc(sysdate,'') from dual; --為空 select trunc(sysdate) from dual; --截取到日(今天) select to_char(trunc(sysdate),'yyyy-mm-dd hh24:mi:ss') from dual; --默認截取到日(當日的零點零分零秒) select trunc(sysdate,'day') from dual; --截取到周(本周第一天,即上周日) select trunc(sysdate,'iw') from dual; --本周第2天,即本周一 select to_char(trunc(sysdate,'dd'),'yyyy-mm-dd hh24:mi:ss') from dual; --截取到日(當日的零點零分零秒) select trunc(sysdate,'hh24') from dual; --截取到小時(當前小時,零分零秒) select trunc(sysdate,'mi') from dual; --截取到分(當前分,零秒) select trunc(sysdate,'ss') from dual ;--報錯,沒有精確到秒的格式   

截取數值:
trunc(number,decimals
) number:指需要截取的數字
select trunc(122.555) from dual t; --默認取整

select trunc(122.555,2) from dual t;
select trunc(122.555,-2) from dual t;--負數表示從小數點左邊開始截取2位

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM