0

If i update ACK or ReJ column it should update all the other columns with the same GlobalID.

create table t_emp(
    empid varchar2(10) not null,
    empname varchar2(50),
    Dep varchar2(50),
    ACk number(5),
    REJ number(5),
    globalID varchar2(10) default '0'
);

insert into t_emp t values ( 'TM01' , 'Logu','Java',null,null,'01');
insert into t_emp t values ( 'BT01' , 'Logu','Java' ,null,null,'01');
insert into t_emp t values ( 'Oracle01' , 'Logu','DBA' ,null,null,'01');
insert into t_emp t values ( 'Google01' , 'Logu','Design' ,null,null,'0');
insert into t_emp t values ( 'AR02' , 'Uthaya','CRM' ,null,null,'02');
insert into t_emp t values ( 'RIL02' , 'Uthaya','Java' ,null,null,'02');
insert into t_emp t values ( 'EA02' , 'Uthaya','DBA' ,null,null,'02');
insert into t_emp t values ( 'TCS02' , 'Uthaya','Java' ,null,null,null);
insert into t_emp t values ( 'P05' , 'Krish','.Net' ,null,null,'05');
insert into t_emp t values ( 'TCS06' , 'Krish','.Net' ,null,null,'06');
insert into t_emp t values ( 'IBM06' , 'Krish','.Net' ,null,null,'06');

CREATE OR REPLACE TRIGGER t_emp_update
AFTER UPDATE
    ON t_emp
    FOR EACH ROW
DECLARE
    t_Ack varchar2(15);
    t_Rej varchar2(15);
    t_globalID varchar2(10);
    t_empid varchar2(10);
BEGIN
    t_globalID := :new.globalID;
    t_Ack := :new.ACk;
    t_Rej := :new.REJ;
    t_empid := :new.empid;
    IF t_Ack is not null then
        DBMS_OUTPUT.PUT_LINE('t_Ack := ' || t_Ack || ',  t_globalID := '|| t_globalID ||', t_empid := '||t_empid);
        update t_emp set ACk = t_Ack where globalID = t_globalID and empid != t_empid;
    end if;
    IF t_Rej is not null then
        DBMS_OUTPUT.PUT_LINE('t_REJ := ' || t_Rej || ',  t_globalID := '|| t_globalID ||', t_empid := '||t_empid);
        update t_emp set Rej = t_Rej where globalID = t_globalID and empid != t_empid;
    end if;
END;

update t_emp v set Rej = 1 where empid = 'TCS06';

If I Update empid = 'TCS06' it should Update Internally all rows with same globalID (06).

select * from t_emp order by empname,globalID;

I am getting some errors in this trigger.

ORA-04091: table TEST1.T_EMP is mutating, trigger/function may not see it
ORA-06512: at "TEST1.T_EMP_UPDATE", line 17
ORA-04088: error during execution of trigger 'TEST1.T_EMP_UPDATE'

Kindly Help me ...

Yaroslav
  • 6,476
  • 10
  • 48
  • 89
Uthay
  • 505
  • 1
  • 4
  • 7

2 Answers2

1

This link and this other one should be helpfull to understand the error and how to correct it. Also check sample of an AFTER UPDATE trigger.

Check a similar question here at SO with a detailed answer.

Community
  • 1
  • 1
Yaroslav
  • 6,476
  • 10
  • 48
  • 89
0

Please refer these links: INSERT trigger for inserting record in same table(Stackoverflow)

Avoiding Mutating Tables

Community
  • 1
  • 1
TechDo
  • 18,398
  • 3
  • 51
  • 64