I have a trigger that looks something like this:
create or replace
TRIGGER cluster_check
before insert on my_table
FOR EACH ROW
when (passive_server = new.server)
begin
ROLLBACK;
UPDATE my_table
set (server,passive_server) = (passive_server,server) where passive_server = new.server;
end;
I am getting the error Error: ORA-04076: invalid NEW or OLD specification on compilation.
Essentially what I am trying to do is check on insert to see if the incoming server matches the passive server in another record and if so cancel the insert and swap the existing records passive and active servers.
What am I doing wrong?
A trigger on a table can’t change the operation like this.
You could define a view on top of
my_table, do theINSERTagainst the view, and then have aninstead of inserttrigger that changed theINSERToperation into anUPDATE. But then all your DML would have to go against the view rather than the table. You could potentially rename the table and then create a view namedmy_tableto make that transition easier.Before you go down that path, however, are you certain that you need a trigger in the first place? Are you sure that your application couldn’t do something like call a stored procedure that would determine what to do or that it couldn’t do a
MERGEinstead of anINSERT?