Oracle触发器表发生了变化 触发器不能读它的解决方法(必看)
出现原因,是因为在更新的的表和读取的表是同一个表。
CREATEorreplaceTRIGGERT_userupdateTBEFOREupdateONT_userREFERENCINGOLDASoldNEWASN_ROWFOREACHROW DECLAREU_xtfidemp1varchar(36); u_xtempcode1varchar(20); u_xtempcodeCountint:=0; U_xtfidempCountint:=0; u_id1int:=0; BEGIN U_xtfidemp1:=:N_ROW.U_xtfidemp; u_xtempcode1:=:N_ROW.u_xtempcode; u_id1:=:N_ROW.u_id; selectcount(u_xtempcode)intou_xtempcodeCountfromeas.T_userwhereu_xtempcodeisnotnullandu_xtempcode=u_xtempcode1andu_id<>u_id1; selectcount(U_xtfidemp)intoU_xtfidempCountfromeas.T_userwhereU_xtfidempisnotnullandU_xtfidemp=U_xtfidemp1andu_id<>u_id1; IFu_xtempcodeCount>0orU_xtfidempCount>0THEN RAISE_APPLICATION_ERROR(-20001,'eas.T_useru_xtempcode,U_xtfidemp,U_GZCode更新数据时有错误,有重复'); ENDIF; end;
出现错误时,是因为触发器在T_userupdateT在T_user上,触发器内部有读取了T_user所以有错误。
修改如下
CREATEorreplaceTRIGGERT_userupdateTBEFOREupdateONT_userREFERENCINGOLDASoldNEWASN_ROWFOREACHROW DECLAREU_xtfidemp1varchar(36); u_xtempcode1varchar(20); u_xtempcodeCountint:=0; U_xtfidempCountint:=0; u_id1int:=0; PRAGMAAUTONOMOUS_TRANSACTION; BEGIN U_xtfidemp1:=:N_ROW.U_xtfidemp; u_xtempcode1:=:N_ROW.u_xtempcode; u_id1:=:N_ROW.u_id; selectcount(u_xtempcode)intou_xtempcodeCountfromeas.T_userwhereu_xtempcodeisnotnullandu_xtempcode=u_xtempcode1andu_id<>u_id1; selectcount(U_xtfidemp)intoU_xtfidempCountfromeas.T_userwhereU_xtfidempisnotnullandU_xtfidemp=U_xtfidemp1andu_id<>u_id1; IFu_xtempcodeCount>0orU_xtfidempCount>0THEN RAISE_APPLICATION_ERROR(-20001,'eas.T_useru_xtempcode,U_xtfidemp,U_GZCode更新数据时有错误,有重复'); ENDIF; COMMIT; end;
多了PRAGMAAUTONOMOUS_TRANSACTION;COMMIT;两句
以上这篇Oracle触发器表发生了变化触发器不能读它的解决方法(必看)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短