0

I'm trying to create a function like the following:

CREATE FUNCTION TitleToFileName(title varchar(200)) RETURNS varchar(200)
  BEGIN
    set title = REPLACE(title,":"," ");
    set title=REPLACE(title,"/"," ");
    set title=REPLACE(title,"_"," ");
    RETURN title;
  END

MySQL shows 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 '' at line 3

I tried using ' instead of " and @title instead of title , but didn't work..

1
  • 2
    Probably a delimiter problem. Add DELIMITER $$ or something similar before the definition. Commented Sep 28, 2018 at 14:30

1 Answer 1

2
  • You need to redefine Delimiter to something else (eg: $$), instead of (;).
  • Also as a safety measure, check if the same name function already exists or not (DROP FUNCTION IF EXISTS)
  • At the end, redefine the DELIMITER to ;

Try :

DELIMITER $$
DROP FUNCTION IF EXISTS `TitleToFileName`$$
CREATE FUNCTION TitleToFileName(title varchar(200)) RETURNS varchar(200)
  BEGIN
    set title = REPLACE(title,":"," ");
    set title=REPLACE(title,"/"," ");
    set title=REPLACE(title,"_"," ");
    RETURN title;
  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.