我是sql的新手,我的大部分培训都是在MSSQL中,但是我正在MYSQL中学习。我有一个存储过程给我一个问题。我将分隔符设置为//.
CREATE PROCEDURE AddComment
(
name varchar(50),
emailAddress varchar(50),
Comments text
)
BEGIN
DECLARE ComName varchar(50);
DECLARE ComID int;
SELECT name into ComName;
SELECT ID into ComID from Commenters WHERE names = ComName;
if ComID = NULL
BEGIN
INSERT INTO COMMENTERS ('names', 'emailAddresses') values (name, emailAddress);
SELECT ID into ComID from Commenters WHERE names = ComName;
END
INSERT INTO COMMENTS ('commentersID', 'Comments') values (ComID, Comments);
END;
//
这就是我现在所拥有的:
CREATE PROCEDURE AddComment
(
Username varchar(50),
UseremailAddress varchar(50),
UserComment text
)
BEGIN
DECLARE ComName varchar(50);
DECLARE ComID int;
SELECT Username into ComName;
SELECT ID into ComID from Commenters WHERE names = ComName;
if ComID = NULL
BEGIN
INSERT INTO COMMENTERS(names,emailAddresses) values (Username, UseremailAddress);
SELECT ID into ComID from Commenters WHERE names = ComName;
END
INSERT INTO COMMENTS(commentersID, Comments) values (ComID, UserComment);
END;
//
我得到的错误是:
错误1064(42000):您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'BEGIN INSERT INT附近使用正确的语法 O COMMENTERS(姓名,电子邮件地址)值(用户名,第1行的Useremail'
任何想法?
答案 0 :(得分:0)
您正在编写插入语句中反转的列名和值。
应该是
INSERT INTO COMMENTERS (name, emailAddress) values ('names', 'emailAddresses') ;