原数据库里面有一张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 //调用储存过程后,发现多了一行,请问这个肿么破:

解决方案 »

  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 //