Error description
Oracle-04082:new or old references are not allowed in table-level triggers
Solve the sample
(1) Create a trigger, there is a problem
CREATE OR REPLACE TRIGGER trigger_cname
before DELETE on C
DECLARE
v_count number;
BEGIN
Select COUNT (*) into the v_count from SC where Cno=:old. CNO;
If V_count > 0 Then
raise_application_error (-20000, ' The course has been selected by a student and cannot be deleted from the database ');
else
Dbms_output.put_line (' No student chooses the course, will delete the course from the database ');
End If;
End Trigger_cname;
/
(2) Problem solving
CREATE OR REPLACE TRIGGER trigger_cname
before DELETE on the C for each
ROW
DECLARE
v_count number;
BEGIN
Select COUNT (*) into the v_count from SC where Cno=:old. CNO;
If V_count > 0 Then
raise_application_error (-20000, ' The course has been selected by a student and cannot be deleted from the database ');
else
Dbms_output.put_line (' No student chooses the course, will delete the course from the database ');
End If;
End Trigger_cname;
/
Description: Using old or New in a table-level trigger should be added for each ROW