mysql游标cursor与for循环


delimiter //

create procedure p2()
begin
    declare row_id int DEFAULT 0;
    declare row_num int DEFAULT 0;
    declare done int default False;
    declare temp int DEFAULT 0;

    declare my_cursor cursor  for select id, num from a;
    declare continue handler for not found set done = True;

    open my_cursor;
            n:loop
                fetch my_cursor into row_id, row_num;
                if done then
                    leave n;
                end if;
                set temp = row_id + row_num;
                insert into b(num) values(temp);
            end loop n;
    close my_cursor;

end //

delimiter ;

call p2();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM