plsql中的新旧用法

时间:2014-01-07 20:29:54

标签: sql oracle plsql

任何人都可以告诉我以下代码有什么问题

create trigger salary_chk before update on employees for each row
when (employee_id>0)
declare
  begin
    if(new.salary>old.salary*1.2)
      signal 'You cannot do this';
    end if;
  end;
/

我收到以下错误

Error report:
ORA-04076: invalid NEW or OLD specification
04076. 00000 -  "invalid NEW or OLD specification"
*Cause:    An invalid NEW or OLD specification was given for a column.
*Action:   Re-specify the column using the correct NEW or OLD specification.

2 个答案:

答案 0 :(得分:1)

create trigger salary_chk before update on employees for each row
when (:new.employee_id>0)
declare
  old integer = :old.salary * 1.2;

  begin
    if(:new.salary>old)
      signal 'You cannot do this';
    end if;
  end;

试一试。我无法看到为什么它不应该工作,因为它的PL / SQL

答案 1 :(得分:1)

create trigger salary_chk 
before update 
on employees 
for each row
when (new.employee_id > 0) -- missing new
  begin
    if( :new.salary > :old.salary*1.2) -- Missing colons
    then -- Missing then
      dbms_alert.signal('my_alert', 'You Cannot Do this');
    end if;
  end;
/