MYSQL 在 CONCAT 函数中使用 NEW 关键字插入时触发错误

MYSQL trigger error on insert with NEW keyword in CONCAT function

我在 mysql 触发器插入中遇到问题:

CREATE TRIGGER `trg1` AFTER INSERT ON `table1` FOR EACH ROW 

BEGIN
      SET @column = (SELECT GROUP_CONCAT(table_1.col1 SEPARATOR ',')   FROM table2,table3..etc;
      SET @values = (SELECT GROUP_CONCAT(CONCAT_WS('.','NEW', table_1.col1) SEPARATOR ',') FROM table2,table3..etc);
      INSERT INTO log_table(Description)VALUES(CONCAT(@values));
END;
    $$ 
    DELIMITER ;

我正在选择列名称并将其与 NEW 关键字连接,然后将值作为单个字符串插入日志 table。

但是这些值以字符串格式存储为 'NEW.col1,NEW.col2..etc' 而没有新值 keyword.PLs 帮帮我..

table structure

  1. Within the trigger body, the OLD and NEW keywords enable you to access columns in the rows affected by a trigger
  2. In an INSERT trigger, only NEW.col_name can be used.
SET @values = (SELECT GROUP_CONCAT(CONCAT_WS('.',table1.col1,NEW.col1,NEW.col2,NEW.col3) SEPARATOR ',') FROM table2,table3..etc);

您在 ''(引号)中使用了 NEW。将其删除。并使用 NEW.col1.

希望对您有所帮助。