'MySQL Syntax Error when Select Count into inout Variable
Here is the code:
CREATE PROCEDURE CountOrderByStatus(
IN orderStatus VARCHAR(25),
OUT total INT)
BEGIN
SELECT count(orderNumber)
INTO total
FROM orders
WHERE status = orderStatus;
END
When I try to execute this, i get the following error:
Error SQL (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 '' at line 8
I was googling for a while, but I can't find any information about this problem. Many sources does not refer such type of code as invalid. For example, fragment above found at this site.
Any ideas, why everybody is saying, that is normal, but MySQL produces such strange error?
P.S.: MySQL Server 5.6 at Windows 8.1.
Solution 1:[1]
Was forget to add DELIMITER. It must look:
DELIMITER $$
CREATE PROCEDURE CountOrderByStatus(
IN orderStatus VARCHAR(25),
OUT total INT)
BEGIN
SELECT count(orderNumber)
INTO total
FROM orders
WHERE status = orderStatus;
END$$
DELIMITER ;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | vinzee |