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();