Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Instead of insert trigger on view

464641Nov 14 2005 — edited Nov 19 2005
I have a table (teacher) that has a column (current school) to indicate whether this teacher record is valid for the current school. When a new teacher record is inserted i want to check the table for records of the same teacher and if there are any to set the current school flag for those records to 'N', sounds simple right?

Ive written the following procedure and trigger based on a view of my teacher table (the view is simply select * from teacher) but will it work? No!

CREATE OR REPLACE TRIGGER v_teacher_tg
instead of insert on v_teacher
begin
update_old_teacher_schools(:new.te_teacher_id);
end;

CREATE OR REPLACE procedure update_old_teacher_schools (new_teacher_id number) is
/* This procedure takes the latest teacher id as a parameter and checks for
...existing teachers with the same te_ni_number, if there are any it updates the
...current school flag to 'N' as this teacher is now at a new school */
ni_number varchar2(9);
begin
select te_ni_number into ni_number from v_teacher
where te_teacher_id = new_teacher_id;
if ni_number is not null then
update teacher set te_current_school = 'N'
where te_ni_number = ni_number
and te_teacher_id != new_teacher_id;
commit;
end if;
end update_old_teacher_schools;

the procedure works fine when i run it on its own but when used with the trigger it doesnt update, any ideas?

Thanks

danny
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2005
Added on Nov 14 2005
18 comments
1,115 views