Hi Guys,
Here’s my table data and my stored procedure in mySql
Table checkval
val
----
5705
5704
5703
5702
5701
Stored Procedure
BEGIN
DECLARE x INT;
DECLARE done INT DEFAULT FALSE;
DECLARE myType INT;
DECLARE cur1 CURSOR FOR select val from checkval;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET x = 10;
WHILE x >= 2 DO
##############
OPEN cur1;
read_loop: LOOP
IF done THEN
LEAVE read_loop;
END IF;
FETCH cur1 INTO myType;
insert into myType values (myType);
END LOOP read_loop;
CLOSE cur1;
SET x = x-1;
##################
END WHILE;
END
Current Output
5705
5704
5703
5702
5701--Loops only twice
5705
5704
5703
5702
5701
Desired Output
5705 - Loops 8 times
5704
5703
5702
5701
5705
5704
5703
5702
5701
5705
5704
5703
5702
5701
5705
5704
5703
5702
5701
5705
5704
5703
5702
5701
5705
5704
5703
5702
5701
5705
5704
5703
5702
5701
5705
5704
5703
5702
5701
In all of this, even when I specify a while loop starting at 10
and ending at 2
, why do I get my output only looped twice in the target table. I was hoping to see it repeated 8 times. Can you pls help me on this? I’m backward with stored procedures, so I guess I’m not putting something in the right place or something like that.