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