我正在尝试创建一个动态 ALTER TABLE 命令,但某些命令将从查询中生成。问题是我想在触发器中使用它!
尝试1:
ALTER TABLE `redinfomanager` CHANGE `Unterkategorie` `Unterkategorie` ENUM(("SELECT GROUP_CONCAT(CONCAT('\'', REPLACE(`Unterkategorien`, '\r\n', '\',\''), '\'') SEPARATOR ',') FROM `kategorien` GROUP BY '1'")) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL;
尝试2:
SELECT @tmp:=GROUP_CONCAT(CONCAT('\'', REPLACE(`Unterkategorien`, '\r\n', '\',\''), '\'') SEPARATOR ',') FROM `kategorien` GROUP BY '1';
SET @query=CONCAT('ALTER TABLE `redinfomanager` CHANGE `Unterkategorie` `Unterkategorie` ENUM(', @tmp, ') CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL');
PREPARE stmt FROM @query;
EXECUTE stmt;
尝试 3:
SET @kat = (SELECT GROUP_CONCAT(CONCAT('\'', REPLACE(`Unterkategorien`, '\r\n', '\',\''), '\'') SEPARATOR ',') FROM kategorien GROUP BY '1');
PREPARE stmt FROM 'ALTER TABLE redinfomanager CHANGE Unterkategorie Unterkategorie ENUM(?) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL';
EXECUTE stmt USING @kat;
它告诉我:
1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 '; 附近使用的正确语法。在第 1 行从 'ALTER TABLE
redinfomanager
CHANGEUnterkategorie
'Unte' 准备stmt
我怎么能那样做?
这个错误代表什么?