I have the following tables:
Professor
id_professor
name
number_courses_assigned
Course
id_course
name_course
id_professor
I want to have a trigger that after I insert or delete a course into the table of the same name, the field number_courses_assigned from the table Professor gets updated immediately. So far I have done the following:
create or replace trigger update_number_courses
after insert on course
declare
codP course.id_professor%type;
countC professor.number_courses_assigned%type;
begin
select course.id_professor into codP from course;
select professor.number_courses_assigned into countC from professor where id_professor=codP;
update professor set number_courses_assigned=countC+1 where id_professor=codP;
end;
The problem that I have is that when I want to insert a row into the Course table the Oracle SQL Developer returns me an error and does not allow the insertion of the new record, the message I got is:
Row 5: ORA-01422: exact fetch returns more than requested number of rows
Any help?