user3314502
user3314502

Reputation: 21

Mysql 5.6 Function error statement

I try to write mysql function. I have mysql 5.6, and I don`t know why every time i try do it:

 CREATE FUNCTION do_it (s INT) RETURNS INT 
    BEGIN
    DECLARE k INT;
    SET k= s + 2;
    RETURN k;
    END;

I get:

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 1 */

I know it is basic mistake, but I don`t know how I can fix it...

Upvotes: 0

Views: 88

Answers (1)

user1864610
user1864610

Reputation:

You need to change the delimiter that MySQL is using or it will stop processing the CREATE request after the first semi-colon.

Do this:

DELIMITER $$
 CREATE FUNCTION do_it (s INT) RETURNS INT 
    BEGIN
    DECLARE k INT;
    SET k= s + 2;
    RETURN k;
    END$$
DELIMITER ;

Upvotes: 1

Related Questions