mysql 循环游标老是多一行

weiryou10 2014-11-22 11:29:52
原数据库里面有一张customers表,有7行数据,学习到游标这,想写一个储存过程,创建一张新表,将cust_name每次使用游标读出来并添加到新表中去,这是原表的数据:

这是储存过程:

create procedure uu()
-> begin
-> declare o int;
-> declare u char(50);
-> declare done boolean default 0;
-> declare hh cursor for select cust_name from customers;
-> declare continue handler for not found set done = 1;
-> open hh;
-> create table bb(cust_name char(50) not null);
-> repeat
-> fetch hh into u;
-> insert into bb(cust_name) values(u);
-> until done end repeat;
-> close hh;
-> end //

调用储存过程后,发现多了一行,请问这个肿么破:
...全文
331 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2014-11-22
  • 打赏
  • 举报
回复 1
create procedure uu() -> begin -> declare o int; -> declare u char(50); -> declare done boolean default 0; -> declare hh cursor for select cust_name from customers; -> declare continue handler for not found set done = 1; -> open hh; -> create table bb(cust_name char(50) not null); -> repeat -> fetch hh into u; if done=1 then ... -> insert into bb(cust_name) values(u); -> until done end repeat; -> close hh; -> end //

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧