开发者

create function mysql error

Here is my function

DELIMITER //
CREATE FUNCTION specialUser(user INT) RETURNS user_id INT
BEGIN
    DECLARE user_id INT DEFAULT 0;
    CASE 
     WHEN user = 1556 THEN SET user_id = 1001;
     WHEN user = 1018 THEN SET user_id = 1002;
     WHEN user = 3658 THEN SET user_id = 1003;
         ELSE SET user_id = user;
    END CASE;
 RETURN user_id;
END//

I get error:

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 'us开发者_C百科er_id INT BEGIN DECLARE user_id INT DEFAULT 0; CASE ' at line 1


You can only state the type of the result, there's no use in giving an identifier, so:

CREATE FUNCTION specialUser(user INT) RETURNS INT

instead of

CREATE FUNCTION specialUser(user INT) RETURNS user_id INT
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜