Trunc函数

trunc函数

TRUNC函数用于对值进行截断。

主要用于截断数字(TRUNC(number)),以及截断日期型,

  1. 截断数字:

TRUNC(n1,n2),n1表示被截断的数字,n2表示要截断到哪一位,并且n2也可以为负数,表示小数点左边指定位数后面的部分截去,均以0计。

例如-》TRUNC(8.99,1)=======》8.9

​ -》 TRUNC(8.99,-1) ======》0

  1. 截断日期;用法于数字型基本类似,废话不说直接上demo

    select trunc(sysdate) from dual  --2011-3-18  今天的日期为2011-3-18
    select trunc(sysdate, 'mm')   from   dual  --2011-3-1    返回当月第一天.
    select trunc(sysdate,'yy') from dual  --2011-1-1       返回当年第一天
    select trunc(sysdate,'dd') from dual  --2011-3-18    返回当前年月日
    select trunc(sysdate,'yyyy') from dual  --2011-1-1   返回当年第一天
    select trunc(sysdate,'d') from dual  --2011-3-13 (星期天)返回当前星期的第一天
    select trunc(sysdate, 'hh') from dual   --2011-3-18 14:00:00   当前时间为14:41   
    select trunc(sysdate, 'mi') from dual  --2011-3-18 14:41:00   当前分钟
    
posted @ 2020-11-14 16:17  且I听  阅读(955)  评论(0)    收藏  举报