--语法如下
merge into qcfang.bbb b using(select * from qcfang.aaa) a
on (b.a_id=a.a_id)
when matched then
update set
b.a_name=a.a_name, b.a_sex = a.a_sex, b.a_type = a.a_type,b.a_salary = a.a_salary
when not matched then
insert
(b.a_id,b.a_name,b.a_sex,b.a_type,b.a_salary)
values
(a.a_id,a.a_name,a.a_sex,a.a_type,a.a_salary);
commit;
注意:
1、merge为dml操作,没必要在存储过程里写动态sql来实现,动态sql性能相对于静态sql来说效果要差一些;
2、不能update两表关联的key值;
本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/
时间: 2025-01-30 06:33:40