MySQL无法创建程序

时间:2012-04-23 17:59:49

标签: mysql

我正在尝试创建一个程序(将一个新的类名,类型,国家,枪支数量,钻孔和位移作为参数。将此信息添加到类中,并将带有类名的船添加到船上)

关系:

classes(class, type, country, numGuns, bore, displacement)
ships(name, class, launched)


mysql> CREATE PROCEDURE addClass(in VARCHAR(50) inClassName, in VARCHAR(5) inType, in
VARCHAR(50) inCountry, in INT inNumGuns, in INT inBore, in INT inDis)
-> begin
-> INSERT INTO classes VALUES(inClassName, inType, inCountry, inNumGuns, inBore, inDis);
-> INSERT INTO ships VALUES(inClassName, inClassName, NULL);
-> end
-> //
ERROR 1064 (42000): 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 'VARCHAR(50)
inClassName, in VARCHAR(50) inType, in VARCHAR(50) inCountry, in INT' at line 1

我不确定这个错误的来源,有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

输入变量名称在它们的数据类型之前,而不是在您指定它们之后:

CREATE PROCEDURE addClass(
  in inClassName VARCHAR(50),
  in inType VARCHAR(5) , 
  in inCountry VARCHAR(50), 
  in inNumGuns INT,
  in inBore INT,
  in inDis INT
)
BEGIN
  INSERT INTO classes VALUES(inClassName, inType, inCountry, inNumGuns, inBore, inDis);
  INSERT INTO ships VALUES(inClassName, inClassName, NULL);
END

From the CREATE PROCEDURE docs,规范看起来像

proc_parameter:
    [ IN | OUT | INOUT ] param_name type

答案 1 :(得分:0)

更正语法。这是一个例子:

delimiter //

CREATE PROCEDURE addClass(in inClassName VARCHAR(50),
in inType VARCHAR(5), in inCountry VARCHAR(50),
in inNumGuns INT, in inBore INT, in inDis INT)

begin

INSERT INTO classes VALUES(inClassName, inType, inCountry, inNumGuns, inBore, inDis);
INSERT INTO ships VALUES(inClassName, inClassName, NULL);

end//

delimiter ;
相关问题