2016-09-29 17 views
2
CREATE FUNCTION .CreateGroup(GroupName VARCHAR(50), GroupIcon TEXT, GroupDescription VARCHAR(130), GroupCreator INT) 
     RETURNS int(11) 
     DETERMINISTIC 
    BEGIN 
     DECLARE groupID INT; 
     INSERT INTO groups (name, icon, description) VALUES (GroupName, GroupIcon, GroupDescription); 
     SET groupID = LAST_INSERT_ID(); 
     INSERT INTO group_members VALUES (groupID, GroupCreator); 
     RETURN groupID; 
    END; 

我得到上述錯誤:#1064 - 您的SQL語法錯誤;修理它?

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 5

如何解決呢?

回答

0

請刪除之前函數名. ...

CREATE FUNCTION .CreateGroup(GroupName VARCHAR(50), GroupIcon TEXT, 
GroupDescription VARCHAR(130), GroupCreator INT) 
1

在創建MySQL存儲程序包含分號(如程序),您需要將語句分隔符更改爲不串出現在CREATE語句中。

作爲示範:

-- change statement delimiter to string that doesn't appear in the statement 

DELIMITER $$ 

-- terminate the statement with the specified delimiter 

CREATE PROCEDURE ... 
BEGIN 
    DECLARE groupID INT; 
    ... 
END$$ 

-- then change the delimiter back to the default semicolon 

DELIMITER ;