0

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 ; enter image description here

#   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

KEVINBOSS
  • 149
  • 1
  • 1
  • 11

1 Answers1

2

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.

enter image description here

Harshal_Kalavadiya
  • 312
  • 1
  • 5
  • 15
  • As I have added screenshot, it works perfectly for me. @KEVINBOSS Can you share screenshot, what error are you getting? – Harshal_Kalavadiya Aug 10 '18 at 19:30
  • Hi I have posted the screenshot can you see it? – KEVINBOSS Aug 10 '18 at 19:45
  • @KEVINBOSS Can you execute following statement and try once : SET GLOBAL log_bin_trust_function_creators = 1; for more details you can visit below link : https://stackoverflow.com/questions/26015160/deterministic-no-sql-or-reads-sql-data-in-its-declaration-and-binary-logging-i – Harshal_Kalavadiya Aug 10 '18 at 19:51