2012-12-14 34 views
0

我有以下查詢:SQL查詢 - 我倒是希望限制不起作用

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 

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

但是我卻越來越不重sults當我添加的最後一個限制:

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

您正在選擇xex.xex_xexc_k,而您的測試是xexc_k。由於這是一個外部連接,他們可能會有所不同。當與xex.xex_xexc_k相比時會發生什麼?