[英]Ignoring duplicates when updating multiple rows in PL/SQL in Oracle SQL Developer
我正在嘗試更新與另一個表(B)的ID匹配的表(A)的所有行。 問題是我遇到以下錯誤:
無法在源表中獲得穩定的行集
我已經進行了研究,並且知道原因可能是其中一張表中的行重復。 只有表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;
有人可以幫忙嗎?
提前致謝
重復項可以在進行更新的一側。 但是在源端不能有重復項。
考慮一下,他們sql引擎不知道在更新中使用多個記錄中的哪個。 您需要解決重復的問題。 或者執行某種最大值或最小值來獲取要在更新中使用的唯一數據集。
我能夠解決此問題,這是我所做的解決方案:
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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.