行级触发器的问题

时间:2018-11-20 09:26:47

标签: 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.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'

1 个答案:

答案 0 :(得分:1)

现在可以正常工作

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;
/