I'm using MySQL, of course.
However, I'm unable to run any while loop in the text box in the browser to update records in a table - I'm getting an error.
DECLARE @count INT
SET @count = 0
WHILE @count <2000 DO
/* loop logic in here */
SET @count = @count + 1;
END WHILE;
Is the above code wrong?
Here is the error:

MySQL said:
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 'DECLARE @count INT SET @count = 0 WHILE @count <2000 DO SET @count = @co' at line 1
You can do this with a procedure like this :
DELIMITER $$
DROP PROCEDURE IF EXISTS test$$
CREATE PROCEDURE test()
BEGIN
DECLARE count INT DEFAULT 0;
WHILE count < 2000 DO
/* statment */
SET count = count + 1;
END WHILE;
END$$
DELIMITER ;
mysql>call test();
Hope this help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With