标签:
一、作用:从一个date(日期)类型或者interval(时间区间)类型中截取指定的部分。
二、范例:
获取系统当前时间
select sysdate from dual ;
分别获取对应的年月日时分秒
(1)select (to_char(sysdate,‘YYYY‘)) from dual
(2)select (to_char(sysdate,‘YEAR‘)) from dual
(1)select (to_char(sysdate,‘MM‘)) from dual
(2)select (to_char(sysdate,‘MONTH‘)) from dual
(1)select (to_char(sysdate,‘DD‘)) from dual
(2)select (to_char(sysdate,‘DAY‘)) from dual
CREATE OR REPLACE FUNCTION xiaoxing_is_date(parameter VARCHAR2) RETURN NUMBER IS
val DATE;
BEGIN
val := TO_DATE(NVL(parameter, ‘a‘), ‘yyyy-mm-dd hh24:mi:ss‘);
RETURN 1;
EXCEPTION
WHEN OTHERS THEN
RETURN 0;
END;
select extract(year from sysdate) year from dual ;
获取date中的月
select extract(month from sysdate) month from dual ;
获取date中的天
select extract(day from sysdate) day from dual;
获取两个日期之间具体的时间间隔
select to_timestamp(‘2015-02-15 22:22:22‘,‘yyyy-mm-dd hh24:mi:ss‘) from dual ;
select to_date(‘2015-02-15 22:22:22‘,‘yyyy-mm-dd hh24:mi:ss‘) from dual ;
select to_timestamp(‘2016-02-15 22:22:22‘, ‘yyyy-mm-dd hh24:mi:ss‘) -
to_timestamp(‘2016-01-04 10:55:55‘, ‘yyyy-mm-dd hh24:mi:ss‘)
from dual;
select to_date(‘2016-02-15 22:22:22‘, ‘yyyy-mm-dd hh24:mi:ss‘) -
to_date(‘2016-01-04 10:55:55‘, ‘yyyy-mm-dd hh24:mi:ss‘)
from dual;
select systimestamp from dual ;
select extract(year from systimestamp) year
,extract(month from systimestamp) month
,extract(day from systimestamp) day
,extract(minute from systimestamp) minute
,extract(second from systimestamp) second
,extract(timezone_hour from systimestamp) th
,extract(timezone_minute from systimestamp) tm
,extract(timezone_region from systimestamp) tr
,extract(timezone_abbr from systimestamp) ta
from dual ;
标签:
原文地址:http://www.cnblogs.com/yaoxiaoxing/p/5109892.html