Whenever I try to create the below stored procedure.
CREATE PROCEDURE purchaseItem (IN productID INT, IN quantity INT, IN price DECIMAL(10,2) , IN memID INT)
BEGIN
DECLARE qnty INT DEFAULT 0;
SELECT p_Unit INTO qnty FROM product WHERE p_ID = productID;
IF qnty >= quantity && qnty != 0 THEN
INSERT INTO purchase VALUES (NULL, productID, quantity, price, memID, 0, NULL);
UPDATE product SET p_Unit = (qnty - quantity) WHERE p_ID = productID;
END IF;
END;
I get the error
#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 3
Can someone please point out me where I'm doing wrong. Thanks!
Don't forget to change the DELIMITER
, try the following query without using SELECT..INTO
DELIMITER $$
CREATE PROCEDURE purchaseItem
(
IN productID INT,
IN quantity INT,
IN price DECIMAL(10,2) ,
IN memID INT
)
BEGIN
DECLARE qnty INT;
SET qnty = (SELECT p_Unit FROM product WHERE p_ID = productID);
IF qnty >= quantity && qnty != 0 THEN
INSERT INTO purchase VALUES
(NULL, productID, quantity, price, memID, 0, NULL);
UPDATE product
SET p_Unit = (qnty - quantity)
WHERE p_ID = productID;
END IF;
END$$
DELIMITER ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.