Oracle comparing timestamp with date

后端 未结 3 658
抹茶落季
抹茶落季 2020-12-29 03:31

I have a timestamp field and I just want to compare the date part of it in my query in Oracle

How do I do that,

SELECT *
FROM Table1
WHERE date(field         


        
3条回答
  •  萌比男神i
    2020-12-29 04:10

    You can truncate the date part:

    select * from table1 where trunc(field1) = to_date('2012-01-01', 'YYYY-MM-DD')
    

    The trouble with this approach is that any index on field1 wouldn't be used due to the function call.

    Alternatively (and more index friendly)

    select * from table1 
     where field1 >= to_timestamp('2012-01-01', 'YYYY-MM-DD') 
       and field1 < to_timestamp('2012-01-02', 'YYYY-MM-DD')
    

提交回复
热议问题