zoukankan      html  css  js  c++  java
  • Oracle 带回滚的存储过程

    create or replace procedure PROC_insertUserAmount
    (
         userid  number,
         msgtype number,
         amountvalue number,
         financeType  number,
         createUserid number,
         msgId nvarchar2,
         remark nvarchar2,
         addtime date
    )
    is
         v_cnt number;
         v_beforevalue number;
         v_aftervalue number;
         v_userid number;
         v_msgtype number;
    begin
      v_userid:=userid;
       v_msgtype:=msgtype;
    
    
       select count(*)into v_cnt from dual
           where exists (select 1 from user_amountinfo t where t.userid=v_userid and t.msgtype=v_msgtype);
       if  v_cnt>0 then
           update user_amountinfo set amount=amount+amountvalue  where user_amountinfo.userid=v_userid and user_amountinfo.msgtype=v_msgtype;
       else
           insert into user_amountinfo (userid,msgtype,amount)values(userid,msgtype,amountvalue);
       end if;
    
       select amount-amountvalue,amount into v_beforevalue,v_aftervalue from user_amountinfo t where t.userid=v_userid and t.msgtype=v_msgtype;
    
       insert into user_amountinfodetails(userid,msgtype,beforevalue,amountvalue,aftervalue,financetype,createUserid,msgid,remark,addtime)
           values(userid,msgtype,v_beforevalue,amountvalue,v_aftervalue,financetype,createUserid,msgid,remark,addtime);
    
       if(financetype<>2)then
           insert into user_amountinforecharges(id,userid,msgtype,beforevalue,amountvalue,aftervalue,financetype,createUserid,msgid,remark,addtime)
           values(seq_user_amountinfodetails_id.currval,userid,msgtype,v_beforevalue,amountvalue,v_aftervalue,financetype,createUserid,msgid,remark,addtime);
       end if;
    
       if(financetype=1) then--类型为充值
            update user_amountinfo set rechargeamount=rechargeamount+amountvalue  where user_amountinfo.userid=v_userid and user_amountinfo.msgtype=v_msgtype;
       end if;
       commit;
    exception--出现异常,回滚事务,抛出异常
      when others then
        rollback;
        raise;
    end;
  • 相关阅读:
    2019EC-Final参赛总结
    [2019HDU多校第五场][HDU 6626][C. geometric problem]
    [2019HDU多校第四场][HDU 6617][D. Enveloping Convex]
    [2019HDU多校第二场][HDU 6591][A. Another Chess Problem]
    [2019HDU多校第三场][HDU 6603][A. Azshara's deep sea]
    函数柯里化
    Polyfill 与 Shim
    Webpack 中的 Tree Shaking
    部署hexo后github pages页面未更新或无法打开问题
    如何删除github wiki page
  • 原文地址:https://www.cnblogs.com/rengke2002/p/6698211.html
Copyright © 2011-2022 走看看