Oracle中的外部联接

时间:2014-10-10 09:14:57

标签: sql oracle outer-join

我在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;

任何人都可以帮助我吗?

5 个答案:

答案 0 :(得分: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;

答案 1 :(得分:1)

on子句必须作为join语句的一部分包含在内。

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;

答案 2 :(得分: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页面

答案 3 :(得分: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;

答案 4 :(得分: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;