简体   繁体   中英

Mysql workbench creating a function

this is my code, pretty simple, I always get errors i dont know where I went wrong, please help:

create function fun1() returns int(1) begin

return 1;

end ; 在此处输入图片说明

#   Time    Action  Message Duration / Fetch

0 1 11:20:30 end Error Code: 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 'end' at line 1 0.000 sec

Hi Can you please try below code with changing the delimiter:

    delimiter $$
    create function fun1() returns int(1) 

    begin

    return 1;

    end$$

    delimiter ;

Hope it will work for you.

MySql use ; as default delimiter so delimiters other than the default ; are typically used when defining functions, stored procedures, and triggers wherein you must define multiple statements. You define a different delimiter like $$ which is used to define the end of the entire procedure, but inside it, individual statements are each terminated by ; . That way, when the code is run in the mysql client, the client can tell where the entire procedure ends and execute it as a unit rather than executing the individual statements inside.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM