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触发器表发生了变化触发器不能读它的解决方法(必看)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。