Oracle trunc函数总结

当天日期是 2020-2-20 星期三
1.select trunc(sysdate) from dual    输出:2020-2-20 返回今天的日期
2.select trunc(sysdate, 'mm') from dual 输出:2020-2-1 返回当月第一天.
3.select trunc(sysdate,'yy') from dual 输出:2020-1-1返回当年第一天
4.select trunc(sysdate,'dd') from dual 输出:2020-2-20 返回当前年月日
5.select trunc(sysdate,'yyyy') from dual 输出:2020-1-1返回当年第一天
6.select trunc(sysdate,'d') from dual 输出:2020-2-16 返回当前星期的第一天 第一天从星期天算起
7.select trunc(sysdate, 'hh') from dual 输出:2020-2-20 13:00:00 输出的当前时间的精确到小时  当前时间为13:25
8.select trunc(sysdate, 'mi') from dual 输出:2020-2-20 13:25:00 trunc()函数没有秒的精确
精确数字位数
trunc(number,length)
number 需要截尾取整的数字。
length用于指定取整精度的数字。length 的默认值为 0。
trunc函数截取时不进行四舍五入

9.select trunc(133.458) from dual --133
10.select trunc(133.458,0) from dual --133
11.select trunc(133.458,1) from dual --133.4
12.select trunc(133.458,-1) from dual --130
13.select trunc(133.458,-4) from dual --0
14.select trunc(133.458,4) from dual --133.458
15.select trunc(133) from dual --133
16.select trunc(133,1) from dual --133
17.select trunc(133,-1) from dual --130

比较日期的大小

select  * from  mtl_item_price_record_info m 
where  trunc(m.price_date) <=trunc(sysdate) and trunc(m.price_date)>trunc(to_date('2019-11-22','yyyy-mm-dd'))
m.price_date 的时间小于等于 当前系统的时间 并且 大于2019-11-22的时间

发布了31 篇原创文章 · 获赞 1 · 访问量 1829

猜你喜欢

转载自blog.csdn.net/liangdingguo/article/details/104391676