MYSQL的触发器中 变量赋值
CREATETRIGGERsync_doingBEFOREINSERTONet_contentFOREACHROWBEGINSELECT@uc_id:=user_head...
CREATE TRIGGER sync_doing BEFORE INSERT ON et_content
FOR EACH ROW BEGIN
SELECT @uc_id:=user_head FROM et_users WHERE user_id=NEW.user_id; //报错!!!
INSERT INTO `school`.`et_content2` (`content_id`, `user_id`, `content_body`, `media_body`, `posttime`, `type`, `filetype`, `retid`, `replyid`, `replytimes`, `zftimes`) VALUES
(null, @uc_id, NEW.content_body, '', 1302966296, '网页', '', 0, 0, 0, 0);
END
怎么在触发器中select赋值变量??
自己解决了。。。
CREATE TRIGGER `sync_doing` BEFORE INSERT ON `et_content`
FOR EACH ROW BEGIN
declare v_2 varchar(50);
declare v_3 int(10);
set v_2=NEW.content_body;
set v_3=(select user_head FROM `et_users` WHERE user_id=NEW.user_id);
INSERT INTO `et_content2` (`content_id`, `user_id`, `content_body`, `media_body`, `posttime`, `type`, `filetype`, `retid`, `replyid`, `replytimes`, `zftimes`) VALUES
(null, v_3, v_2, '', 1302966296, '网页', '', 0, 0, 0, 0);
END
谁TMD说MYSQL赋值要: 变量要@的!!谁TM的还说MYSQL变量不要声明!!! 展开
FOR EACH ROW BEGIN
SELECT @uc_id:=user_head FROM et_users WHERE user_id=NEW.user_id; //报错!!!
INSERT INTO `school`.`et_content2` (`content_id`, `user_id`, `content_body`, `media_body`, `posttime`, `type`, `filetype`, `retid`, `replyid`, `replytimes`, `zftimes`) VALUES
(null, @uc_id, NEW.content_body, '', 1302966296, '网页', '', 0, 0, 0, 0);
END
怎么在触发器中select赋值变量??
自己解决了。。。
CREATE TRIGGER `sync_doing` BEFORE INSERT ON `et_content`
FOR EACH ROW BEGIN
declare v_2 varchar(50);
declare v_3 int(10);
set v_2=NEW.content_body;
set v_3=(select user_head FROM `et_users` WHERE user_id=NEW.user_id);
INSERT INTO `et_content2` (`content_id`, `user_id`, `content_body`, `media_body`, `posttime`, `type`, `filetype`, `retid`, `replyid`, `replytimes`, `zftimes`) VALUES
(null, v_3, v_2, '', 1302966296, '网页', '', 0, 0, 0, 0);
END
谁TMD说MYSQL赋值要: 变量要@的!!谁TM的还说MYSQL变量不要声明!!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询