正常工作或生产环境有可能会碰到以下这种情况:
将表table1中的数据定时同步到表table2中,如果table2中已经有表table1的数据了,那么就将表table2中的数据更新成和表table1一样,如果表table2中不存在,那么就将表table1中的数据插入到table2中
针对以上场景就可以使用以下语法,既方便有快捷

create or replace procedure ZK_MEMBER  isbeginMERGE INTO  v_zhongke5 M
​
using (
​
​
​
      select id,name,riqi,statu from v_zhongke4 where statu=0) N
​
on (M.id=N.id)when matched thenupdate  set M.statu=0,M.riqi=N.riqi where M.name=N.name
​
when not matched theninsert (id,name,riqi,statu)values(N.id,N.name,N.riqi,N.statu);update v_zhongke4 set statu=1;commit;end ;

在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐