简体   繁体   中英

UPDATE table with PL/SQL trigger?

I have this trigger, and I am getting an arror message when I run it; "bad bind variable". I can't seem to see where the problem lies. Any help would be appreciated.

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;

try like this:

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;

If you use lowercase for Oracle objects, you'll have to surround object names with quotes (") and match the case exactly to get it to work.

like this

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM