BEGIN
#Routine body goes here...
declare tmp0 VARCHAR(1000);
declare tmp1 VARCHAR(1000); declare done int default -1;-- 用于控制循环是否结束 /* 声明游标 */ declare myCursor cursor for select name,address from ads_building_info; /* 当游标到达尾部时,mysql自动设置done=1 */
declare continue handler for not found set done=1; /* 打开游标 */
open myCursor; /* 循环开始 */
myLoop: LOOP /* 移动游标并赋值 */
fetch myCursor into tmp0,tmp1;
if done = 1 then
leave myLoop;
end if; /* do something */ -- 循环输出信息 insert into test_demo (name,address) VALUES (tmp0,tmp1); end loop myLoop; close myCursor; END
来源:https://www.cnblogs.com/devin-sl/p/12527507.html