0

I am attempting to create a MySQL variable inside a stored function similar to this:

CREATE DEFINER = CURRENT_USER
FUNCTION t_func(cc char(2), lc char(2), os varchar(1000))
    RETURNS varchar(1000)
    DETERMINISTIC
    READS SQL DATA
BEGIN

    DECLARE mytext VARCHAR(1000);
    SET mytext = NULL;

    -- Other stuff follows...

    RETURN mytext;

END;;

But I get this error complaining about the DECLARE line:

[Err] 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 '' at line 8

How do you declare a variable inside a MySQL function? According to the MySQL documentation on DECLARE syntax, I am following all of the placement rules.

Adam
  • 4,590
  • 10
  • 51
  • 84
  • I know this is probably going to be something stupid simple and overlooked. Any help is much appreciated. – Adam Dec 18 '17 at 05:11
  • 1
    `the right syntax to use near '' at line 8` ...when the error is reported to be near *empty string*, this means the parser is at the end of the input buffer... which means you didn't use a `DELIMITER` statement to change the statement delimiter from `;` to something else -- `;;` is probably what you were planning, based on `END;;` so the client is only sending up through line 8. – Michael - sqlbot Dec 18 '17 at 07:23
  • Thank you! New is was something simple. If you make it into an answer I will gladly accept it. – Adam Dec 19 '17 at 01:48
  • Thank you for offering me the option of posting an answer, but I think this is one we can close as a problem that can no longer be reproduced or simple typographical error. – Michael - sqlbot Dec 19 '17 at 11:16

0 Answers0