trunc用于截取数字和日期。
1.截取数字
trunc(n1,n2),n1表示被截断的数字,n2表示要截断到那一位。n2可以是负数,表示截断小数点前.
1. select trunc(34.245) from dual; --34
2. select trunc(34.245,1) from dual; --34.2 3. select trunc(34.245,-1) from dual; --30
2.截取日期
1.select trunc(sysdate) from dual --2017-10-13 今天的日期为2017-10-13
2.select trunc(sysdate, 'mm') from dual --2017-10-1 返回当月第一天.3.select trunc(sysdate,'yy') from dual --2017-1-1 返回当年第一天4.select trunc(sysdate,'dd') from dual --2017-10-13 返回当前年月日5.select trunc(sysdate,'yyyy') from dual --2017-1-1 返回当年第一天6.select trunc(sysdate,'d') from dual --2017-10-8 (星期日)返回当前星期的第一天7.select trunc(sysdate, 'hh') from dual --2017-10-13 17:00:00 当前时间为17:318.select trunc(sysdate, 'mi') from dual --2017-10-13 17:31:00 TRUNC()函数没有秒的精确