开发者

mysql stored procedure: using declared vars in a limit statement returns an error

开发者 https://www.devze.com 2023-01-28 03:56 出处:网络
I have the following code: delimiter ; DROP PROCEDURE IF EXISTS ufk_test; delimiter // CREATE PROCEDURE ufk_test(IN highscoreChallengeId INT UNSIGNED)

I have the following code:

delimiter ;

DROP PROCEDURE IF EXISTS ufk_test;
delimiter //
CREATE PROCEDURE ufk_test(IN highscoreChallengeId INT UNSIGNED)
BEGIN
DECLARE vLoopOrder INT UNSIGNED DEFAULT 5;
DECLARE vLoopLimit INT UNSIGNED DEFAULT 10;
select * from fb_user LIMIT vLoopOrder,vLoopLimit;
END//

delimiter ;

Mysql returns the following error:

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 'vLoopOrder,vLoopLimit;
END' at line 11
开发者_Go百科

it seems that I cannot use declared variables in a LIMIT statement. is there any other way to overcome this ?

of course this is a simple example, here i could just put static numbers but I need to know if it's possible in any way to use any kind of variables with LIMIT.

Thanks


i use something like:

SET @s = CONCAT('SELECT * FROM table limit  ', vLoopOrder ', ', vLoopLimit); 
PREPARE stmt1 FROM @s; 
EXECUTE stmt1; 
DEALLOCATE PREPARE stmt1;
0

精彩评论

暂无评论...
验证码 换一张
取 消