0

I'm trying to define a function in mysql (mysql-server version 8.0) like this:

CREATE FUNCTION myVeryCoolFunc ( json1 JSON, json2 JSON )
RETURNS JSON
DETERMINISTIC
BEGIN

   DECLARE abc JSON;
   DECLARE foo INT;
   DECLARE bar INT;
...

but it fails with the message

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 6

In other words: Somehow "declare abc JSON;" contains a syntax error. I just can't figure out why.

Additionally, I only get this when I try to use the mysql console or the mysql command with "--execute=...", not when I use my IDE (PyCharm).

Any help with this is greatly appreciated as I'm really losing my mind over this.

1 Answer 1

1

Found the solution.

You have to change the delimiter before defining a function with ";" in it:

e.g.

DELIMITER //

CREATE FUNCTION myfunc (...)
...
END; //

DELIMITER ;
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.