2

我很难针对这种情况修改脚本,并且想知道是否有人可以提供帮助:

我有一张address桌子和一张phone桌子都共享同一个名为 id_number. 所以id_number = 2在两个表上都指的是同一个实体。过去,地址和电话信息存储在一个表(表)中,但自从我们迁移到 Oracle 11g 后,address它现在被拆分为表。addressphone

有一个名为 3 的表both_idsid_number除了other_ids存储列SSN和一些其他 id之外,该表还有一个列。

在将表拆分为addressphone表之前,我有这个脚本:(用 Sybase 编写)

INSERT INTO sometable_3 (          
SELECT a.id_number, a.other_id, 
       NVL(a1.addr_type_code,0)      home_addr_type_code,             
       NVL(a1.addr_status_code,0)    home_addr_status_code,             
       NVL(a1.addr_pref_ind,0)      home_addr_pref_ind,             
       NVL(a1.street1,0)             home_street1,             
       NVL(a1.street2,0)              home_street2,             
       NVL(a1.street3,0)              home_street3,             
       NVL(a1.city,0)                 home_city,             
       NVL(a1.state_code,0)           home_state_code,             
       NVL(a1.zipcode,0)              home_zipcode,             
       NVL(a1.zip_suffix,0)           home_zip_suffix,             
       NVL(a1.telephone_status_code,0) home_phone_status,             
       NVL(a1.area_code,0)             home_area_code,             
       NVL(a1.telephone_number,0)      home_phone_number,             
       NVL(a1.extension,0)             home_phone_extension,             
       NVL(a1.date_modified,'')      home_date_modified               
 FROM both_ids a, address a1          
 WHERE a.id_number = a1.id_number(+) 
 AND a1.addr_type_code = 'H');   

现在我们迁移到 Oracle 11g,地址和电话信息被拆分了。

如何修改上述脚本以在 Oracle 11g 中生成相同的结果?

我是否必须首先在地址表和电话表之间进行 INNER JOIN,然后对 both_ids 进行 LEFT OUTER JOIN?

我尝试了以下方法,但没有奏效:

Insert Into..
  select ...
    FROM a1. address
      INNER JOIN t.Phone ON a1.id_number = t.id_number
      LEFT OUTER JOIN both_ids a ON a.id_number = a1.id_number
    WHERE a1.adrr_type_code = 'H'
4

1 回答 1

1

您的查询中有语法错误。您在下面的评论中写道,您的查询是:

 ..
 FROM address a1 JOIN telephone t ON a1.id_number = t.id_number
 AND RIGHT OUTER JOIN tt_gl_both_ids a ON a.id_number = a1.id_number
 WHERE
 ..

扔掉AND它就会起作用。此外,将右外连接替换为左外连接,因为这就是您要实现的目标(同样,基于您编写的评论)。

于 2012-09-06T15:48:26.807 回答