开发者

MySQL 5.1.39 SQL syntax error

I have made an upgrade for my MySQL Server to 5.1.39 and now when I run SQL scripts (which had worked previously) - it throws error. I have checked syntax many times and I couldn't find any incompatible code parts. Please suggest any solution for this problem.

Error message

Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL serv开发者_JAVA技巧er version for the right syntax to use near 'CREATE FUNCTION clean_dymmy_table (dummy_name VARCHAR(255)) RETURNS V' at line 3:

SQL code:

 /*DELIMITER //*/
 DROP FUNCTION IF EXISTS clean_dymmy_table;
 CREATE FUNCTION clean_dymmy_table (dummy_name VARCHAR(255)) RETURNS VARCHAR(255)
 DETERMINISTIC
 BEGIN
    DECLARE temp_val VARCHAR(255);
    SET temp_val = dummy_name;

    -- Test
    SET temp_val = REPLACE(temp_val, 'Tmp ', '');
    SET temp_val = REPLACE(temp_val, ' TmP', '');
    SET temp_val = REPLACE(temp_val, 'TMP ', '');
    SET temp_val = REPLACE(temp_val, ' TMP', '');
    SET temp_val = REPLACE(temp_val, ' tmp', '');

    RETURN dummy_name;
 END/*//*/


Not sure why you removed the DELIMITER part, but when I add that back in, it runs fine:

DELIMITER // -- you have to change what MySQL expects between commands
DROP FUNCTION IF EXISTS clean_dymmy_table // -- tell it a new command's coming
CREATE FUNCTION clean_dymmy_table (dummy_name VARCHAR(255)) 
                                   RETURNS VARCHAR(255)
DETERMINISTIC
BEGIN
    -- now this can be parsed as part of the current command.
    DECLARE temp_val VARCHAR(255); 
    SET temp_val = dummy_name;

    -- Test
    RETURN dummy_name;
END
// -- Now you're done with that command.
-- go back to semi-colons, because otherwise life is too zany for me.
DELIMITER ; 

(This was in 5.1.54... but I don't think that should matter)


A hunch: There seems to be a MySQL Bug in the 5.1.x line pertaining to DELIMITER that may be biting you here:

  • #46429 use DELIMITER command in MySql.Data.MySqlClient.MySqlScript

Though that heavily depends on how you're calling it, given cwallenpoole's response, your symptom does suggest it may well be that bug, given your MySQL version. Is upgrading a possibility for you?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜