修改某列后触发本表的其他列更新, 报错:表hr.t00hz008发生了变化,触发器/函数不能读他我的程序如下:
/*
  当本表的定员或现员修改后,触发修改本表的超员+、缺员-;
  “现员-定员>0”时计入“超员+”字段,同时清除“缺员-”字段内容;
  “现员-定员<0”时计入“缺员-”字段,同时清除“超员+”字段内容;
  “现员-定员=0”时,清除“超员+”和“缺员-”字段内容
*/create or replace trigger tr_table8_aft_table8
  before update of CAPACITY,NOW_CAP on   table8
  for each row
declare
  -- local variables here
  temp        number(5);
  IN_SUM      number(5);
  OUT_SUM     number(5);
  
begin
  dbms_output.put_line('trriger :new.NOW_CAP='||:new.NOW_CAP||'  :new.CAPACITY='||:new.CAPACITY);   
  dbms_output.put_line('trriger :new.t00hz008id='||:new.t00hz008id);   
  temp :=:new.NOW_CAP-:new.CAPACITY;--现员-定员
  if(temp>0)then
     IN_SUM :=temp; --缺员
     update t00hz008 set OUT_SUM=OUT_SUM-1,IN_SUM=IN_SUM+1 where t00hz008id = :new.t00hz008id;
  elsif(temp<0)then
     OUT_SUM :=temp;--超员
     update t00hz008 set OUT_SUM=OUT_SUM+1,IN_SUM=IN_SUM-1 where t00hz008id = :new.t00hz008id;
  elsif(temp=0)then
     update t00hz008 set OUT_SUM=0,IN_SUM=0 where t00hz008id = :new.t00hz008id;
  end if;
  end tr_table8_aft_table8;打出来的log值都有的,报错行是update t00hz008 set OUT_SUM=OUT_SUM+1,IN_SUM=IN_SUM-1 where t00hz008id = :new.t00hz008id;

解决方案 »

  1.   


    是的,table8就是t00hz008表
      

  2.   

    本表的话使用before触发器,赋值采用:new.需赋值字段:=:new.复制字段
      

  3.   

    Connected to Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 
    Connected as scott
     
    SQL> desc aa
    Name Type         Nullable Default Comments 
    ---- ------------ -------- ------- -------- 
    ID1  NUMBER(10)   Y                         
    X    VARCHAR2(10) Y                         
    M    VARCHAR2(10) Y                         
     
    SQL> 
    SQL> create or replace trigger tri_aa
      2    before update of x on aa
      3    for each row
      4  declare
      5  begin
      6    :new.m:=:new.x;
      7  end;
      8  /
     
    Trigger created
     SQL> select * from aa where x='a';
     
            ID1 X          M
    ----------- ---------- ----------
              1 a          ттт
              1 a          test
     
    SQL> update aa set x=x where x='a';
     
    2 rows updated
     
    SQL> select * from aa where x='a';
     
            ID1 X          M
    ----------- ---------- ----------
              1 a          a
              1 a          a
     
    SQL> 
      

  4.   


    --通过修改:new关键字试试,或者使用自制事务
    create or replace trigger tr_table8_aft_table8
      before update of CAPACITY,NOW_CAP on table8
      for each row
    declare
      -- local variables here
      temp number(5);
      IN_SUM number(5);
      OUT_SUM number(5);   
    begin
      dbms_output.put_line('trriger :new.NOW_CAP='||:new.NOW_CAP||' :new.CAPACITY='||:new.CAPACITY);   
      dbms_output.put_line('trriger :new.t00hz008id='||:new.t00hz008id);   
      temp :=:new.NOW_CAP-:new.CAPACITY;--现员-定员
      if(temp>0)then
         :new.IN_SUM  := temp; --缺员
         :NEW.OUT_SUM := :NEW.OUT_SUM-1;
         :NEW.IN_SUM  := :NEW.IN_SUM+1 ;
      elsif(temp<0)then
         :new.OUT_SUM := temp;--超员
          :NEW.OUT_SUM := :NEW.OUT_SUM+1;
         :NEW.IN_SUM  := :NEW.IN_SUM-1 ;
      elsif(temp=0)then
         :NEW.OUT_SUM := 0;
         :NEW.IN_SUM  := 0;
      end if;
      end tr_table8_aft_table8;