Description:
\d $ create procedure p()
-- t1 is exactly like t2 (int,int) no indexes
BEGIN
declare a,b,done int;
declare c cursor for select * from t1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
set done = FALSE;
open c;
lbl:loop
fetch c into a,b;
insert into t2(a,b) values(a,b);
if done then
leave lbl;
end if;
end loop;
close c;
END$
in lubuntu 12.4 same case
mysql> \u cur
Database changed
mysql> create table t1(a int,b int);
Query OK, 0 rows affected (0.09 sec)
mysql> insert into t1 values(1,1),(3,4);
Query OK, 2 rows affected (0.06 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> \d $ create procedure p()
-> begin
-> declare a,b,done int;
-> declare c cursor for select * from t1;
-> declare continue handler for not found set done =true;
-> open c;
-> lbl:
-> loop
-> fetch c into a,b;
-> insert into t2(a,b) values(a,b);
-> if done then
-> leave lbl;
-> end if;
-> end loop;
-> close c;
-> end$
Query OK, 0 rows affected (0.35 sec)
mysql> create table t2 like t1;
-> $
Query OK, 0 rows affected (0.08 sec)
mysql> call p$
Query OK, 1 row affected (0.06 sec)
mysql> select * from t2;
-> $
+------+------+
| a | b |
+------+------+
| 1 | 1 |
| 3 | 4 |
| 3 | 4 |
+------+------+
3 rows in set (0.00 sec)
How to repeat:
when ever i call the procedure