表名是student,表中有3个字段id,name,grade
下面是创建触发器的代码:
create or replace trigger insert_update
after insert or update of grade on student for each row
begin
if inserting then
dbms_output.putline('插入操作!');
else
dbms_output.putline('更新操作!');
end if;
if :new.grade<60 then
dbms_output.putline(:new.name||'的成绩不及格!将删除之');
delete from student where id=:new.id;
else
dbms_output.putline('该生成绩及格!');
end if;
end;
这里,先谢过各位了。
下面是创建触发器的代码:
create or replace trigger insert_update
after insert or update of grade on student for each row
begin
if inserting then
dbms_output.putline('插入操作!');
else
dbms_output.putline('更新操作!');
end if;
if :new.grade<60 then
dbms_output.putline(:new.name||'的成绩不及格!将删除之');
delete from student where id=:new.id;
else
dbms_output.putline('该生成绩及格!');
end if;
end;
这里,先谢过各位了。
应该是这一句有问题
在触发器里面不能使用这样的删除语句 。
要实现这个功能你需要新加一个表级触发器。
另外还有一个包,这个包里面有一个数组变量用于存储要删除的学生的id号码。首先需要修改这个行级触发器,if :new.grade<60 then 里面,将需要删除的学生的id号码存储到包变量里面。
表级触发器里面遍历这个包变量,删除相应的数据 。即可。