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
);