oracle trunc(oracle trunc得到什么格式)

本文目录
oracle trunc得到什么格式
oracle trunc 函数处理日期格式
select to_char(sysdate,’yyyy-mm-dd hh24:mi:ss’) from dual; --显示当前时间
2011-12-29 16:24:34
select trunc(sysdate,’year’) from dual; --截取到年(本年的第一天)
2011-1-1
select trunc(sysdate,’q’) from dual; --截取到季度(本季度的第一天)
2011-10-1
select trunc(sysdate,’month’) from dual; --截取到月(本月的第一天)
2011-12-1
select trunc(sysdate,’’) from dual;
空
select to_char(trunc(sysdate),’yyyymmdd hh24:mi:ss’) from dual; --默认截取到日(当日的零点零分零秒)
20111229 00:00:00
select trunc(sysdate-1,’w’) from dual; -- 离当前时间最近的周四,若当天为周四则返回当天,否则返回上周四
2011-12-22
select trunc(sysdate,’ww’) from dual; --截取到上周末(上周周六)
2011-12-24
select trunc(sysdate,’day’) from dual; --截取到周(本周第一天,即上周日)
2011-12-25
select trunc(sysdate,’iw’) from dual; --本周第2天,即本周一
2011-12-26
select to_char(trunc(sysdate,’dd’),’yyyymmdd hh24:mi:ss’) from dual;--截取到日(当日的零点零分零秒)
20111229 00:00:00
select trunc(sysdate,’hh24’) from dual; --截取到小时(当前小时,零分零秒)
2011-12-29 16:00:00
select trunc(sysdate,’mi’) from dual; --截取到分(当前分,零秒)
2011-12-29 16:24:00
select trunc(sysdate,’ss’) from dual ;--报错,没有精确到秒的格式
Oracle round()函数与trunc()函数区别介绍
round(x[,y])
【功能】返回四舍五入后的值
【参数】x,y,数字型表达式,如果y不为整数则截取y整数部分,如果y》0则四舍五入为y位小数,如果y小于0则四舍五入到小数点向左第y位。
【返回】数字
【示例】
select
round(5555.6666,2.1),round(5555.6666,-2.6),round(5555.6666)
from
dual;
返回:
5555.67
,
5600
,
5556
【相近】trunc(x[,y])
返回截取后的值,用法同round(x[,y]),只是不四舍五入
trunc(x[,y])
【功能】返回x按精度y截取后的值
【参数】x,y,数字型表达式,如果y不为整数则截取y整数部分,如果y》0则截取到y位小数,如果y小于0则截取到小数点向左第y位,小数前其它数据用0表示。
【返回】数字
【示例】
select
trunc(5555.66666,2.1),trunc(5555.66666,-2.6),trunc(5555.033333)
from
dual;
返回:5555.66
5500
5555
【相近】round(x[,y])
返回截取后的值,用法同trunc(x[,y]),只是要做四舍五入

更多文章:
易语言网页api接口怎么调用(易语言,怎么读取网页json的api)
2026年10月11日 08:00
majority of(the majority of 和 a majority of的区别以及用法例句)
2026年10月11日 07:40
another time(another time和other time的区别)
2026年10月11日 05:00








