oracle使用 extract获取当前时间,并比较两个时间

--根据当前时间戳获取年月日时分秒,其中sysdate不能用于获取时分秒
select
systimestamp, extract(year from systimestamp) year ,extract(month from systimestamp) month ,extract(day from systimestamp) day ,extract(hour from cast(systimestamp as timestamp)) hour ,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
  • 使用extract比较两个时间,是最好的选择

    比较两个时间之间相差得小时数,代码以下:spa

1 select t.* from tableName t where EXTRACT(day FROM(systimestamp - t.update_date))*24+
EXTRACT(hour FROM(systimestamp - t.update_date))+
EXTRACT(minute FROM(systimestamp - t.update_date))/60+
EXTRACT(second FROM(systimestamp - t.update_date))/60/60)>=2

 

相关文章
相关标签/搜索