extract --提取函数
--获取年月日
select extract(year from systimestamp) year
,extract(month from systimestamp) month
,extract(day from systimestamp) day
from dual
--获取小时
select extract (hour from timestamp'2017-06-09 21:11:11') from dual
select to_char(systimestamp, 'YYYY-MM-DD HH24:MI:SS.FF9') from dual
select to_char(systimestamp, 'HH24') from dual
--获取两个日期之间的间隔
select extract(day from dt2 - dt1) day
,extract(hour from dt2 - dt1) hour
,extract(minute from dt2 - dt1) minute
,extract(second from dt2 - dt1) second
from (select to_timestamp('2013-07-10 21:00:0', 'yyyy-mm-dd hh24:mi:ss') dt1
,to_timestamp('2017-06-8 14:07:00', 'yyyy-mm-dd hh24:mi:ss') dt2
from dual)```
网友评论