以下是触发器内容:
我想在表PPLME_SYS中某一列被更新是更新与其相关的另一列,但老是报错死循环
CREATE OR REPLACE TRIGGER "INFODBA"."TEST" BEFORE
UPDATE OF "PPLM_STRING01" ON "PPLME_SYS" FOR EACH ROW DECLARE  pragma autonomous_transaction; 
tempPUID  varchar2(32);
CURSOR Mycur is
select PPLM_STRING01 from PPLME_SYS where PUID=:new.PPLM_STRING01;
CursorRecord Mycur%ROWTYPE;
begin
 open Mycur;
 FETCH Mycur into CursorRecord;
 if Mycur%NOTFOUND 
 then
  if :new.PPLM_STRING01 is not null 
  then
   update PPLME_SYS set PPLM_STRING03='aa' where PUID=:new.PPLM_STRING01;
 
   update PPLME_SYS set PPLM_STRING01=:new.PUID where PUID=:new.PPLM_STRING01;
end if;
else
 update PPLME_SYS set PPLM_STRING03='aa' where PUID=:new.PPLM_STRING01;
select PPLM_STRING01 into tempPUID from PPLME_SYS where PUID=:new.PPLM_STRING01;
 if tempPUID is null then
 update PPLME_SYS set PPLM_STRING01=:new.PUID where PUID=:new.PPLM_STRING01;
end if;
end if;
commit;
end;多谢!

解决方案 »

  1.   

    open Mycur;
    loop
    FETCH Mycur into CursorRecord;
    exit when Mycur%Notfound
    if :new.PPLM_STRING01 is not null
    then
    update PPLME_SYS set PPLM_STRING03='aa' where PUID=:new.PPLM_STRING01;
    update PPLME_SYS set PPLM_STRING01=:new.PUID where PUID=:new.PPLM_STRING01;
    end if;
    else
    update PPLME_SYS set PPLM_STRING03='aa' where PUID=:new.PPLM_STRING01;
    select PPLM_STRING01 into tempPUID from PPLME_SYS where PUID=:new.PPLM_STRING01;
    if tempPUID is null then
    update PPLME_SYS set PPLM_STRING01=:new.PUID where PUID=:new.PPLM_STRING01;
    end loop;触发器出现异常将自动回滚