使用游标,实现类似于for循环的操作。
BEGIN
DECLARE t VARCHAR(200);
DECLARE t1 int ;
DECLARE ls_cursor CURSOR FOR SELECT name FROM user;
#游标结束时,设置状态
DECLARE CONTINUE HANDLER FOR NOT FOUND SET t1=1;
SET t1=0;
#开启游标
OPEN ls_cursor;
FETCH next FROM ls_cursor into t;
WHILE (t1=0) DO
#设置业务逻辑
SELECT t as 结果;
FETCH next FROM ls_cursor into t;
END WHILE;
#关闭游标
CLOSE ls_cursor;
END