2016-09-14 31 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引擎不知道在更新上使用多個記錄中的哪一個。您需要修復重複的問題。或者做一些最大值或最小值來獲取更新中要使用的唯一數據集。