not in 用外連線實現

wei-xh發表於2012-02-01
* from test;
        ID       NAME
---------- ----------
         1          2
         2          3
* from test1;
        ID       NAME
---------- ----------
         1          2
         2          3

  2  test.*
  3  from
  4  test,
  5  test1
  6  where
  7  test1.id(+) = test.id
  8  and test1.name(+) = 2
  9  and test1.id is null
 10  ;
        ID       NAME
---------- ----------
         2          3
        
等價於:
select test.*
from test
where test.id not in (
select test1.id
from test1
where test1.name = 2
)
;
* from
  2  test,
  3  test1
  4  where
  5  test1.id(+) = test.id
  6  and test1.name(+) = 2;
        ID       NAME         ID       NAME
---------- ---------- ---------- ----------
         1          2          1          2
         2          3
* from
  2  test,
  3  test1
  4  where
  5  test1.id(+) = test.id;
        ID       NAME         ID       NAME
---------- ---------- ---------- ----------
         1          2          1          2
         2          3          2          3
連線以後。對於test1.name不為2的記錄,整條記錄用null值代替。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22034023/viewspace-715426/,如需轉載,請註明出處,否則將追究法律責任。

相關文章