set SERVEROUT ON;
create or replace TRIGGER tr_check_status
BEFORE DELETE ON supplier
for each row
declare
active_suppliers NUMBER;
begin
active_suppliers := 0;
select count(1) into active_suppliers
from supplier where supplier_id = :old.supplier_id
AND supplier_status='active';
IF(active_suppliers > 0) THEN
raise_application_error(-20001, 'Active supplier can not be deleted');
END IF;
end;
/
delete from supplier
where supplier_id=1;
Меня попросили создать триггер, который будет выполнять операцию удаления в таблице «Поставщик», если supplier_status = «неактивен», и не разрешать удалять, если supplier_status = «активный».
Я получаю следующее ошибка в вышеприведенном коде:
Error starting at line : 19 in command -
delete from supplier
where supplier_id=1
Error report -
ORA-04091: table DARSHAK.SUPPLIER is mutating, trigger/function may not see it
ORA-06512: at "DARSHAK.TR_CHECK_STATUS", line 6
ORA-04088: error during execution of trigger 'DARSHAK.TR_CHECK_STATUS'