getting syntax error on creating function

后端 未结 1 961
栀梦
栀梦 2021-01-28 19:54

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

CREATE FUNCTION TitleToFileName(title varchar(200)) RETURNS varchar(200)
  BEGIN
    set title = REPLACE(tit         


        
相关标签:
1条回答
  • 2021-01-28 20:34
    • 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 ;
    
    0 讨论(0)
提交回复
热议问题