date_col between to_date('16-10-2005','DD-MM-YYYY')
and to_date('16-10-2005','DD-MM-YYYY')
は、2005 年 10 月 16 日の午前 0 時の値のみを返しDATE
ます。2005 年 10 月 16 日の任意の時刻のデータを取得する場合
date_col between to_date('16-10-2005','DD-MM-YYYY')
and to_date('16-10-2005 23:59:59','DD-MM-YYYY HH24:MI:SS')
やります。そうでしょう
date_col between to_date('16-10-2005','DD-MM-YYYY')
and to_date('17-10-2005','DD-MM-YYYY') - interval '1' second
その秒を差し引かないとdate_col
、2005 年 10 月 17 日の午前 0 時の値を持つ行も取得することになります。
trunc
に関数を適用することもできますdate_col
trunc(date_col) = date '2005-10-16'
しかし、それでは標準のインデックス ondate_col
を使用できなくなります。通常、関数ベースのインデックスを作成する必要がありますtrunc(date_col)
CREATE INDEX idx_trunc_date_col
ON table_name( trunc(date_col) );