2016-09-14 66 views
0

我试图在与另一个表(B)的ID匹配时更新表(A)的所有行。问题是,我发现了以下错误:在Oracle SQL Developer中更新PL/SQL中的多行时忽略重复记录

无法获得源表中一组稳定的行

我做了我的研究,我知道原因可能重复的行在其中一个表格中。只有表B有重复的行,我试图以某种方式忽略它们,但不成功。

merge into A x 
    using B y 
    on (x.id= y.id) 
    when matched then 
     UPDATE SET 
     x.apples= y.apples, 
     x.bananas= y.bananas, 
     x.grapes= y.grapes; 

有人可以帮忙吗?

在此先感谢

+0

有一个在你的问题没有PL/SQL。 –

回答

0

我能解决这个问题,这是我提出的解决方案:

merge into A x 
     using (select distinct id from B) y 
     on (x.id= y.id) 
     when matched then 
      UPDATE SET 
      x.apples= (select apples from B where id = 
(select distinct id from B where id = x.id) and rownum = '1'), 
      x.bananas= (select bananas from B where id = 
(select distinct id from B where id = x.id) and rownum = '1'), 
      x.grapes= (select grapes from B where id = 
(select distinct id from B where id = x.id) and rownum = '1'); 
0

重复可以在您正在进行更新的一侧。 但是你不能在源端重复。
想想看,他们sql引擎不知道在更新上使用多个记录中的哪一个。您需要修复重复的问题。或者做一些最大值或最小值来获取更新中要使用的唯一数据集。