1、 SYSTATE
用来返回系统当前时间
SQL> select sysdate from dual;
SYSDATE
-------------------
2017-03-03 09:49:25
2、 ADD_MONTHS
语法: ADD_MONTHS(date,integer)
用于从一个日期值增加或减少一些月份
1) 返回系统时间一个月后的日期
SQL> select sysdate,add_months(sysdate,1) as "months+1" from dual;
SYSDATE months+1
------------------- -------------------
2017-03-03 09:52:43 2017-04-03 09:52:43
2) 返回系统时间一年后的日期
SQL> select sysdate,add_months(sysdate,12) as "months+12" from dual;
SYSDATE months+12
------------------- -------------------
2017-03-03 09:53:57 2018-03-03 09:53:57
3) 返回指定时间1月后的日期
SQL> select add_months('20170102',1) from dual;
ADD_MONTHS('2017010
-------------------
2017-02-02 00:00:00
3、 LAST_DAY
语法: LAST_DAY(date)
返回包含了日期参数的月份的最后一天的日期
SQL> select sysdate,last_day(sysdate) "last" from dual;
SYSDATE last
------------------- -------------------
2017-03-03 14:52:27 2017-03-31 14:52:27
4、 CURRENT_DATE
返回当前会话时区中的当前日期
SQL> select dbtimezone,sessiontimezone,current_date from dual;
DBTIME SESSIONTIM CURRENT_DATE
------ ---------- -------------------
+00:00 +08:00 2017-03-03 14:55:06
5、 MONTHS_BETWEEN
语法:MONTHS_BETWEEN(date1,date2)
返回两个日期之间的月份数
SQL> select months_between('20110301','20110201') as mb from dual;
MB
----------
1
6、 NEXT_DAY
语法:NEXT_DAY(date,char)
返回由第二个参数指出的日子第一次出现的日期值
SQL> select next_day('2017-3-3','Friday') "next day" from dual;
next day
-------------------
2017-03-10 00:00:00
SQL> select next_day('2017-3-3',6) "next day" from dual;
next day
-------------------
2017-03-10 00:00:00
注: 1-7:代表周日-周六。
7、 TRUNC
语法:TRUNC(date,fmt)
按照给出的要求将日期截断
1) trunc函数处理日期,没有fmt参数,默认截取到日
SQL> select trunc(sysdate) from dual;
TRUNC(SYSDATE)
-------------------
2017-03-03 00:00:00
2) 时间截取到小时,分钟
SQL> select trunc(sysdate,'hh') "hh",trunc(sysdate,'mi') "mi" from dual;
hh mi
------------------- -------------------
2017-03-03 15:00:00 2017-03-03 15:34:00
3) 返回本周周一
SQL> select trunc(sysdate,'iw') from dual;
TRUNC(SYSDATE,'IW')
-------------------
2017-02-27 00:00:00
4) 返回本周周日
SQL> select trunc(to_date('2008.08.08','yyyy.mi,ss'),'d') from dual;
TRUNC(TO_DATE('2008
-------------------
2008-02-24 00:00:00
8、 ROUND
SQL> select round(dd,'month'),round(dd,'year'),trunc(dd,'month'),trunc(dd,'year') from
2 (select to_date('2008-08-15','yyyy-mm-dd')as dd from dual);
ROUND(DD,'MONTH') ROUND(DD,'YEAR') TRUNC(DD,'MONTH') TRUNC(DD,'YEAR')
------------------- ------------------- ------------------- -------------------
2008-08-01 00:00:00 2009-01-01 00:00:00 2008-08-01 00:00:00 2008-01-01 00:00:00