Oracle: SQL select date with timestamp

前端 未结 2 562
[愿得一人]
[愿得一人] 2021-02-06 13:31

I have the following data:

SQL> select * from booking_session;

BK_ID|BK_DATE
-----|-------------------------
    1|18-MAR-12 10.00.00.000000
    2|18-MAR-12          


        
2条回答
  •  一个人的身影
    2021-02-06 14:34

    You can specify the whole day by doing a range, like so:

    WHERE bk_date >= TO_DATE('2012-03-18', 'YYYY-MM-DD')
    AND bk_date <  TO_DATE('2012-03-19', 'YYYY-MM-DD')
    

    More simply you can use TRUNC:

    WHERE TRUNC(bk_date) = TO_DATE('2012-03-18', 'YYYY-MM-DD')
    

    TRUNC without parameter removes hours, minutes and seconds from a DATE.

提交回复
热议问题