在为可调用语句创建存储过程期间出错: 我知道有些事情很简单会出错,但我无法理解!
我的查询:
USE演示;
1. CREATE PROCEDURE
2. INSERT_emp_data (IN ID INT, IN NAME VARCHAR(2), IN AGE INT, IN IMAGE BLOB)
3. BEGIN
4. INSERT INTO emp_data VALUES(ID, NAME, AGE, IMAGE);
5. END;
/
SQL查询:
CREATE PROCEDURE
INSERT_emp_data (IN ID INT, IN NAME VARCHAR(2), IN AGE INT, IN IMAGE BLOB)
BEGIN
INSERT INTO emp_data VALUES(ID, NAME, AGE, IMAGE);
MySQL said: Documentation
#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 4
感谢您的帮助! 谢谢你的时间!
答案 0 :(得分:2)
在MySQL中编写存储过程时,应使用DELIMITER
语句。此外,您应该为列命名,以使它们不与列名冲突。并且,使用INSERT
时始终列出列名称。所以:
DELIMITER $$
CREATE PROCEDURE INSERT_emp_data (
IN IN_ID INT,
IN IN_NAME VARCHAR(2),
IN IN_AGE INT,
IN IN_IMAGE BLOB
)
BEGIN
INSERT INTO emp_data(id, name, age, image)
VALUES(IN_ID, IN_NAME, IN_AGE, IN_IMAGE);
END;
$$
DELIMITER ;