首页 > 解决方案 > 行级触发器问题

问题描述

有人可以让我知道我在下面的代码中犯了什么错误为什么会出现下面的编译错误?

create or replace trigger emp_trigger
before insert or update or delete on emp
for each row
begin
 if inserting then
  dbms_output.put_line('Before inserting Old value is '|| :old.salary ||' New value : '|| :new.salary);
 elsif updating then
  dbms_output.put_line('Before updating Old value is '|| :old.salary ||' New value : '|| :new.salary);
 elsif deleting then
  dbms_output.put_line('Before deleting Old value is '|| :old.salary ||' New value : '|| :new.salary);
 end if;
end;
/


Warning: Trigger created with compilation errors.

SQL> show err;
Errors for TRIGGER EMP_TRIGGER:

LINE/COL ERROR
-------- -----------------------------------------------------------------
3/59     PLS-00049: bad bind variable 'OLD.SALARY'
3/91     PLS-00049: bad bind variable 'NEW.SALARY'
5/58     PLS-00049: bad bind variable 'OLD.SALARY'
5/90     PLS-00049: bad bind variable 'NEW.SALARY'
7/58     PLS-00049: bad bind variable 'OLD.SALARY'
7/90     PLS-00049: bad bind variable 'NEW.SALARY'

标签: plsql

解决方案


现在工作正常

create or replace trigger emp_trigger
before insert or update or delete on emp
for each row
begin
 if inserting then
  dbms_output.put_line('Before inserting Old value is '|| :old.sal ||'
                 New value : '|| :new.sal);
 elsif updating then
  dbms_output.put_line('Before updating Old value is '|| :old.sal ||'
                 New value : '|| :new.sal);
 elsif deleting then
  dbms_output.put_line('Before deleting Old value is '|| :old.sal ||'
                 New value : '|| :new.sal);
 end if;
end;
/

推荐阅读