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;
Oracle 带回滚的存储过程
标签:cep val type 回滚事务 rac end after begin charge
小编还为您整理了以下内容,可能对您也有帮助:
oracle 存储过程更改了怎么回滚
create or replace procere my_update(vempno in number,vsal in number)as vint stu.sal%type:=vsal; my_exception exception; rint stu.sal%type;begin update stu set sal = vint where empno = vempno; select sal into rint from stu where empno = vempno; if rint<>0 then raise my_exception; end if; exception when my_exception then rollback;
oracle 存储过程更改了怎么回滚
create or replace procere my_update(vempno in number,vsal in number)as vint stu.sal%type:=vsal; my_exception exception; rint stu.sal%type;begin update stu set sal = vint where empno = vempno; select sal into rint from stu where empno = vempno; if rint<>0 then raise my_exception; end if; exception when my_exception then rollback;
oracle存储过程
分如下情况:
1。如果return 在commit之后,已经提交无所谓回滚。
2。如果return在commit之前,所有都回滚
3。如果希望中间有一部分回滚是不可能的,可以把中间的一部分提取出来成为一个单独的存储过程或者函数,把它设置为事务控制,这样执行这个存储过程就会提交,其他的程序块,可以通过rollback控制回滚。
事务控制语法:
CREATE OR REPLACE PROCEDURE
IS
PRAGMA AUTONOMOUS_TRANSACTION;