I am trying to write a simple procedure but am encountering a syntax error at the first parameter. As best I can tell I'm following the syntax of CREATE PROCEDURE correctly.
I am limited to accessing my database with phpMyAdmin. Here is the create script I'm trying to run:
DROP PROCEDURE IF EXISTS product_index_swap/
CREATE PROCEDURE product_index_swap (@id INT, @oldIndex INT, @newIndex INT)
BEGIN
DECLARE @swapID;
SET @swapID = (SELECT `id` FROM `product` WHERE `order_index` = @newIndex LIMIT 1);
UPDATE `products` SET `order_index` = (CASE WHEN `id` = @id THEN @newIndex
WHEN `id` = @swapID THEN @oldIndex END)
WHERE `id` IN (@id, @swapID);
END
I am using the option on phpMyAdmin to change the delimiter to /.
I receive a syntax error "near '@id INT, @oldIndex INT....
". I thought I may encounter more delimiter errors since I'm not entirely clear on the scope of them. I believe if that was the problem the error would be on a new line in the procedure when it failed to understand a semicolon, not at the parameters declaration.