PL SQL触发器无法正常运行

时间:2015-12-11 11:22:01

标签: oracle plsql plsqldeveloper

请通过以下触发器帮助我:

    create or replace TRIGGER "TRG_ECO"
AFTER delete OR UPDATE or INSERT ON add_tree

  referencing new as new old as old
  for each row
  declare
  var_num  number(1) :=1; 
  var_tree_type number(1);


BEGIN
        dbms_output.put_line('tRIGGER ADD CONTACT TRRIGGERED: ');



   select tree_type 
          INTO var_tree_type
          FROM master
          where seq_id = :old.add_parent;
    dbms_output.put_line('tRIGGER TRRIGGERED: ' || :new.add_parent);
   if(var_tree_type=7) then 


        select 
               CASE
                    WHEN (:new.add_parent not in (select a.seq_id  
                    from mastera)) then 0
                    WHEN (:new.add_parent in (select a.seq_id  
                    from mastera)) then 1
                    ELSE 1

            end
        into var_num
        from dual;


          UPDATE masterSET contact = var_num where seq_id = :new.add_parent;

    end if;


    dbms_output.put_line('tRIGGER TRRIGGERED: ');

END TRG_ECO;

因为当我尝试删除,插入,更新一行时,我得到一个错误,如:

  

错误报告 -   SQL错误:ORA-01403:找不到数据   ORA-06512:在“TOADM.TRG_ECO”,第11行   ORA-04088:执行触发器'TOADM.TRG_ECO'时出错   01403. 00000 - “找不到数据”   *原因:没有从对象中找到数据。   *操作:没有来自对象的数据可能是由于提取结束。   经过时间:00:00:00.032

当我用

更新代码时
create or replace TRIGGER "TRG_ECO"
AFTER UPDATE or INSERT ON add_tree

我把seq_id = :new.add_parent;我的错误放在哪里:

"SQL Error: ORA-04098: trigger 'TOADM.ECO' is invalid and failed re-validation
04098. 00000 -  "trigger '%s.%s' is invalid and failed re-validation"
*Cause:    A trigger was attempted to be retrieved for execution and was
           found to be invalid.  This also means that compilation/authorization
           failed for the trigger.
*Action:   Options are to resolve the compilation/authorization errors,
           disable the trigger, or drop the trigger."

1 个答案:

答案 0 :(得分:2)

当由delete语句触发时,没有:new值,同样当由insert语句触发时,没有:old值。这可能是一个问题。