各位版友,
我建立了一個 trigger 如下
create or replace trigger checkmodulecount
before insert or update on registration
for each row
declare
maxnum number;
ex exception;begin
select count(moduleid) into maxnum
from registration
where studentid = :new.studentid
group by studentid,year,semester;
if maxmum < 4 then
dbms_output.put_line('Row added to registration table successful');
else raise ex;
end if;
exception
when ex then
raise_application_error(-30001,'Student'||:new.studentid||'already registered 4 courses');
end;table Registration
Create table Registration
(StudentID varchar2(6), 
ModuleID varchar2(5), 
Year char(2), 
Semester char(1),  
CwMark number(2),
ExamMark number(2), 
constraint pk_r1 primary key(StudentID,ModuleID,Year,Semester),
constraint fk_st1 foreign key(StudentID) references Student(StudentID),
constraint fk_m3 foreign key(ModuleID) references Module(ModuleID)  );當試著 Insert new row 去解發 trigger 時就出現以下的錯誤信息
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SYSTEM.CHECKMODULECOUNT", line 6
ORA-04088: error during execution of trigger 'SYSTEM.CHECKMODULECOUNT'
請問是否 Trigger 有什麼寫得不對的地方?