Oracle 11g学习笔记–MERGE
oracle database 9i引入了merge语句,它可以用来将一个表中的行合并到另一个表中;
merge into products p--要执行合并操作的目标表
using product_changes pc on(--指定要被合并的表
p.product_id = pc.product_id --合并条件:当id相等时
)
when matched then -- 符合条件时,更新数据
update
set p.product_type_id = pc.product_type_id,
p.name = pc.name,
p.description = pc.description,
p.price = pc.price
when not matched then -- 不符合条件时,增加数据
insert (
p.product_id,p.product_type_id,p.name,p.description,p.price)
values(
pc.product_id,pc.product_type_id,pc.name,pc.description,pc.price
);