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

 

相關文章
相關標籤/搜索