欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

oracle merge

程序员文章站 2022-03-07 15:21:03
...

merge into carpt.T_FT_WGJYL t
using (
select trunc(gpo.creationdate) creationdate,substr(gpo.memberacctcode,1,11) membercode,gpo.bosstype,sum(gpo.realamount)/1000 successfulamount from T_D_GATEWAYPAYORDER gpo
where
gpo.creationdate >= v_s_date
and gpo.creationdate < v_e_date
and gpo.orderstatus=111
and gpo.cardno is not null
group by trunc(gpo.creationdate),gpo.memberacctcode,gpo.bosstype
)  s
ON (t.datetime=s.creationdate and t.membercode=s.membercode and t.bosstype=s.bosstype)
WHEN MATCHED THEN
  UPDATE
     Set t.successfulamount=s.successfulamount
   WHERE t.datetime=s.creationdate and t.membercode=s.membercode and t.bosstype=s.bosstype
WHEN NOT MATCHED THEN
  INSERT
  VALUES(s.creationdate,s.membercode,s.bosstype,s.successfulamount)
;

相关标签: Oracle