【问题标题】:PLSQL Trigger: before insertPLSQL 触发器:插入前
【发布时间】:2014-04-12 11:33:42
【问题描述】:

我正在尝试编写一个触发器,该触发器必须在插入之前限制为零工资。 我已经写了,但它不起作用。我收到一个错误,因为触发器无效并且重新验证失败。

代码:

create or replace trigger emp_sal
  before insert or update on employee
  referencing new as new old as old
  for each row
begin
     if :new.salary<=0 then
         raise_application_error (-20999,’salary is zero’);
     end if;
end;
/

请告诉我问题出在哪里。谢谢

【问题讨论】:

  • 为什么不使用检查约束呢?

标签: oracle plsql triggers


【解决方案1】:

您的代码没问题。我能想象的唯一问题是你在“salary is zero”中的单引号中使用了错误的字符。

在创建触发器后立即运行 show errors(假设您正在使用 sqlplus)

但我同意 zerkms。这是一个检查约束的例子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2010-11-22
    相关资源
    最近更新 更多