I have this trigger
create or replace trigger upd_totprc_trg
after insert or update or delete of total_price on sales_detail
for each row
declare
v_diff number := 0;
v_master number;
begin
if inserting then
v_master := :new.master_id;
v_diff := :new.total_price;
elsif updating then
v_master := :new.master_id;
v_diff := :new.total_price - :old.total_price;
elsif deleting then
v_master := :old.master_id;
v_diff := :old.total_price * -1;
end if;
update sales_master
set value = value + v_diff
where id = v_master;
end;
/
it calculates the changes in sales_detail.total_price
and updates the sales_master.value
.
the thing is that the total_price
column is a virtual column defined as the product of quantity and unit_price.
When I enter new detail row the trigger seems not to catch the new calculated value even though it's an after
. My question is: does the execution of the virtual column expression conflicts with the running of the trigger? note that when I set the total_price
as a normal column again it returned correct values.
I am using Oracle 12c