红色部分不能更新显示在错误提示上(我的触发器是可以运行)
create or replace trigger checkmodulecount
before insert on registration
for each row
declare
lastnames varchar2(20);
studentids varchar2(20);
moduleCount number;
ex exception;
begin
select count(moduleid) into moduleCount
from registration r,student s
where s.lastname= lastnames
and s.studentid= studentids
and moduleid = :new.moduleid
and r.studentid=s.studentid
and r.semester='2' or r.semester='1';
if moduleCount < 4 then
dbms_output.put_line('Module registered successful');
else
raise ex;
end if;
exception
when ex then
raise_application_error(-20000, 'Student '|| lastnames || ' ID '||studentids || ' has register 4 modules already, the number of module for a particular semester should not exceed 4');
end;
create or replace trigger checkmodulecount
before insert on registration
for each row
declare
lastnames varchar2(20);
studentids varchar2(20);
moduleCount number;
ex exception;
begin
select count(moduleid) into moduleCount
from registration r,student s
where s.lastname= lastnames
and s.studentid= studentids
and moduleid = :new.moduleid
and r.studentid=s.studentid
and r.semester='2' or r.semester='1';
if moduleCount < 4 then
dbms_output.put_line('Module registered successful');
else
raise ex;
end if;
exception
when ex then
raise_application_error(-20000, 'Student '|| lastnames || ' ID '||studentids || ' has register 4 modules already, the number of module for a particular semester should not exceed 4');
end;
改正后发现还是不行,出现错误:
TRIGGER CHECKMODULECOUNT 出现错误:LINE/COL ERROR
8/16 PLS-00049: 错误的赋值变量 'OLD.LASTNAME'
19/47 PLS-00049: 错误的赋值变量 'OLD.LASTNAME'
create or replace trigger checkmodulecount
before insert on registration
for each row
declare
moduleCount number;
ex exception;begin
select count(moduleid) into moduleCount
from registration r,student s
where lastname=:new.lastname
and studentid=:new.studentid
and r.studentid=s.studentid
and r.semester='2' or r.semester='1';
if moduleCount < 4 then
dbms_output.put_line('Module registered successful');
else
raise ex;
end if;
exception
when ex then
raise_application_error(-20000, 'Student '|| :new.lastname || ' ID '||:new.studentid || ' has register 4 modules already, the number of module for a particular semester should not exceed 4');
end;
'OLD.LASTNAME' 这个值在哪呢。
insert 的时候没有old 值