ORACLE MERGE INTO语句,unable to get a stable set of rows in the source tables报错解决
?ORACLE數(shù)據(jù)庫,MERGE INTO語句,經(jīng)常會出現(xiàn) ?ORA-30926: unable to get a stable set of rows in the source tables ? 這個錯誤,如下圖所示:
?
? ? ? ?經(jīng)檢查,這個錯誤是由于數(shù)據(jù)來源表(即語句中,from關(guān)鍵字后面的表)存在數(shù)據(jù)重復(fù)造成的。在實(shí)際項(xiàng)目研發(fā)中,我們一般不能隨便改動數(shù)據(jù)表的記錄,那么如何避免這種錯誤的產(chǎn)生以及如何改正錯誤呢?
?
請看下面的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ù)記錄排序,然后子查詢只取rd=1的行,這樣的子查詢生成的記錄都是只有一條,再執(zhí)行語句,就高枕無憂啦,再也不怕數(shù)據(jù)源表重復(fù)數(shù)據(jù)錯誤提示了啊。
如果是臨時表,存在數(shù)據(jù)重復(fù),還可以將重復(fù)數(shù)據(jù)刪除,從而執(zhí)行merge不報錯。
?
?-- 刪除重復(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报错解决的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML背景及边距设置
- 下一篇: xpath用于HTML文档通过元素,理解