触发器创建无效

时间:2013-04-10 13:53:07

标签: mysql triggers phpmyadmin

我遇到与在phpmyadmin上创建触发器有关的问题。 我有一个简单的代码,如下所示,当我提交代码时,在变量x声明的行中返回一个sintax错误。我知道SELECT查询有效,因为我测试了它,并返回一个字符串。谁能帮我?提前谢谢。

DELIMITER $$

CREATE TRIGGER `after_assigntags_insert` AFTER INSERT ON `assigntags`
FOR EACH ROW 
BEGIN
DECLARE x VARCHAR(10);
SET x = (SELECT UltLabel FROM assignlabels WHERE ALmessage=1);
INSERT INTO messages (Message) VALUES (x);
$$
END

DELIMITER ;

3 个答案:

答案 0 :(得分:0)

如何使用user variables

DELIMITER $$

CREATE TRIGGER `after_assigntags_insert` AFTER INSERT ON `assigntags`
FOR EACH ROW 
BEGIN
   SET @x = (SELECT UltLabel FROM assignlabels WHERE ALmessage=1 LIMIT 1);
   INSERT INTO messages (Message) VALUES (@x);
$$
END

DELIMITER ;

答案 1 :(得分:0)

我认为BEGIN来自DECLARE

DELIMITER $$

CREATE TRIGGER `after_assigntags_insert` AFTER INSERT ON `assigntags`
FOR EACH ROW 

DECLARE 
  x VARCHAR(10);
BEGIN
  SET x = (SELECT UltLabel FROM assignlabels WHERE ALmessage=1);
  INSERT INTO messages (Message) VALUES (x);
  $$
END

DELIMITER ;

答案 2 :(得分:0)

这是语法错误,

END应该在您的分隔符$$之前。

尝试这样的事情:

DELIMITER $$

CREATE TRIGGER `after_assigntags_insert` AFTER INSERT ON `assigntags`
FOR EACH ROW 
BEGIN
DECLARE x VARCHAR(10);
SET x = (SELECT UltLabel FROM assignlabels WHERE ALmessage=1);
INSERT INTO messages (Message) VALUES (x);
END
$$

DELIMITER ;