--根据当前时间戳获取年月日时分秒,其中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比较两个时间,是最好的选择

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

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

 

posted on 2019-04-17 10:17  一粒麦子777  阅读(1125)  评论(0编辑  收藏  举报