Oracle's stored procedures with rollback

Source: Internet
Author: User

Create or Replace procedureProc_insertuseramount (userid Number, Msgtype Number, Amountvalue Number, Financetype Number, Createuserid Number, MsgId nvarchar2, remark nvarchar2, Addtime date) isv_cnt Number; V_beforevalue Number; V_aftervalue Number; V_userid Number; V_msgtype Number;beginV_userid:=userid; V_msgtype:=Msgtype; Select Count(*) intoV_cnt fromDualwhere exists(Select 1  fromUser_amountinfo TwhereT.userid=V_userid andT.msgtype=V_msgtype); ifV_cnt>0  Then       UpdateUser_amountinfoSetAmount=Amount+AmountvaluewhereUser_amountinfo.userid=V_userid andUser_amountinfo.msgtype=V_msgtype; Else       Insert  intoUser_amountinfo (Userid,msgtype,amount)Values(Userid,msgtype,amountvalue); End if; SelectAmount-Amountvalue,amount intoV_beforevalue,v_aftervalue fromUser_amountinfo TwhereT.userid=V_userid andT.msgtype=V_msgtype; Insert  intoUser_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  intoUser_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--type is recharge        UpdateUser_amountinfoSetRechargeamount=Rechargeamount+AmountvaluewhereUser_amountinfo.userid=V_userid andUser_amountinfo.msgtype=V_msgtype; End if; Commit; exception--An exception occurs, a transaction is rolled back, an exception is thrown   whenOthers Then    rollback; raise;End;

Oracle's stored procedures with rollback

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.