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

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_0046.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2016/9/14 9:50:03
對於 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 (+) 用法
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

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