Oracle use LIKE '%' on DATE

后端 未结 8 1879
灰色年华
灰色年华 2021-01-12 02:52

My table myTab has the column startDate, which has the datatype \"DATE\". The data in this column are stored like dd.mm.yyyy.

8条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 03:10

    If the field type is "DATE" then the value isn't stored as a string, it's a number managed by Oracle, so you have to convert it to a string:

    SELECT * FROM myTab WHERE to_char(startDate, 'MM.YYYY') = '01.2015';
    

    You can also use date ranges in SQL queries:

    SELECT * FROM myTab 
    WHERE startDate 
    BETWEEN to_date('01.01.2015', 'DD.MM.YYYY') 
    AND     to_date('31.01.2015', 'DD.MM.YYYY');
    

提交回复
热议问题