0

我是 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;
//

我得到的错误是:

ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'BEGIN INSERT INT O COMMENTERS(names, emailAddresses) 值(用户名,Useremail' 附近使用正确的语法

有任何想法吗?

4

1 回答 1

0

您正在对插入语句中反转的列名称和值进行编码。

它应该是

 INSERT INTO COMMENTERS (name, emailAddress) values ('names', 'emailAddresses') ;
于 2012-12-01T01:06:05.457 回答