請幫我用下面的觸發器: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;
我得到的錯誤:
需要處理'NO_DATA_FOUND'異常。當'select into'語句沒有返回行時,會引發'NO_DATA_FOUND'異常。錯誤消息說明了一切。第二個'select'語句看起來多餘。 'case'表達式的結果可以直接賦值給'var_num'變量。 –
但我有數據要返回。 – SocketM