【发布时间】:2011-12-17 16:46:12
【问题描述】:
我遇到了 Oracle DBMS 的奇怪行为。 使用下面引用的 SQL,结果集为空。如果我删除“this_.order_date >=" 条件中的任何一个 - 它会返回预期的 2 行。
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”有助于解决此问题。问题是我无法在实际应用中添加这个提示,如上所述。
【问题讨论】:
-
您是否指的是 ">=" 条件中的任何一个?因为只有一个“
-
@DmitrySidorenko:您能否编辑问题以包含修改后的查询有效时返回的数据?
-
@Glenn,你是对的,">="
-
>=to_timestamp('12/13/2011', 'mm/dd/yyyy')AND>=to_timestamp('12/15/2011'没有任何意义。 >= '12/13/2011' 仅适用于与第二个条件匹配的行。所以不需要第一个>= '12/13/2011' -
@a_horse_with_no_name,谢谢,我知道了。