Update in Before Insert Trigger
Hima, November 17, 2016 - 8:52 pm UTC
thank you very much for your help and suggestions.
I come across new scenario during update trigger code testing.
question:
1. During insert operation on T1, it goes inside if inserting block.
2. during update operation on T1, it goes inside if updating block. But, when it hits else blocks it runs insert statements which are supposed to run. But, also it is calling BEFORE INSERT trigger which has been defined at #1 on T1.
My requirement is, it should not call the other INSERT trigger (#1) when it is being called by UPDATE TRIGGER and then follows by INSERT in else blocks. Please look into below pseudo code.
Expected Result: When I do update on T1, based on conditions it has to do inserts in else blocks only but not the insert statement of #1.
create Trigger Trg
before insert or update of c1,c2 on T1
for each row
begin
if inserting then
:new.c1 := 'A';
:new.c2 := 'B';
end if;
if updating then
if :old.active = 'INACTIVE' then
raise_application_error(-20000,'do not update');
else if :old.active = 'FALSE' then
insert query on T1(c1,c2) values(:new.c1,:new.c2);
else
insert query on T1(c1,c2,active) values(:old.c1,:old.c2,'FALSE');
end if;
end if;
end if;
end;
/
A reader, November 18, 2016 - 3:59 pm UTC
Thank you, it works perfectly.
November 19, 2016 - 1:59 am UTC
glad we could help
Update same table with previous date data
Srinivas, January 29, 2018 - 6:53 pm UTC
Hi All,
I have write update code using merge and I have written Insert code as well.
My requirement is when effective_date = current_date it should update and if it is not equal then it should insert.
It is working but while inserting if we modify any data then it is not reflecting.
January 30, 2018 - 2:45 am UTC
Please ask this as a new question with a *full* test case.