Trigger with update

Asked

Viewed 42 times

-2

I have a table emp with salary, id, and job and added a new column value in this column. I will update when the employee receives a raise. I created a support table where I have id , salary,date and new_salary I created the first one trigger when there is a insert in table a trigger fires and inserts into the support table (it’s working so far), then I need to update the table emp with value = new salary - salary. I compiled the trigger but when I execute update table emp appears error: ora-06519: active autonomous transition and if I take the pragma the mistake changes to: ora-04091:the table emp_log is mutant

Original text for consultation: I have a table emp with salary, id, and job and add a new column value in this column I will do update when Employee receive an Increase. I created a table support when I have id , salary,date and new_salary I created a first Trigger when a Insert in table emp the Trigger Shoots and Insert in table support (it’s Working until here) , after I need update the table emp with value = new salary - salary. I Compiled Trigger but when I execute update on emp show error: ora-06519: active Autonomous Transition and if I take pragma change error to: ora-04091:the table emp_log is Mutant

    CREATE OR REPLACE TRIGGER new_salario_emp
AFTER INSERT
   ON emp_log
   FOR EACH ROW
   --
 DECLARE
 Pragma Autonomous_Transaction;
 --
 BEGIN
 --
 update emp_log set old_salario = :new.sal - :new.old_salario where empno = 
:new.empno;
 --
END;
  • 3

    You may not have noticed (which is strange), but we are on [pt.so], so you can (and should) ask the question in Portuguese. Take the [tour] now and read the [Ask] guide. If you have any questions, go to [help] and/or [meta].

1 answer

0

I don’t understand: your Rigger should not be in the original table (EMP) and not in the support table (EMP_LOG)?

It seems to me that you want to keep only the last salary before the change. Is that it? Then in the inclusion of an EMP line you must include a row in the EMP_LOG E table in the change of SALARY in EMP you that update EMP_LOG.

If this is true, create an AFTER INSERT TRIGGER on EMP and include the line in EMP_LOG. Create a TRIGGER AFTER UPDATE SALARY on EMP and update the EMP_LOG table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.