oracle merge into用法
oracle merge into简单用法
merge into 目标表 b using 源表 p
on(目标表字段一 = 源表字段一
and 目标表字段二 = 源表字段二
and 目标表字段三 = 源表字段三
)
when matched then -- 当条件匹配,更新逻辑
update set b.market_basic_price =p.market_basic_price,
b.imitation_basic_price =p.imitation_basic_price,
b.applier_basic_price=p.applier_basic_price;
我这里是按照下面语句写的,具体的得自己拼条件
merge into M_BASEPRICE_0719_temp b using M_BASEPRICE_0719_temp_p p on(b.part_code_zs = p.part_code_zs and b.brand_code = p.brand_code and b.supplier_code = p.supplier_code ) when matched then update set b.market_basic_price =p.market_basic_price, b.imitation_basic_price =p.imitation_basic_price, b.applier_basic_price=p.applier_basic_price;
b表和p表的里面有6个字段是一样的,三个价格加上
part_code_zs,
brand_code ,
supplier_code
,编码相同用p表价格覆盖b表
注意:p表的数据不能重复,就是存在两条数据所有字段一模一样,重复了就报以下错误
ORA-30926:无法在源表中获得一组稳定的行
b表数据可以重复,重复项满足条件,也会被更新
merge into常见用法,匹配更新,不匹配插入,我这里只用了更新