SQL查询 - 限制不能像我期望的那样工作

时间:2012-12-14 11:33:17

标签: sql oracle

我有以下查询:

SELECT 
(substr(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,'), 2, length(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,')) - 2)) ,
xex.xex_xexc_k,
  FROM qot, sec, exc, ctr, xcx, xex, xexc, xcrr, crr
 WHERE qot_source = 'X'
       AND qot_id = 2029557521
       AND nvl(qot_real_exc_id, qot_exc_id) = exc_id
       AND exc_ctr_id = ctr_id
       AND qot_sec_id = sec_id
       AND nvl(qot_real_exc_id, qot_exc_id) = xex_exc_id(+)
       AND qot_crr_id = xcx_crr_id(+)
       AND xex_xexc_k = xexc_k(+)
       AND xcx_xcrr_k = xcrr_k(+)
       AND qot_crr_id = crr_id(+)
       AND qot_status IN (1, 2)
      AND (qot_sup_xpressfeed IS NULL OR to_number(substr(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,'), 2, length(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,')) - 2)) = xexc_k);

当我注释掉最后一个限制AND (qot_sup_xpressfeed IS NULL OR to_number(substr(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,'), 2, length(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,')) - 2)) = xexc_k);时,我得到了结果:

1135    67
1135    111
1135    549
1135    246
1135    103
1135    564
1135    1135
1135    21

所以你可以看到我有一排:

1135 1135

但是当我添加最后一个限制时,我没有得到任何结果:

 AND (qot_sup_xpressfeed IS NULL OR to_number(substr(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,'), 2, length(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,')) - 2)) = xexc_k);

我希望我会得到1个结果(提到的1135 1135)。 我做错了什么?

1 个答案:

答案 0 :(得分:1)

当您的考试在xex.xex_xexc_k时,您正在选择xexc_k。由于这是一个外部联接,他们可能会有所不同。与xex.xex_xexc_k进行比较时会发生什么?