注意事項: Oracle Not Exists 及 Not In 使用


select value from temp_a a
where a.id between 1 and 100
and not exists(select * from temp_b b where a.value=b.value);

這時能查出結果

select value from temp_a a
where a.id between 1 and 100
and a.value not in(select value from temp_b);

此時查出的結果為空.

經過google終於找出原因: 內表(temp_b)有空值. 用not in得到的結果集都為空.以下是結論:

1、對於not exists查詢,內表存在空值對查詢結果沒有影響;對於not in查詢,內表存在空值將導致最終的查詢結果為空。

2、對於not exists查詢,外表存在空值,存在空值的那條記錄最終會輸出;對於not in查詢,外表存在空值,存在空值的那條記錄最終將被過濾,其他數據不受影響。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM