|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729846
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2016/9/14 9:50 |
- 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 (+) 用法
|
|
|
討論串
-
[轉貼]MSSQL Join總結 (冷日 (冷日), 2010/10/23 12:21)
-
[轉貼][MySQL] outer join 使用 (冷日 (冷日), 2012/11/13 7:40)
-
[轉貼][MySQL]left, right, inner, outer join 使用方法 (冷日 (冷日), 2012/11/13 7:45)
-
[分享]一些來自 MySql 官網上的討論範例,超實用! (冷日 (冷日), 2012/11/13 8:08)
- »
[轉貼]Oracle PL/SQL SELECT 的 OUT JOIN (+) 用法 (冷日 (冷日), 2016/9/14 9:50)
-
[轉貼]SQL Join 的觀念 (冷日 (冷日), 2018/12/12 4:57)
-
[轉貼]SQL inner join、full out join、left join 的觀念 (冷日 (冷日), 2018/12/12 5:01)
|