茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1729846 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
PIMG_00217.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

DB研討會 : [轉貼]MSSQL Join總結

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15773
[轉貼]Oracle PL/SQL SELECT 的 OUT JOIN (+) 用法
對於 Oracle Out Join (+) 的用法,是將 (+) 放置在可能沒有資料的 Table 一方,

範例如下 :
-- 建立 Temp Table
create table tom1(
  aa number
, bb varchar2(100)
);

create table tom2(
  aa number
, cc varchar2(100)
);

create table tom3(
  cc varchar2(100)
, dd varchar2(100)
);

-- 建立 Temp Data
insert into tom1 values( 1, 'A' );
insert into tom1 values( 2, 'B' );
insert into tom1 values( 3, 'C' );
insert into tom1 values( 4, 'D' );
insert into tom1 values( 5, 'E' );

insert into tom2 values( 1, 'I' );
insert into tom2 values( 3, 'J' );
insert into tom2 values( 5, 'K' );

insert into tom3 values( 'J', 'JJJ' );
insert into tom3 values( 'K', 'KKK' );

commit;

-- 查詢 tom1 有, 且 tom2 也要有的資料, 同時也抓出 tom2 在 tom3 的 dd 欄位值
select t1.aa
     , t1.bb
     , t2.cc
     , t3.dd
  from tom1 t1
     , tom2 t2
     , tom3 t3
 where t1.aa = t2.aa
   and t2.cc = t3.cc(+)  -- (+) 放置在可能沒有資料的 Table 一方
 order by t1.aa;

-- 結果
AA     BB     CC     DD
------ ------ ------ ------
1      A      I      (null)
3      C      J      JJJ
5      E      K      KKK

-- 查詢 tom1 有, 但 tom2 可有可無的資料, 同時也抓出 tom2 在 tom3 的 dd 欄位值
select t1.aa
     , t1.bb
     , t2.cc
     , t3.dd
  from tom1 t1
     , tom2 t2
     , tom3 t3
 where t1.aa = t2.aa(+)  -- (+) 放置在可能沒有資料的 Table 一方
   and t2.cc = t3.cc(+)  -- (+) 放置在可能沒有資料的 Table 一方
 order by t1.aa;

-- 結果
AA     BB     CC     DD
------ ------ ------ ------
1      A      I      (null)
2      B      (null) (null)
3      C      J      JJJ
4      D      (null) (null)
5      E      K      KKK


原文出處:昭佑.天翔: Oracle PL/SQL SELECT 的 OUT JOIN (+) 用法
前一個主題 | 下一個主題 | | | |

討論串




Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|