Merge into 表A A Using(select * from 表B) B on A.ID=B.ID when Matched then update set name=B.name when not Matched then insert (A.Name) values(B.Name);--最重要的就是在A.ID和B.ID上建立索引,最好应该是B树索引.
找到原因了,是因为我再using里面的select语句有group by,去掉了就快了。 但是发现有问题: 1.在merge的时候,好像on里面的条件,不会检查这次的insert的内容,比如说using里面有两条记录,A|10,A|20,on的条件是第一个字段相等,符合的时候第二个字段相加,但是merge出来的结果是A|10,A|20,而我期望的结果是A|30。 2.在把A表的内容merge到B表(merge前为空)里面后,在保留B表内容的同时,重新在把A表的内容merge到B表内,报错30926ORA-30926: unable to get a stable set of rows in the source tables
Using(select * from 表B) B
on A.ID=B.ID
when Matched then
update set name=B.name
when not Matched then
insert (A.Name) values(B.Name);--最重要的就是在A.ID和B.ID上建立索引,最好应该是B树索引.
但是发现有问题:
1.在merge的时候,好像on里面的条件,不会检查这次的insert的内容,比如说using里面有两条记录,A|10,A|20,on的条件是第一个字段相等,符合的时候第二个字段相加,但是merge出来的结果是A|10,A|20,而我期望的结果是A|30。
2.在把A表的内容merge到B表(merge前为空)里面后,在保留B表内容的同时,重新在把A表的内容merge到B表内,报错30926ORA-30926: unable to get a stable set of rows in the source tables