首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

ORACLE日期函数汇总

2012-07-23 
ORACLE日期函数集锦?This Month----------5SQL select extract(year from sysdate) This year from dua

ORACLE日期函数集锦


?

This Month
----------
5
SQL> select extract(year from sysdate) "This year" from dual;

This year
----------
2007
SQL> select extract(month from add_months(sysdate,2)) " Month" from dual;

Month
----------
7


==================================================================

三、一些实践后的用法:

1.上月末天:
select to_char(add_months(last_day(sysdate),-1),'yyyy-MM-dd') LastDay from dual;

2.上月今天
SQL> select to_char(add_months(sysdate,-1),'yyyy-MM-dd') PreToday from dual;

3.上月首天
SQL> select to_char(add_months(last_day(sysdate)+1,-2),'yyyy-MM-dd') firstDay from dual;

4.要找到某月中所有周五的具体日期

SELECT to_char(b.a,'YY-MM-DD')
FROM ( SELECT trunc(SYSDATE,'mm')+ROWNUM-1 a
FROM dba_objects where rownum < 32 ) b
WHERE to_char(b.a,'day')='星期五';


如果把where to_char(t.d, 'MM') = to_char(sysdate, 'MM')改成sysdate-90,即为查找当前月份的前三个月中

的每周五的日期。


5.得到系统当前月及以后的日期

select trunc(sysdate, 'MM')+ROWNUM-1 FROM dba_objects ;

?

-----------------------------------

to_date 字符串类型转为换日期类型
字符串中的相应位置上的字符,必须符合时间范围的限制??

14.MI 分钟数(0~59)
提示注意不要将MM格式用于分钟(分钟应该使用MI)。MM是用于月份的格式,将它用于分钟也能工作,但结果是错误的。

15.SS 秒数(0~59)

?

热点排行