mysql存储过程之循环遍历查询结果集
https://blog.csdn.net/fish_study_csdn/article/details/125263253
CREATE DEFINER=`root`@`%` FUNCTION `test`(intParam INT,strParam VARCHAR(50)) RETURNS varchar(4000) CHARSET utf8mb4
BEGIN
DECLARE resultStr VARCHAR(4000) DEFAULT '';
DECLARE sTempChd VARCHAR(4000);
DECLARE s INT DEFAULT 0;
DECLARE si Int ;
DECLARE album_curosr CURSOR FOR SELECT `name` from sys_dept LIMIT 2;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET s = 1;
open album_curosr;
FETCH album_curosr INTO sTempChd;
SET resultStr = CONCAT( ',', sTempChd );
set si = 0;
WHILE s <> 1 DO
FETCH album_curosr INTO sTempChd;
if s <> 1 THEN
SET resultStr = CONCAT(resultStr,',' , sTempChd);
end if;
-- SET resultStr = CONCAT(resultStr,',' , sTempChd);
END WHILE;
CLOSE album_curosr;
-- RETURN CONVERT(si,CHAR);
RETURN resultStr;
END
择善人而交,择善书而读,择善言而听,择善行而从。