Hi,
I have a trigger which fires on change in certain fields & inserts the old field data in a history table.
If the field has value (e.g.college name) & I replace it with null, a record is inserted with the member id in the history table but the old value (college name) is not inserted. This happens with any of fields. Please find below the code. This happens only if the field data is blank/null.
for e.g. if the college ADD1 has data "12th Street, Mumbai" & while updating the field, I blank it/remove "12th Street, Mumbai". So it has to update the history table with "12th Street, Mumbai" but it doesn't - inserts a record in the history table with member id. What changes do I need to do to get the old value updated in the history table.
-----------------------------------------------------
create or replace trigger "TGR_STUDENT_MST_CHG"
before Update or Insert of
MEMBER_ID,
COLLEGE_NAME,
COLLEGE_ADD1,
on T_STUDENT_MST
for each row
declare
VCOLLEGENAME t_student_mst.COLLEGE_NAME%type;
VCOLLEGEADD1 t_student_mst.COLLEGE_ADD1%type;
begin
if old.COLLEGE_NAME <> :new.COLLEGE_NAME) then
VCOLLEGENAME := ld.COLLEGE_NAME ;
else VCOLLEGENAME := null ;
end if;
if OLD.COLLEGE_ADD1 <> :NEW.COLLEGE_ADD1) then
VCOLLEGEADD1 := :OLD.COLLEGE_ADD1;
else VCOLLEGEADD1 := null ;
end if;
if updating then
insert into T_STUDENT_HST (
MEMBER_ID,
COLLEGE_NAME,
COLLEGE_ADD1)
values old.member_id,
VCOLLEGENAME,
VCOLLEGEADD1);
end if ;
end TGR_STUDENT_MST_CHG;
---------------------------------------------
TIA,
Raj
I have a trigger which fires on change in certain fields & inserts the old field data in a history table.
If the field has value (e.g.college name) & I replace it with null, a record is inserted with the member id in the history table but the old value (college name) is not inserted. This happens with any of fields. Please find below the code. This happens only if the field data is blank/null.
for e.g. if the college ADD1 has data "12th Street, Mumbai" & while updating the field, I blank it/remove "12th Street, Mumbai". So it has to update the history table with "12th Street, Mumbai" but it doesn't - inserts a record in the history table with member id. What changes do I need to do to get the old value updated in the history table.
-----------------------------------------------------
create or replace trigger "TGR_STUDENT_MST_CHG"
before Update or Insert of
MEMBER_ID,
COLLEGE_NAME,
COLLEGE_ADD1,
on T_STUDENT_MST
for each row
declare
VCOLLEGENAME t_student_mst.COLLEGE_NAME%type;
VCOLLEGEADD1 t_student_mst.COLLEGE_ADD1%type;
begin
if old.COLLEGE_NAME <> :new.COLLEGE_NAME) then
VCOLLEGENAME := ld.COLLEGE_NAME ;
else VCOLLEGENAME := null ;
end if;
if OLD.COLLEGE_ADD1 <> :NEW.COLLEGE_ADD1) then
VCOLLEGEADD1 := :OLD.COLLEGE_ADD1;
else VCOLLEGEADD1 := null ;
end if;
if updating then
insert into T_STUDENT_HST (
MEMBER_ID,
COLLEGE_NAME,
COLLEGE_ADD1)
values old.member_id,
VCOLLEGENAME,
VCOLLEGEADD1);
end if ;
end TGR_STUDENT_MST_CHG;
---------------------------------------------
TIA,
Raj