Error declaring varchar variable inside MySQL Function

时间:2017-12-18 05:10:40

标签: mysql mysql-variables mysql-function

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.

0 个答案:

没有答案
相关问题