mysql 存储过程 cursor 范例

declare v_total int default 0;
declare no_list cursor for select no,id from table;
select count(1) into v_total from table;

open no_list;
loop1:loop
-- mysql cursor 不会自动退出cursor 循环,需自行增加条件判断
IF i > v_total THEN LEAVE loop1; end if;
-- 根据游标当前指向的一条数据
fetch no_list into v_no , v_id ;

--do operation here

set i = i+1;
end loop;
close no_list;

猜你喜欢

转载自blog.csdn.net/u013240609/article/details/80667972
今日推荐