简体   繁体   English

ORA-00936:缺少表达式(sql-oracle)

[英]ORA-00936: missing expression (sql-oracle)

I want to add 100 dollars to the old money, But tell me ORA-00936: missing expression 我想在旧钱中增加100美元,但请告诉我ORA-00936:缺少表达

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;


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. 您不能在after触发器中修改:NEW值。 You can do so in a before trigger though. 不过,您可以before触发before执行此操作。
  • The pseudo record is prefixed with a colon, as :NEW 伪记录以冒号作为前缀,例如:NEW

After adding this trigger, here is the result: 添加此触发器后,结果如下:

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

800

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM