mysql cursor infinite loop
Hi! I wanna traverse each row of the table and perform operation based on the values I get using cursor.
Senario:
tbl_bets --> userId, amount, stack, betId
I'm iterating cursor using "WHERE betId = 34", and wanna perform some other operations using amount and stack over each row.
But my Cursor goes infinite loop and sqlyog got stuck.
DECLARE _appUId INT;
DECLARE _stack,_amount FLOAT;
DECLARE cur1 CURSOR FOR SELECT stack,amount,appUId FROM tbl_bets WHERE id = 2;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO _stack,_amount,_appUId;
/*IF done = 0 THEN
LEAVE read_loop; */
/* ////logic here////// */
/*INSERT INTO tbl_test VALUES (_appUId,_stack,_amount);*/
END LOOP;
CLOSE cur1;
END$$
DELIMITER ;
This line is giving error so I removed it.
IF done = 0 THEN LEAVE read_loop;
Query : CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_betWon`() BEGIN DECLARE done INT DEFAULT 0; DECLARE _appUId INT; DECLAR...
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LOOP;
Thanks
Subject
Views
Written By
Posted
mysql cursor infinite loop
5608
May 31, 2011 01:53AM
1140
May 31, 2011 06:01AM
1086
May 31, 2011 06:10AM
1670
May 31, 2011 06:02AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.