在phpMyAdmin中创建带输入参数的MySQL存储过程遇#1064错误求助
Hey there! That error is super common when building stored procedures in phpMyAdmin—let’s break down what’s going wrong and how to fix it.
The Root Cause
phpMyAdmin uses the semicolon (;) as its default statement delimiter. When you wrote your stored procedure, the SELECT * FROM Toy WHERE Toy_ID = toy_no; line ends with a semicolon. MySQL sees that semicolon and thinks, "Okay, the entire CREATE PROCEDURE command is done here!" Then it tries to parse the remaining END; as a brand-new statement, which doesn’t make any sense—hence the syntax error.
The Fix: Temporarily Change the Delimiter
We need to tell MySQL to use a different delimiter (like //) while we define the stored procedure, then switch back to the semicolon afterward. Here’s the corrected code:
DELIMITER // CREATE PROCEDURE searchtoy (IN toy_no INT) BEGIN SELECT * FROM Toy WHERE Toy_ID = toy_no; END // DELIMITER ;
How to Use This in phpMyAdmin
Just paste the entire block above into the SQL window and click "Go". The DELIMITER // line tells MySQL to treat // as the end of a full statement instead of ; until we run DELIMITER ; to reset it.
That should resolve the #1064 error and create your stored procedure successfully!
内容的提问来源于stack exchange,提问作者beginIT

