sum value in before oracle trigger -


i have table : table1 (field1, field2, field3). want validate values of updating. if sum(field1) group field2 > 10 raise error.

create or replace trigger hdb_tsgh_revise    before update of field1    on table1     each row declare    v_sum_amt number := 0; begin select sum(field1) v_sum_amt  table1  field2 = 'vnd';  if v_sum_amt  > 10 raise_application_error(-20000, 'error'); end if;  end;  error 4091 at: select sum(field1) v_sum_amt  table1  field2 = 'vnd'; 

please me

it caused because of ora-04091: table name mutating, trigger/function may not see it

as per suggestion given, try using after update trigger instead of before update

since case that, should not update value if error, maybe can re-update old value in case of error in after update trigger.

you can consider using autonomous transaction.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -