我遇到以下问题的问题:
merge into table2 d
using (
select firstname, lastname, max(id) id
from table1 t1
group by firstname, lastname
having count(0) = 1
) s
on (d.firstname=s.firstname and d.lastname=s.lastname)
when matched then update set t1_id = s.id;
如果table2中的多行与ON子句匹配,那么我得到“SQL错误:ORA-30926:无法在源表中获得一组稳定的行”
你知道过滤器的任何方法,只是忽略那些“重复”吗? 感谢。
修改
@Polppan,您对样本数据的请求以一种非常奇怪的方式引导我:
这里有一些示例数据:
table1
ID firstname lastname
1 John Doe
2 John DOE
3 Jane Doe
4 Jane Doe
(注意UPPER)
table2
t1_ID firstname lastname
null John Doe
null Jane Doe
null Jane Doe
现在,我无法使用这些数据重现错误,直到:
知道为什么吗?
答案 0 :(得分:1)
尝试使用DISTINCT
MERGE INTO table2 d
USING (SELECT DISTINCT ((firstname))fname, ((lastname))lname,max(id) id
FROM table1 t1
GROUP BY firstname, lastname
HAVING COUNT (0) = 1
) s
ON ( upper(d.firstname) = upper(fname)
AND upper(lastname) = upper(lname))
WHEN MATCHED
THEN
UPDATE SET id = s.id;
更新1
MERGE INTO table2 d
USING (SELECT DISTINCT upper((firstname))fname, upper((lastname))lname,max(id) id
FROM table1 t1
GROUP BY firstname, lastname
HAVING COUNT (0) = 1
) s
ON ( upper(d.firstname) = upper(fname)
AND upper(lastname) = upper(lname))
WHEN MATCHED
THEN
UPDATE SET id = s.id;