트리거 ORA-04091 솔루션

2935 단어 트리거
최근에 트리거를 쓸 때 이 문제를 미리 찾았는데, 다방면으로 찾아낸 결과

1. after   for each row  triggers, insert trigger,  trigger  trigger table 
2. before   for each row  triggers,  insert into ... values  trigger , trigger  table ;
  insert into select .. from  trigger , trigger  table ora-04091 ;


해결 방법,oracle의 자치사무로
create or replace trigger twininfo_trriger
  after insert on twininfo for each row

declare
  PRAGMA AUTONOMOUS_TRANSACTION;-- 
begin
     IF INSERTING THEN

     if :new.lotno='T01012' then
     update twininfo set info='100_234100_100,1_1_1300;2_1_600;3_1_6500;4_1_13000;5_1_1900;6_1_19500;7_1_117000;8_1_7800;9_1_54000;10_1_9000;11_1_2600;12_1_900'
     where lotno= :new.lotno and batchcode= :new.batchcode;
     dbms_output.put_line(:new.lotno||'====='||:new.batchcode);
     commit;
      dbms_output.put_line(' '||'=====');
     end if;
      if :new.lotno='T01001' then
     update twininfo set info='8442562400_2232960500_13276345700,1_0_0;2_37_12540700;3_61_1856200;4_133_300000;5_3439_60000;6_12371_10000;7_153408_1000;8_1830877_500;11_0_0;12_8_7524400;13_16_1113700;14_33_150000;15_1021_30000;16_3624_5000;17_46687_500;18_10312_6000'
        where lotno= :new.lotno and batchcode= :new.batchcode;
       commit;
     end if;
 END IF;

 end;

사실 가장 간단한 것은 다음과 같다.


 create or replace trigger twininfo_trriger
  before insert on twininfo for each row


begin
     IF INSERTING THEN

     if :new.lotno='T01012' then
  

      :new.info :='100_234100_100,1_1_1300;2_1_600;3_1_6500;4_1_13000;5_1_1900;6_1_19500;7_1_117000;8_1_7800;9_1_54000;10_1_9000;11_1_2600;12_1_900';
     end if;
     if :new.lotno='T01001' then
     :new.info :='8442562400_2232960500_13276345700,1_0_0;2_37_12540700;3_61_1856200;4_133_300000;5_3439_60000;6_12371_10000;7_153408_1000;8_1830877_500;11_0_0;12_8_7524400;13_16_1113700;14_33_150000;15_1021_30000;16_3624_5000;17_46687_500;18_10312_6000';
 
    end if;
 END IF;

 end;

다른 사람의 예:

create or replace trigger TR_U_ID_SYNCH
  before update on COMPANY referencing old as old_value
    new as new_value
  for each row
declare
tId  company.id%type;
PRAGMA AUTONOMOUS_TRANSACTION;
begin
if :new_value.U_ID is not null and :new_value.U_ID!=ld_value.U_ID  then
   select t.t_id into tId from company t where t.id= :new_value.U_ID;
   :new_value.P_ID :=:new_value.U_ID;
   :new_value.T_ID :=tId;
end if;
COMMIT;
end TR_CO_GB_ID_SYNCH;


좋은 웹페이지 즐겨찾기