I am working on a stored procedure in mariadb and I try to dynamically limit the number of rows. If I hardcode the Limit e.g. LIMIT 5 my procedure works perfectly but if I write LIMIT @below it I receive a quite generic sql syntax error. I can use the variable @below everywhere else in my statement but not after LIMIT. Would be nice to understand this behavior?
SET sql_mode=ORACLE;
CREATE PROCEDURE hello AS
BEGIN
DECLARE
below INT;
BEGIN
SELECT round(COUNT(*)/2) FROM tableName INTO @below;
SELECT
col1,col2, col3, @below /* this is ok*/
FROM tableName
WHERE col1=@below /* this is ok*/
LIMIT @below; /* doesn't work*/
END;
END hello;
I receive this error:
SQL ERROR(1064): You have an error in your SQL syntax check the manual that corresponds to your MariaDB server version for the right syntax to use near '@below
Thanks Amit