1

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 'user_id INT BEGIN DECLARE user_id INT DEFAULT 0; CASE ' at line 1

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.