【问题标题】:ORA-00936: missing expression (sql-oracle)ORA-00936: 缺少表达式 (sql-oracle)
【发布时间】:2019-06-15 00:20:24
【问题描述】:

我想在旧钱上加 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;


【问题讨论】:

  • insert into sala values('300'); 该列是 varchar 还是数字?您的数据类型很粗略。
  • in not null ???
  • @TheImpaler '300' 不添加
  • @GordonLinoff 是的
  • @koki - when(new.salary IS not null)

标签: sql oracle


【解决方案1】:

触发器语法不正确。

试试这个:

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;

关键点:

  • 您无法更新触发器所在的同一个表 - 这会导致 mutating table 错误。这样做的方法是直接赋值,如上所示。
  • 您不能修改after 触发器中的:NEW 值。不过,您可以在 before 触发器中执行此操作。
  • 伪记录以冒号为前缀,如:NEW

添加此触发器后,结果如下:

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

800

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多