[英]how to filter a db for datetime in sqldeveloper
我需要為特定的時間間隔精確篩選表。 數據類型為“ TIMESTAMP(6)”
select *
from table
where trunc(load_date)<=to_date ('10.08.15 15:10:58', 'dd.mm.yy hh24:mi:ss')
and trunc(load_date)>=to_date ('10.08.15 15:11:08', 'dd.mm.yy hh24:mi:ss');
這是怎么回事。 但我似乎想念smt。
select *
from b_bis_donexa_delta_2
where trunc(load_date)=to_date ('10.08.15', 'dd.mm.yy');
這工作得很好。 但是匯總結果並不是很有效。
atm我沒有結果,但是沒有錯誤消息。 但至少有一個結果。 我什至試圖隨機交換這些<=>,因為我以為我迷失了方向。
進行trunc(load_date)
時間截斷到該值當天的午夜(並且還轉換為日期,而不是時間戳):
select systimestamp, trunc(systimestamp) from dual;
SYSTIMESTAMP TRUNC(SYSTIMESTAMP)
------------------------------------ -------------------
2019-09-10 12:53:54.400453000 +01:00 2019-09-10 00:00:00
截斷load_date
,該午夜時間不在目標范圍內。 在您的第二個版本中,您正在將截斷后的值與也在午夜的時間進行比較,因此現在可以找到匹配項-但它可能在或可能不在您的10秒窗口中(無法分辨),並且可能防止使用該列上的索引-這可能是為什么它很慢的原因。
不要截斷; 我將比較相同的數據類型:
select *
from table
where load_date >= to_timestamp ('10.08.15 15:10:58', 'dd.mm.yy hh24:mi:ss')
and load_date <= to_timestamp ('10.08.15 15:11:08', 'dd.mm.yy hh24:mi:ss');
或最好使用4位數的年份:
select *
from table
where load_date >= to_timestamp ('10.08.2015 15:10:58', 'dd.mm.yyyy hh24:mi:ss')
and load_date <= to_timestamp ('10.08.2015 15:11:08', 'dd.mm.yyyy hh24:mi:ss');
甚至是時間戳字面量(如果它們是固定值):
select *
from table
where load_date >= timestamp '2015-08-10 15:10:58'
and load_date <= timestamp '2015-08-10 15:11:08';
還要檢查您是否確實確實想要>=
和<=
; 如果要獲得多個10秒范圍,則實際上可能需要>=
和<
以避免確切的時間出現在兩個范圍內。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.