begin
declare temp_user_id int default null;
declare stop int default 0;
#声明游标
declare temp_cur cursor for select f_user_id from table_test where f_user_id=1;
#声明游标的异常处理
declare
continue handler for sqlstate '02000' set stop=1;
open temp_cur;
fetch temp_cur into temp_user_id;
#判断游标是否到达最后
while stop<>1 do
#各种判断
#读取下一行的数据
fetch temp_cur into temp_user_id;
#循环结束
end while;
#关闭游标
close temp_cur;
end