Oracle use LIKE '%' on DATE

后端 未结 8 1876
灰色年华
灰色年华 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:19

    The data in this column are stored like dd.mm.yyyy.

    Oracle does not store date in the format you see. It stores it internally in proprietary format in 7 bytes with each byte storing different components of the datetime value.

    WHERE startDate like '%01.2015"

    You are comparing a DATE with a STRING, which is pointless.

    From performance point of view, you should use a date range condition so that if there is any regular INDEX on the date column, it would be used.

    SELECT * FROM table_name WHERE date_column BETWEEN DATE '2015-01-01' AND DATE '2015-02-01'
    

    To understand why a Date range condition is better in terms of performance, have a look at my answer here.

提交回复
热议问题