我先建了一个存储过程,大致是用于统计某论坛贴子功能的.我计划当论坛数据表中插入或修改或删除记录时,用一个触发器来调用重新统计贴子数的存储过程.存储过程如下:
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`bbstextcount` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `bbstextcount`(IN authorid INTEGER,IN lsbbsid Integer)
BEGIN
DECLARE depart1ID integer;
DECLARE DEPART2ID integer;
DECLARE tempstring1 varchar(50);
DECLARE tempstring2 varchar(50);
DECLARE newnum integer;
DECLARE total integer;
select userdepart1,userdepart2 into tempstring1,tempstring2 from user where userid= authorid;
select userdepartid into depart1id from depart1 where depart1.userdepart=tempstring1;
select userdepartid;
........
END $$
DELIMITER ;
触发器我是这样写的:
create trigger addbbstext after insert on bbstext for each row call bbstextcount(NEW.userid,NEW.bbsid);
但是当插入数据时,后台报错:Not allowed to return a result set from a trigger
找个半天毛病,后来去掉了存储过程中的"select userdepartid; "一句,问题解决.开始以为是trigger定义的错误,后来找了一下网络,有朋友建议把存储过程中的select 输出语句去掉,解决了问题.