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

2

There are 2 answers

1
Littlefoot On

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;
0
milind brahme On

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