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;

 1

2

 

3

posted @ 2016-10-09 10:48  Ving鸣人  阅读(6607)  评论(2编辑  收藏  举报