I need to write a trigger, if a particular field value is changed (say employee type from salary to hourly or hourly to salary) then the the record id value need to be updated.
Note: for me old_clock will maintain the id without prefix S or H
example of id: S222222 or H3333333
clock: 222222 or 333333
I am getting the error
One error saving changes to table "USERS":
Row 1: ORA-04091: table USERS is mutating, trigger/function may not see it
ORA-06512: at "TRIGGER_UPDATE_USERS_ID", line 20
ORA-04088: error during execution of trigger 'TRIGGER_UPDATE_USERS_ID'
CODE:
```create or replace TRIGGER "TRIGGER_UPDATE_USERS_ID"
AFTER UPDATE OF
empl_type
ON USERS
FOR EACH ROW
DECLARE
new_empl_type varchar(5);
old_empl_type varchar(5);
old_pw_clock varchar(10);
BEGIN
new_empl_type := :NEW.empl_type;
old_empl_type := :OLD.empl_type;
old_clock := :OLD.clock;
if
old_empl_type ='S' and new_empl_type ='H'
then
UPDATE USERS set id = 'H'||old_clock
where id = 'S222222';
DBMS_OUTPUT.PUT_LINE('updated with new id prefix to Z '|| new_empl_type);
elsif
old_empl_type ='H' and new_empl_type ='S'
then
UPDATE USERS set id = 'S'||old_clock
where id = 'H274952';
DBMS_OUTPUT.PUT_LINE('updated with new id prefix to M '|| new_empl_type);
end if;
END;```