/**************日期********************/SELECT TRUNC(SYSDATE) FROM DUAL; --2019/11/29 今天的日期为2019/11/29SELECT TRUNC(SYSDATE, 'MM') FROM DUAL; --2019/11/01 返回当月第一天.SELECT TRUNC(SYSDATE,'YY') FROM DUAL; --2019/11/01 返回当年第一天SELECT TRUNC(SYSDATE,'YYYY') FROM DUAL; --2019/01/01 返回当年第一天SELECT TRUNC(SYSDATE,'DD') FROM DUAL; --2019/11/29 返回当前年月日SELECT TRUNC(SYSDATE,'D') FROM DUAL; --2019/11/24 (星期天)返回当前星期的第一天SELECT TRUNC(SYSDATE, 'HH24') FROM DUAL; --2019/11/29 17:00:00 当前时间为17:11SELECT TRUNC(SYSDATE, 'MI') FROM DUAL; --2019/11/29 17:11:00 TRUNC()函数没有秒的精确
/***************数字********************//*TRUNC(NUMBER,NUM_DIGITS)NUMBER 需要截尾取整的数字。NUM_DIGITS 用于指定取整精度的数字。NUM_DIGITS 的默认值为 0。TRUNC()函数截取时不进行四舍五入*//****************小数***********************/SELECT TRUNC(123.458,-4) FROM DUAL; --0SELECT TRUNC(123.458,-3) FROM DUAL; --0SELECT TRUNC(123.458,-2) FROM DUAL; --100SELECT TRUNC(123.458,-1) FROM DUAL; --120SELECT TRUNC(123.458) FROM DUAL; --123SELECT TRUNC(123.458,1) FROM DUAL; --123.4SELECT TRUNC(123.458,2) FROM DUAL; --123.45SELECT TRUNC(123.458,3) FROM DUAL; --123.458SELECT TRUNC(123.458,4) FROM DUAL; --123.458/****************整数***********************/SELECT TRUNC(123,-4) FROM DUAL; --0SELECT TRUNC(123,-3) FROM DUAL; --0SELECT TRUNC(123,-2) FROM DUAL; --100SELECT TRUNC(123,-1) FROM DUAL; --120SELECT TRUNC(123) FROM DUAL; --123SELECT TRUNC(123,1) FROM DUAL; --123SELECT TRUNC(123,2) FROM DUAL; --123
联系客服