PL SQL 触发器不工作
PL SQL trigger not functioning
请使用以下触发器帮助我:
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;
放在哪里我得到错误:
"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."
当由 delete 语句触发时,没有 :new 值,同样,当由 insert 语句触发时,也没有 :old 值。这可能是这里的问题。
请使用以下触发器帮助我:
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;
放在哪里我得到错误:
"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."
当由 delete 语句触发时,没有 :new 值,同样,当由 insert 语句触发时,也没有 :old 值。这可能是这里的问题。