2015-12-11 56 views
0

請幫我用下面的觸發器:PL SQL觸發器不能正常工作

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; 

,因爲當我嘗試刪除,插入,更新行我得到一個錯誤,如:

Error report - SQL Error: ORA-01403: no data found ORA-06512: at "TOADM.TRG_ECO", line 11 ORA-04088: error during execution of trigger 'TOADM.TRG_ECO' 01403. 00000 - "no data found" *Cause: No data was found from the objects. *Action: There was no data from the objects which may be due to end of fetch. Elapsed: 00:00:00.032

當我

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

更新的代碼,我放在哪裏seq_id = :new.add_parent;我得到的錯誤:

+1

需要處理'NO_DATA_FOUND'異常。當'select into'語句沒有返回行時,會引發'NO_DATA_FOUND'異常。錯誤消息說明了一切。第二個'select'語句看起來多餘。 'case'表達式的結果可以直接賦值給'var_num'變量。 –

+0

但我有數據要返回。 – SocketM

回答

2

當由delete語句觸發時,沒有:新值,同樣,當由插入語句觸發時,沒有:舊值。這可能是一個問題。

+0

SELECT * FROM USER_ERRORS其中type = '觸發' 和名稱= 'TRG_FIRST_CONTACT_FROM_ADD'< - 看看有什麼錯誤觸發實際上得到 – jera

+0

PLS-00103:出現符號 「IF」 – SocketM

+0

序列1線24位置4 – SocketM