2014-10-10 102 views
1

我已經在Oracle中編寫了外連接的代碼。它給我'缺少關鍵字'錯誤Oracle中的外連接

create table Fenergo_data_01 as select tab1.* , tab2.* , tab3.*, tab4.* 
from Fenergo_ext_ref_data tab1 full outer join Fenergo_cntry_incorp_data tab2 
full outer join Fenergo_address_data tab3 
full outer join Fenergo_MCH_data tab4 
on tab1.FGO_ID = tab2.FGO_ID and tab1.FGO_ID = tab3.FGO_ID 
and tab1.FGO_ID = tab4.FGO; 

任何人都可以幫助我嗎?

回答

1

on子句必須作爲連接語句的一部分包含在內。

create table Fenergo_data_01 as 
select tab1.* , tab2.* , tab3.*, tab4.* 
from Fenergo_ext_ref_data tab1 
full outer join Fenergo_cntry_incorp_data tab2 on tab1.FGO_ID = tab2.FGO_ID 
full outer join Fenergo_address_data tab3 on tab1.FGO_ID = tab3.FGO_ID 
full outer join Fenergo_MCH_data tab4 on tab1.FGO_ID = tab4.FGO; 
1

on條款必須遵循加盟:

create table Fenergo_data_01 as select tab1.* , tab2.* , tab3.*, tab4.* 
from Fenergo_ext_ref_data tab1 full outer join Fenergo_cntry_incorp_data tab2 on tab1.FGO_ID = tab2.FGO_ID 
full outer join Fenergo_address_data tab3 on tab1.FGO_ID = tab3.FGO_ID 
full outer join Fenergo_MCH_data tab4 on tab1.FGO_ID = tab4.FGO; 

有關join語法的詳細信息,請參閱this

+0

@Downvoter:請解釋downvote。 – Jens 2014-10-10 09:45:15

2

你需要爲每個join聯接條件(在on條款),而不是像你一樣在最後:

CREATE TABLE  Fenergo_data_01 AS 
SELECT   tab1.* , tab2.* , tab3.*, tab4.* 
FROM    Fenergo_ext_ref_data tab1 
FULL OUTER JOIN Fenergo_cntry_incorp_data tab2 ON tab1.FGO_ID = tab2.FGO_ID 
FULL OUTER JOIN Fenergo_address_data tab3 ON tab1.FGO_ID = tab3.FGO_ID 
FULL OUTER JOIN Fenergo_MCH_data tab4 ON tab1.FGO_ID = tab4.FGO; 
+0

爲什麼downvote? – Mureinik 2014-10-10 10:39:25

0

一個有效的加入將是如下(加入,然後在條件)

SELECT * FROM TABA 
    JOIN TABB 
     ON TABA_SOMEID = TABB_SOMEID 

嘗試以下查詢:

create table Fenergo_data_01 as 
select tab1.* , tab2.* , tab3.*, tab4.* 
from 
    Fenergo_ext_ref_data tab1 
    full outer join 
    Fenergo_cntry_incorp_data tab2 
     on tab1.FGO_ID = tab2.FGO_ID 
     full outer join 
     Fenergo_address_data tab3 
       on tab1.FGO_ID = tab3.FGO_ID 
       full outer join 
       Fenergo_MCH_data tab4 
         on tab1.FGO_ID = tab4.FGO; 
1

你需要指定後,每ON加入,就像這樣:

create table Fenergo_data_01 as 
select tab1.* , tab2.* , tab3.*, tab4.* 
from Fenergo_ext_ref_data tab1 
full outer join Fenergo_cntry_incorp_data tab2 on tab1.FGO_ID = tab2.FGO_ID 
full outer join Fenergo_address_data tab3 on tab1.FGO_ID = tab3.FGO_ID 
full outer join Fenergo_MCH_data tab4 on tab1.FGO_ID = tab4.FGO;