I have a stored procedure in which if I write the following query without a variable, all: works well
CREATE PROCEDURE `some_proc` ()
BEGIN
SELECT blabla FROM mytable ORDER BY id LIMIT 3,1
.....
but, if I use a variable as start number in LIMIT expression, I get an error:
CREATE PROCEDURE `some_proc` ()
BEGIN
DECLARE start INT;
SET start = 3;
SELECT blabla FROM mytable ORDER BY id LIMIT start,1
.....
Is there a way to use a variable in the LIMIT expression inside the stored procedure?
You cannot use a variable directly. A nice workaround that I’ve seen is –
Another search returned this – http://bugs.mysql.com/bug.php?id=8094.
Also you can read more about prepared statements in the manual.