利用mysql游标循环结果集 阿星小栈
USE test;
DELIMITER //
CREATE PROCEDURE pro8(OUT para1 VARCHAR(20))
BEGIN
DECLARE myid INT(11);
DECLARE title VARCHAR(100);
DECLARE i INT DEFAULT 0;
DECLARE str VARCHAR(60);
DECLARE len INT(2);
DECLARE num INT;
DECLARE cur CURSOR FOR SELECT id FROM test.`info`;
SELECT COUNT(*) INTO num FROM test.`info`;
SET str='';
OPEN cur;
WHILE i<num DO
FETCH cur INTO myid;
SET str = CONCAT(str,myid,',');
SET i=i+1;
END WHILE;
SELECT LENGTH(str) INTO len;
SELECT SUBSTR(str,1,len-1) INTO para1;
CLOSE cur;
END//
DELIMITER ;
CALL pro8(@a);
SELECT @a;
http://blog.csdn.net/baixiaoshi/article/details/40112265
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步