SQL>  create or replace trigger number_trig
  2  after  update of 订货数量
  3  on 订单明细表
  4  for each row
  5  declare
  6  cursor my_tor_cur is select *from 订单明细表 where 编号 =:new.编号;
  7  cursor my_tor_cur1 is select * from 订单明细表 where 订单编号 =:new.订单编号;
  8   sumnumber number(12,2);
  9   row_list_order 订单明细表%rowtype;
 10   row_list_order1 订单明细表%rowtype;
 11  begin
 12  DBMS_output.put_line(:new.编号);
 13  open my_tor_cur;
 14  fetch my_tor_cur into row_list_order;
 15  sumnumber := row_list_order.订货价格*row_list_order.订货数量;
 16  DBMS_output.put_line(row_list_order.订货价格||'  '||row_list_order.订货数量);
 17  
 18  open  my_tor_cur1;
 19  loop
 20  fetch my_tor_cur1 into row_list_order1;
 21  exit when my_tor_cur1%notfound;
 22  sumnumber := sumnumber+row_list_order1.订货价格*row_list_order1.订货数量;
 23  end loop;
 24  update 订单表 set 订货总金额 =sumnumber where 订单编号=:old.订单编号;
 25  end;
 26  /Trigger createdSQL> update 订单明细表  set 订货数量=10 where 编号=1;1update 订单明细表  set 订货数量=10 where 编号=1ORA-04091: 表 USERXL.订单明细表 发生了变化, 触发器/函数不能读它
ORA-06512: 在 "USERXL.NUMBER_TRIG", line 2
ORA-06512: 在 "USERXL.NUMBER_TRIG", line 9
ORA-04088: 触发器 'USERXL.NUMBER_TRIG' 执行过程中出错----怎么在申明的时候不能用这两个:new 和:old  这个对像啊

解决方案 »

  1.   

    //需要使用动态游标,给你个例子,你可以s2替换成你的:new.....create or replace trigger aaa
    after update on temp123
    for each row
    begin
      declare 
        cursor s;
        s1 varchar2(100);
        s2 varchar2(100);
      begin
        s2:='查询统计';
        open s for select cname from power_first where cname=s2;
        loop
        fetch s into s1
        EXIT WHEN s%NOTFOUND;
        insert into temp124 values( s1 );
        end loop;
        close s;
      end;
    end;
      

  2.   

    发错了
    create or replace trigger aaa
    after update on temp123
    for each row
    begin
      declare
        type cursor_type is ref cursor;
        s cursor_type;
        s1 varchar2(100);
        s2 varchar2(100);
      begin
        s2:='查询统计';
        open s for select cname from power_first where cName=s2;
        loop
        fetch s into s1;
        insert into temp124 values( s1 );
        EXIT WHEN s%NOTFOUND;
        end loop;
        close s;
      end;
    end;
      

  3.   

    晕!~~~~
    fetch s into s1;
    EXIT WHEN s%NOTFOUND;
    insert into temp124 values( s1 );