红色部分不能更新显示在错误提示上(我的触发器是可以运行)
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;

解决方案 »

  1.   

    lastnames  studentids  的赋值过程在哪啊,没看到
      

  2.   

    赋不了值啊,要是赋值了就不是触发器了都,要求插入数据的时候才激发这个触发器的,原来的想法市插入数据的时候读取插入的那两个字段,然后报错的时候显示出来
    改正后发现还是不行,出现错误:
    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; 
      

  3.   

    看的我比较晕。
    'OLD.LASTNAME' 这个值在哪呢。
    insert 的时候没有old 值
      

  4.   

    啊?大侠能不能解释下,不是:new或者:old只要有其中一个就行了么,如果lastname=:new.lastname,第一个lastname就直接认为是old的了阿
      

  5.   

    insert插入新值应该就是新的值,旧的不用管吧