Oracle中的extract()函数是从oracle 9i开始引入,用于从一个date或者interval类型的数据中截取特定的部分。 extract语法如下: - extract (
- {year | month | day | hour | minute | second}
- | {timezone_hour | timezone_minute}
- | {timezone_region | timezone_abbr}
- from {date_value | interval_value}
- )
复制代码我们只可以从一个date类型的数中截取year , month , day(date的日期是yyyy-mm-dd);我们只可以从一个timestamp with timezone的数据类型中截取timezone_hour和timezone_minute; - select extract(year from sysdate) as year from dual;
- select extract(month from sysdate) as month from dual;
- select extract(day from sysdate) as day from dual;
复制代码获取两个日期之间的具体时间间隔,extract函数是个不错的选择: - select extract(day from date1 - date2) as day,
- extract(hour from date1 - date2) as hour,
- extract(minute from date1 - date2) as minute,
- extract(second from date1 - date2) as second
- from (select sysdate + 7 date1, sysdate date2 from dual);
复制代码
|