ORACLE MERGE INTO语句,unable to get a stable set of rows in the source tables报错解决
?ORACLE數(shù)據(jù)庫(kù),MERGE INTO語(yǔ)句,經(jīng)常會(huì)出現(xiàn) ?ORA-30926: unable to get a stable set of rows in the source tables ? 這個(gè)錯(cuò)誤,如下圖所示:
?
? ? ? ?經(jīng)檢查,這個(gè)錯(cuò)誤是由于數(shù)據(jù)來(lái)源表(即語(yǔ)句中,from關(guān)鍵字后面的表)存在數(shù)據(jù)重復(fù)造成的。在實(shí)際項(xiàng)目研發(fā)中,我們一般不能隨便改動(dòng)數(shù)據(jù)表的記錄,那么如何避免這種錯(cuò)誤的產(chǎn)生以及如何改正錯(cuò)誤呢?
?
請(qǐng)看下面的SQL:
?
?MERGE INTO TEMP_ZL_ACCOUNTLIST t1
USING (select *
from (select row_number() over(partition by a.SCREEN_NAME order by a.user_id desc) rd,
a.*,
a.rowid row_id
from pprt.T_BP_ACL_USER a)
where rd = 1) t2
ON ( t1.LOGIN_NO = t2.SCREEN_NAME )
WHEN MATCHED THEN
UPDATE SET t1.user_id = t2.user_id;
?
? ? ? ?該SQL使用row_number()函數(shù),把重復(fù)記錄排序,然后子查詢(xún)只取rd=1的行,這樣的子查詢(xún)生成的記錄都是只有一條,再執(zhí)行語(yǔ)句,就高枕無(wú)憂(yōu)啦,再也不怕數(shù)據(jù)源表重復(fù)數(shù)據(jù)錯(cuò)誤提示了啊。
如果是臨時(shí)表,存在數(shù)據(jù)重復(fù),還可以將重復(fù)數(shù)據(jù)刪除,從而執(zhí)行merge不報(bào)錯(cuò)。
?
?-- 刪除重復(fù)數(shù)據(jù)
delete from dbsalesadm.mk_task_info_555 a
where rowid <> (select max(rowid)
from dbsalesadm.mk_task_info_555 b
where a.act_id = b.act_id
and a.create_date = b.create_date
and a.id_no=b.id_no)
and to_char(a.create_date,'yyyymmdd')='20131214';
?
總結(jié)
以上是生活随笔為你收集整理的ORACLE MERGE INTO语句,unable to get a stable set of rows in the source tables报错解决的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: HTML背景及边距设置
- 下一篇: lua-switch功能实现