0

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 server 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/*//*/
2
  • The error message doesn't match the provided SQL code. Commented Jun 28, 2011 at 10:31
  • Do you reckon this has anything to do with it? bugs.mysql.com/bug.php?id=46429 Commented Jun 28, 2011 at 11:46

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

2 Comments

I have changed code to this: 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; RETURN temp_val; END // DELIMITER ; But now it throws same error Mysql::Error: 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 'DELIMITER // DROP FUNCTION IF EXISTS clean_dymmy_table // CREATE FUNCTION c' at line 1
What happens if you literally copy and paste the above into something which will evaluate a script? (In MySQL browser this will be under scripts, it won't be a regular query)
0

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?

2 Comments

Better way is not to upgrade. Do you have any suggestion, how can I refactor SQL code to get rid of DELIMITER statement in the code?
I've never worked with SQL procedures, unfortunately. But if I understand the bug correctly, you should be able to use DELIMITER by calling the code from the mysql client. Check out the comment by Valeriy Kravchuk in that link.

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.