[SQL] 針對特定時間區間做搜尋 (如2009/01/01~2009/12/31的 0:00~2:00)

  • 18158
  • 0

[SQL] 針對特定時間區間做搜尋 (如2009/01/01~2009/12/31的 0:00~2:00)

除了基本的判斷時間是否在日期範圍之內外,只要在對小時部份 (hh24) 特別判斷是否在範圍之內即可 (in (0,1))

 

select *
from my_table
where date_data > to_date('2009-01-01 00:00:00','yyyy/mm/dd hh24:mi:ss') 
and date_data < to_date('2009-12-31 00:00:00','yyyy/mm/dd hh24:mi:ss') 
and to_char(date_data ,'hh24') in (0,1);