trunc函数

在做定时任务时碰到了trunc函数,这里对trunc函数简单介绍一下:
trunc函数可以对时间或者数字进行截取处理,用法如下:

对时间(2019-05-09周四操作):
select trunc(sysdate,'yyyy') from dual --当年的第一天--2019/1/1
select trunc(sysdate,'mm') from dual --当月的第一天--2019/5/1

select trunc(sysdate,'dd') from dual --当前时间(精确到天)--2019/5/9
select trunc(sysdate) from dual--当前时间(精确到天)--2019/5/9

select trunc(sysdate,'d') from dual --当前星期的第一天(周日)--2019/5/5
select trunc(sysdate,'hh') from dual --当前时间(精确到小时)--2019/5/9 10:00:00
select trunc(sysdate,'mi') from dual --当前时间(精确到分钟)--2019/5/9 10:15:00

对数字:
trunc(66.6,-1) = 60; //-1(负数)表示从小数点左边第一位截取后面全置为零;
trunc(66.66,1) = 66.6; //1(正数)表示小数点后面保留一位;
trunc(66.6) = 66; //截取整数部分;

你可能感兴趣的:(trunc函数)