target_table1(
key NUMBER;
value VARCHAR2(10);
auto_value VARCHAR(12);
)target_table2(
key NUMBER;
value VARCHAR2(10);
auto_value VARCHAR(12);
)target_table3(
key NUMBER;
value VARCHAR2(10);
auto_value VARCHAR(12);
)现在要做一个AFTER INSERT ON target_tablex(x代表1、2、3)的触发器auto_update_tabx
如果向表target_tablex插入一条数据(1, 'a', NULL),那么auto_update_tabx就根据字段value的值'a'来更新auto_value的值(更新操作,如'a' || 'b')这里要注意的是触发器的触发源,和触发器要更新的数据表是同一个,所以编写过程中常常会遇到ora-04091错误(ORA-04091: 表 target_tablex 发生了变化, 触发器/函数不能读它)请各位达人帮帮忙~~

解决方案 »

  1.   

    if :new.key=a then
    :new.value :=a||b;
    end if;
      

  2.   

    触发器中不能读取触发的表数据,因此,要操作只能对伪表操作
    所以这样做才不会出错:
    if upper(:new.key)='a' then
      :new.value :=:new.value||'b';
    end if;
      

  3.   

    AFTER INSERT 中是不能使用 :new.value :=:new.value||'b';
    因为这里:NEW是不能被赋值的
      

  4.   

    哦,看错,以为是before
    那你改成before不行吗?
      

  5.   

    http://expertanswercenter.techtarget.com/eac/knowledgebaseAnswer/0,295199,sid63_gci1054334,00.html我找到这么一个例子,准备尝试一下
      

  6.   

    To:wiler(@_@),改成before倒是可以,但我想知道after到底能不能实现To:bzszp(SongZip),你说的方法是不是下面这种?From Metalink Problem Description ------------------- 
    Oracle does not allow you to read a mutating table in a row trigger because if you can read it, the information may be incorrect (not read consistent). If you attempt this, the following error is returned: 
    ORA-04091 
    Table %s.%s is mutating, trigger/function may not see it 
    However, you can perform this operation in a statement trigger. 
    One way to handle this situation is to use a package PL/SQL table to store ROWIDs of updated records in a row trigger, and reprocess the updated 
     records in a statement trigger. 
    Below is an example.  Important Note -------------- 
    Note that there are concurrency issues with this if more than one session tries to perform operations simultaneously. 
    This is not intended as a total solution, but as the framework to help show one option. 
     Example Workaround ------------------ create or replace package emp_pkg astypeemp_tab_type is table of rowid index by binary_integer;emp_tab emp_tab_type;emp_index binary_integer; end emp_pkg; /create or replace trigger emp_bef_stm_all before insert or update or delete on emp begin/*Remember to reset the pl/sql table before each statement*/emp_pkg.emp_index := 0; end; /create or replace trigger emp_aft_row_all after insert or update or delete on emp for each row begin/*Store the rowid of updated record into global pl/sql table*/emp_pkg.emp_index := emp_pkg.emp_index + 1;emp_pkg.emp_tab(emp_pkg.emp_index) := :new.rowid; end; /create or replace trigger emp_aft_stm_all afterinsert or update or delete on emp beginfor i in 1 .. emp_pkg.emp_index loop /* Re-process the updated records. There is no restriction here. */ dbms_output.put_line(emp_pkg.emp_tab(i));end loop;emp_pkg.emp_index := 0; end; /