bug笔记_oracle_无法在源表中获得一组稳定的行

ORA-30926:无法在源表中获得一组稳定的行

原因:Merge Into 语句 using表的关联字段对应多个条数据,导致修改语句无法确定以哪条数据为准(关联字段重复)

--修改a的column1字段为表b中(关联字段对应上的数据)column2的值,正常情况 b.key 值在表中不重复
merge into tableName1 a
using tableName2 b
on (a.key = b.key) 
when matched then update set a.column1 = b.column2;

解决:查询重复数据后再进行处理

select
    listagg(s.key,';') within group (order by s.key) as keyList  --用分号拼接成一个字段,也可直接写s.key列出
from (
select
        b.key,
count(b.id) as cnt --key对应的数据有几条
from tableName2 b
    group by b.key
)s
where s.cnt > 1;--取key重复的

 

 
posted @ 2022-09-23 15:20  LuLuYaa  阅读(3699)  评论(0编辑  收藏  举报