1

I just created a trigger on employee table as after updating new value of salary must be large or similar to old salary.

showing error in running trigger showing the code of the trigger

  create trigger fix_salary
  after update on employee
  for each row
  when(old.salary>new.salary)
  begin
  update employee 
  set salary=:old.salary;
  end;
  /

after that i added this to a text file and saved it with .plsql extension. then i added to cmd as:- @"path of the flie";

and when i put a update command as:-

update employee set salary=1000 where eid=1;

after that this error is displayed:

update employee set salary=500 where eid=1
        *
ERROR at line 1:
ORA-04091: table SYSTEM.EMPLOYEE is mutating, trigger/function may not see it
ORA-06512: at "SYSTEM.FIX_SALARY", line 2
ORA-04088: error during execution of trigger 'SYSTEM.FIX_SALARY'
nageshwar
  • 11
  • 3
  • This Oracle, not MySQL. Tag altered. – Akina Apr 11 '20 at 10:47
  • It looks like you are modifying the same table. Check this answer, https://stackoverflow.com/questions/12877732/mysql-trigger-for-updating-same-table-after-insert – Ravi Nain Apr 11 '20 at 10:47
  • Oracle has the same issue, check this way to achieve the same: https://stackoverflow.com/questions/13492015/oracle-trigger-to-update-a-the-same-table – Ravi Nain Apr 11 '20 at 10:48
  • 1
    Oracle recommends ___not___ creating user objects, such as tables or triggers, in the SYSTEM schema. – Abra Apr 11 '20 at 10:55
  • 1
    According to [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users): _Asking a question on Stack Overflow should be the last step in your process for finding an answer_ I Googled for the terms ___oracle trigger table is mutating___ and got almost 50,000 results, including [Get rid of mutating table trigger errors with the compound trigger](http://stevenfeuersteinonplsql.blogspot.com/2016/12/get-rid-of-mutating-table-trigger.html) – Abra Apr 11 '20 at 11:01
  • 1
    @nageshwar Please don't put pictures here. Instead paste as code. – Mayank Porwal Apr 11 '20 at 11:23
  • Share the code of the trigger – Popeye Apr 11 '20 at 14:06

0 Answers0