现在的位置: 首页 > 综合 > 正文

oracle中的函数(二) 日期函数

2013年11月26日 ⁄ 综合 ⁄ 共 715字 ⁄ 字号 评论关闭

oracle中的日期函数

add_months(d,n)
在日期d的基础上加n个月
select hiredate,add_months(hiredate,3) from emp;
months_between(d,e)
select hiredate,months_between(hiredate,sysdate) from emp;
日期d和e之间相差的多少个月,用d的日期减去e的日期

last_day(d)
该日期所在月份的最后一天的日期
select last_day(sysdate) from dual;
next_day(d,weekday)
从今天开始下一个星期几的日期是多少
select next_day(sysdate,'星期一') from dual;

round(d[,fmt])
对时间进行四舍五入,默认的参数是'dd'
select hiredate,round(hiredate,'mm') from emp;

trunc(d[,fmt])
对时间按照参数进行归1,默认的参数是'dd'
select hiredate,trunc(hiredate,'yy') from emp;

extract(c from d)
extract函数可以提取日期或者时间帖中的所有组成部分,参数d可以是date、timestamp、interval,参数c可以是year、month、day、hour、minute、second、timezone_abbr等

select hiredate,extract(year from hiredate) year_of_birth,
extract(month from hiredate),
extract(day from hiredate)  from emp;

 

抱歉!评论已关闭.