我需要创建一个引发错误的触发器如果有人试图删除包含少于20行的表中的Row。我对触发器很新,下面的代码是我停下来的地方。
Create or Replace Trigger Lab16Trigger2
BEFORE Delete On employee_copy
WHEN (count(*) < 20)
Begin
RAISERROR('ORA-20101: At least 20 rows in employee_copy table');
End;
答案 0 :(得分:2)
假设这是一项家庭作业(要求通常没有意义,触发器在多用户环境中不起作用)
create or replace trigger trigger_name
after delete on table_name
declare
l_cnt pls_integer;
begin
select count(*)
into l_cnt
from table_name;
if( l_cnt < 20 )
then
raise_application_error( -20001, 'You must leave at least 20 rows in the table.' );
end if;
end;