DELIMITER // -- Create a stored procedure with params CREATE PROCEDURE GetProductsList(MainSubcategory VARCHAR(500), SubcategoryChildName VARCHAR(500), OffsetVal INT, NumberOfRecordPerPage INT, orderLowToHigh Boolean) READS SQL DATA BEGIN
SET @MainSubcategory = MainSubcategory;
SET @SubcategoryChildName = SubcategoryChildName;
IF orderLowToHigh = true THEN
SET @SortOrder = 'ASC';
ELSE
SET @SortOrder = 'DESC';
END IF;
SET @OffsetVal = OffsetVal;
SET @NumberOfRecordPerPage = NumberOfRecordPerPage;
PREPARE mainQuery FROM "SELECT title, product_category_tree, id, images, price, old_price
FROM PRODUCTS
WHERE MATCH(product_category_tree) AGAINST (MainSubcategory IN NATURAL LANGUAGE MODE) AND
product_category_tree LIKE CONCAT('%',?,' >> ',?,'%')
ORDER BY price ?
LIMIT ?, ?;";
EXECUTE mainQuery USING @MainSubcategory, @SubcategoryChildName, @SortOrder, @OffsetVal, @NumberOfRecordPerPage;
DEALLOCATE PREPARE mainQuery;
END// -- Change the delimiter again DELIMITER ;
when I called this procedure I get an error: Error Code: 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 '? LIMIT ?, ?' at line 5 0.0026 sec
It looks like I cannot have variables in limit clause. Is there a workaround in mysql?