首页 > 其他 > 详细

truncate 函数用法示例

时间:2015-03-25 17:01:29      阅读:251      评论:0      收藏:0      [点我收藏+]
--Oracle trunc()函数的用法
/**************日期********************/
select trunc(sysdate) from dual  --2015-03-23   今天的日期为2015-03-23
select trunc(sysdate, mm)   from   dual  --2015-03-01    返回当月第一天.
select trunc(sysdate,yy) from dual  --2015-01-01     返回当年第一天
select trunc(sysdate,dd) from dual  --2015-03-23   返回当前年月日
select trunc(sysdate,yyyy) from dual  --2015-01-01  返回当年第一天
select trunc(sysdate,d) from dual  -- 2015-03-22(星期天)返回当前星期的第一天
select trunc(sysdate, hh) from dual   --2015-03-23 16:00:00  
select trunc(sysdate, mi) from dual  --2015-03-23 16:32:00 TRUNC()函数没有秒的精确
/***************数字********************/
/*
TRUNC(number,num_digits) 
Number 需要截尾取整的数字。 
Num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。
TRUNC()函数截取时不进行四舍五入
*/
select trunc(123.458) from dual --123
select trunc(123.458,0) from dual --123
select trunc(123.458,1) from dual --123.4
select trunc(123.458,-1) from dual --120
select trunc(123.458,-4) from dual --0
select trunc(123.458,4) from dual  --123.458
select trunc(123) from dual  --123
select trunc(123,1) from dual --123
select trunc(123,-1) from dual --120

 

truncate 函数用法示例

原文:http://www.cnblogs.com/tianmingt/p/4366043.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!