我遇到了Oracle DBMS的奇怪行爲。 以下引用的SQL結果集爲空。如果我刪除了「this_.order_date> =」條件 - 它會返回預期的2行。問題與Oracle 11.2.0.2.0中的日期比較
SELECT DISTINCT this_.id AS y0_,
this_.order_date AS y1_
FROM flight_trip_orders this_,
int_work_order_info iwoi1_,
state_history_records cs2_
WHERE this_.work_info_id =iwoi1_.id
AND iwoi1_.state_history_records_id=cs2_.id
AND this_.order_date <=to_timestamp('12/16/2011', 'mm/dd/yyyy')
AND this_.order_date >=to_timestamp('12/13/2011', 'mm/dd/yyyy')
AND this_.order_date >=to_timestamp('12/15/2011', 'mm/dd/yyyy')
AND rownum <=2;
這是怎麼發生的?查詢結果在兩個不同的Oracle實例上是不同的,但都是版本11.2.0.2.0
請不要建議優化查詢和刪除條件 - 查詢已生成,我無權更改它。
編輯: 添加提示「ALL_ROWS」有助於解決問題。問題在於,我無法在實際應用中添加此提示,如上所述。
您是不是指「> =」條件?因爲只有一個「<=」條件,並且刪除允許未來任何日期記錄的條件。 – Glenn 2011-12-15 13:43:30
@DmitrySidorenko:您可以編輯問題以包含在修改後的查詢工作時返回的數據嗎? – 2011-12-15 14:06:05
@Glenn,你是對的,「> =」 – 2011-12-15 14:19:58