在创建函数时出现语法错误 [英] getting syntax error on creating function

查看:106
本文介绍了在创建函数时出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建如下函数:

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显示错误:

MySQL shows error :

您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 在第3行的"附近

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

我尝试使用'代替和@title代替title,但是没有用..

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

推荐答案

  • 您需要将Delimiter重新定义为其他名称(例如:$$),而不是(;).
  • 作为安全措施,请检查是否已经存在相同名称的功能(DROP FUNCTION IF EXISTS)
  • 最后,将DELIMITER重新定义为;
    • 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 ;
    • 尝试:

      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 ;
      

      这篇关于在创建函数时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆