[英]Using Select INTO Statement in Mysql Trigger based on If Condition
I want to write a trigger. 我想写一个触发器。 The trigger works in the following manner : 触发器以以下方式工作:
When table R_published gets a new entry, based on a column value in the entry(R_published.whichPublishable) it needs to copy a row from either the project_task_goodread_master table or the project_document_master table into the R_publishedGoodReads OR R_publishedDocuments tables respectively. 当表R_published获取一个新条目时,根据条目(R_published.whichPublishable)中的列值,它需要将行分别从project_task_goodread_master表或project_document_master表复制到R_publishedGoodReads或R_publishedDocuments表中。
I have written the following trigger and I'm getting the error : "#1327 - Undeclared variable: R_publishedGoodReads" 我编写了以下触发器,但出现了错误:“#1327-未声明的变量:R_publishedGoodReads”
CREATE TRIGGER trigger_after_published
AFTER INSERT ON R_published
FOR EACH ROW
BEGIN
IF (NEW.whichPublishable=1) THEN
SELECT * INTO R_publishedGoodReads FROM project_task_goodread_master
WHERE
goodReadID= new.publishedItemId;
ELSEIF (NEW.whichPublishable=2) THEN
SELECT * INTO R_publishedDocuments FROM project_document_master where
documentID=new.publishedItemId;
END IF
END
Is there anything wrong with the syntax ? 语法有什么问题吗? Do I need to declare the table name that I am using for insert ? 我需要声明要用于插入的表名吗? Thanks. 谢谢。
MySQL doesn't support SELECT...INTO TABLE. MySQL不支持SELECT ... INTO TABLE。 See MySQL Documentation 参见MySQL文档
Try instead: 请尝试:
IF (NEW.whichPublishable=1) THEN
INSERT INTO R_publishedGoodReads (col1, col2...)
SELECT col1, col2... FROM project_task_goodread_master
WHERE goodReadID= new.publishedItemId;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.