mysql声明游标的方法:
1、声明变量和游标
declare result varchar(3000); declare flag1 varchar(100); DECLARE done INT DEFAULT FALSE; declare cur1 CURSOR FOR SELECT flag from bmlx;
2、变量赋值
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; set result = '';
3、打开游标和循环
open cur1; read_loop: LOOP
-- 给游标赋值
FETCH cur1 INTO flag1;
-- 跳出循环
IF done THEN LEAVE read_loop; END IF;
-- 循环获取游标数据,进行累加
set result = CONCAT(result, flag1 ,','); END LOOP;
-- 关闭游标
close cur1;
-- 返回参数
set result = CONCAT(result,'<span style="color:Red">'); RETURN result;
更多相关免费学习推荐:mysql教程(视频)