Skip to content
Advertisement

ORA-00936: missing expression (sql-oracle)

I want to add 100 dollars to the old money, But tell me ORA-00936: missing expression

create table sala(
    salary char(4));

insert into sala values(300);


create or replace trigger update_sal
after insert on sala
for each row
when(new.salary in not null)
begin
    update sala set salary=new.salary + 100;
end;


Advertisement

Answer

The trigger syntax is not correct.

Try this:

create or replace trigger update_sal
before insert on sala
for each row
begin
  if :new.salary is not null then
      :new.salary := :new.salary + 100;
  end if;
end;

Key points:

  • You can’t update the same table that the trigger is on–this causes a mutating table error. The way to do this is by assigning the value directly, as shown above.
  • You can’t modify the :NEW value in an after trigger. You can do so in a before trigger though.
  • The pseudo record is prefixed with a colon, as :NEW

After adding this trigger, here is the result:

insert into sala values(700);
select * from sala;

800
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement