I have a table that represents locations on a campus. I am displaying these locations for the user in a web program, and I want to give them the ability to change the order that the locations are displayed in. I have a column for that, called ord
. I now am trying to create a way for the user to update that column, and make sure that
1) there are no ord
duplicates
2) that all ord
values are >= 0 && < rowcount (of the table).
I figure I should do this with triggers. First, before I do the update, I use code to make sure the value is >= 0 & < rowcount of table. Then, once that value is inserted, I need to fix the duplicate it creates. What I want to do is just switch the values. However, I get the dreaded oracle mutating table error when I try this trigger:
create or replace
trigger plantry_campus_edit_after
after update on plantry_campus
for each row
declare
v_pkid number;
begin
SELECT pkid INTO v_pkid FROM plantry_campus WHERE ord = :new.ord && pkid != :new.pkid;
UPDATE plantry_campus SET ord = :old.ord WHERE pkid = v_pkid;
end;
I'd prefer to do this in the database and not in the code. Any suggestions as to how I can accomplish this?