1

是否可以在 mysql 触发器中声明一个变量并使用该变量通过 NEW 和/或 OLD 访问字段值?

这是一个例子:

CREATE TRIGGER TestTrigger AFTER UPDATE on ARTICLE
  FOR EACH ROW
  BEGIN
   DECLARE fieldname VARCHAR(40);
   SET fieldname = "my_field;

   UPDATE ARTICLE
   SET foo = NEW.[my_field]
   WHERE ArtID = NEW.ArtID;  
END
4

1 回答 1

1

In short you can't and not only dynamically referencing column names of a row being updated by a trigger using OLD and NEW but also you can't execute any DML statement (in your case UPDATE) on the same table on which you defined your trigger.

于 2013-10-21T14:28:14.973 回答