带PL / SQL触发器的UPDATE表?

时间:2013-12-01 20:46:32

标签: sql oracle plsql triggers

我有这个触发器,当我运行它时,我收到一条错误消息; “坏绑定变量”。 我似乎无法看到问题所在。任何帮助将不胜感激。

create or replace TRIGGER trg_placed AFTER UPDATE
OF STATUS_ID  ON STATUS
FOR EACH ROW
BEGIN
  IF :new.STATUS_ID = 7 
  THEN
     UPDATE STUDENT
        SET PLACED_Y_N = 'Y'
      WHERE RECORD_NUMBER = :NEW.record_number;
  END IF;
END;

2 个答案:

答案 0 :(得分:0)

尝试这样:

create or replace TRIGGER trg_placed AFTER UPDATE

OF STATUS_ID  ON STATUS

REFERENCING OLD AS o NEW AS n

FOR EACH ROW

BEGIN

   IF n.STATUS_ID = 7 

   THEN

      UPDATE STUDENT

      SET PLACED_Y_N = 'Y'

      WHERE RECORD_NUMBER = n.record_number;

  END IF;

END;

答案 1 :(得分:0)

如果对Oracle对象使用小写,则必须用引号(“)包围对象名称,并完全匹配案例以使其起作用。

像这样

create or replace TRIGGER trg_placed AFTER UPDATE
 OF STATUS_ID  ON STATUS
 FOR EACH ROW
BEGIN
IF :new.STATUS_ID = 7 
THEN
 UPDATE STUDENT
    SET PLACED_Y_N = 'Y'
  WHERE RECORD_NUMBER = :NEW."record_number"; --quotes (") required for column name.
END IF;
END;