你是不是想得太复杂了,
在表一上写一个触发器不就行了吗?我的思路是这样的,
在表一上创建一个行级更新前触发器,
在触发器里实现,根据更新前的值查找表二里的数据,
然后在表三里插入数据。不需要rowid,也不需要创建包,也不需要创建那么多的触发器。 

解决方案 »

  1.   

    我觉得只要一个触发器,pms_counter表的after insert or update of index_value就够了吧。
    用游标取表二的item_id = :new.item_id and item_index = :new.item_index
    的记录,包括section_up_limit。判断:new.index_value > 游标.section_up_limit时,insert 表三。
    应该可以吧?你再考虑一下。
      

  2.   

    select  item_id,item_index,index_value into v_item_id,v_item_index,v_index_value
                from pms_counter
                where rowid = state_pkg1.newrows(i);--此处可能有误,查不处数据,但我不知如何解决!!!!!!--是可以查到数据的。
      

  3.   

    我现在建立了了一个行级更新后除法器(因为我要用到表一更新后的index_value值)
    触发器如下:
    出现错误为:ORA_02291表三未找到父项关键字(item_id),望指教!!create or replace trigger aufer_counter_code_order
      after update of index_value on pms_counter  
      for each row
    declare
      -- local variables here
      cursor cur_code
        is
        select * from PMS_MTN_CODE
        where item_id= :old.item_id
        and item_index= :old.item_index;
      l_code  PMS_MTN_CODE%rowtype;
      v_section_up_limit number(8,2);
      v_index_value number(8,2);
      v_item_id char(10);
      v_item_index char(3);
      v_action_id char(3);
      v_workload char(10); 
      v_order_id char(10);
      v_order_id1 char(10);
      --v_count number(1);--
    begin
      v_index_value:= :new.index_value;
      v_item_id:= :new.item_id;
      v_item_index:= :new.item_index;
      open cur_code;
      fetch cur_code into l_code;
      while cur_code%found
      loop
      v_section_up_limit:=l_code.section_up_limit;
      v_item_id:=l_code.item_id;--
      v_item_index:=l_code.item_index;
      v_action_id:=l_code.action_id;
      v_workload:=nvl(l_code.workload,  0); --
      select max(order_id) into v_order_id  
             from work_order;  
      if v_order_id is null then
      v_order_id:=nvl(v_order_id,'0000000000'); 
      end if;
      v_order_id1:=to_char(sysdate,'yy-mm-dd');
      if v_order_id1=substr(v_order_id,2,6) then--
      v_order_id:=lpad(lpad(lpad(to_char((to_number(substr(v_order_id,8,3))+1)),3,'0'),9,v_order_id1),10,'w');
      else  
      v_order_id:=lpad(lpad('001',9,v_order_id1),10,'w');
      end if;
      if v_index_value>v_section_up_limit then --向表三插入数据
      insert into work_order (order_id,item_id,workload,action_id,item_index,type_id,priority_id)
      values
            (v_order_id,v_item_id,v_workload,v_action_id,v_item_index,'AC','3');
      end if;
      fetch cur_code into l_code;
      end loop;
      close cur_code;
    end aufer_counter_code_order;
    create or replace trigger aufer_counter_code_order
      after update of index_value on pms_counter  
      for each row
    declare
      -- local variables here
      cursor cur_code
        is
        select * from PMS_MTN_CODE
        where item_id= :old.item_id
        and item_index= :old.item_index;
      l_code  PMS_MTN_CODE%rowtype;
      v_section_up_limit number(8,2);
      v_index_value number(8,2);
      v_item_id char(10);
      v_item_index char(3);
      v_action_id char(3);
      v_workload char(10); --Ëü¿ÉÄÜÊÇ¿ÕÖµ,ΪʲôÊÇ×Ö·ûÐÍ
      v_order_id char(10);
      v_order_id1 char(10);
      --v_count number(1);--
    begin
      v_index_value:= :new.index_value;
      v_item_id:= :new.item_id;
      v_item_index:= :new.item_index;
      open cur_code;
      fetch cur_code into l_code;
      while cur_code%found
      loop
      v_section_up_limit:=l_code.section_up_limit;
      v_item_id:=l_code.item_id;--
      v_item_index:=l_code.item_index;
      v_action_id:=l_code.action_id;
      v_workload:=nvl(l_code.workload,  0); --
      select max(order_id) into v_order_id  --v_order_idΪ¿Õ£¿
             from work_order;  --ÒÔÏÂÓ¦¸ÃÔö¼Ó·Ç¿ÕµÄÅжÏ
      if v_order_id is null then
      v_order_id:=nvl(v_order_id,'0000000000'); 
      end if;
      v_order_id1:=to_char(sysdate,'yy-mm-dd');
      if v_order_id1=substr(v_order_id,2,6) then--
      v_order_id:=lpad(lpad(lpad(to_char((to_number(substr(v_order_id,8,3))+1)),3,'0'),9,v_order_id1),10,'w');
      else  
      v_order_id:=lpad(lpad('001',9,v_order_id1),10,'w');
      end if;
      if v_index_value>v_section_up_limit then --Éú³ÉÐµĹ¤×÷µ¥
      insert into work_order (order_id,item_id,workload,action_id,item_index,type_id,priority_id)
      values
            (v_order_id,v_item_id,v_workload,v_action_id,v_item_index,'AC','3');
      end if;
      fetch cur_code into l_code;
      end loop;
      close cur_code;
    end aufer_counter_code_order;