Home > Mobile >  pl/sql-create trigger on a table -whenever a new record is inserted in the same table another column
pl/sql-create trigger on a table -whenever a new record is inserted in the same table another column

Time:12-07

create trigger calculation after insert on employee 
for each row
begin
if :new.updated_sal is null
then
update employee set updated_sal= (10/100)* salary
where id=:new.id;
end if;
end;

I would like to create a trigger on the employee table, whenever a new record is inserted in the same table, a 10% of salary in the salary column should be calculated and put into another column updated_sal. If I try to insert a new record, it is showing that the table is mutated, etc

CodePudding user response:

It's just the :new pseudorecord you need:

create trigger calculation 
  after insert on employee 
  for each row
begin
  if :new.updated_sal is null then
     :new.updated_sal := (10/100) * :new.salary; 
  end if;
end;

CodePudding user response:

You need to use before insert trigger, And use :New.updated_sal:= :new.salary * somevalue To assign salary.

  • Related