Reputation: 1
I have been searching for this solution all over the internet and I haven't been able to find the solution for this:
I am trying to get the following code to run:
BEGIN
DECLARE @var int
SELECT @var =5
WHILE @var > 0
PRINT replicate('* ', @var)
SET @var = @var - 1
END
I have been trying to run this query, and I am getting the following message:
ERROR 1064 (42000): 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 @var int SELECT @var = 5
WHILE @var > 0 ' at line 1
I know that there have been iterated many times, but the solution discussed in other conversations have not been working on my console.
Upvotes: 0
Views: 1145
Reputation: 49375
Your code is actually sql server, which doesn't work in mysql
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `ABC`(
IN _tablename VARCHAR(50) -- is a parameter in which table
-- name is stored
)
BEGIN
SET @var = 5;
WHILE @var > 0 DO
select repeat('* ', @var);
SET @var = @var - 1;
END WHILE;
End$$
DELIMITER ;
To give you a better understanding.
This procedure return 5 Recordset, depending on which programing language you use, such multi queries may not be supprted. In workbench you see them, when you run `CALL testdb1.ABC('test');
Upvotes: 1