本文介绍了mysql分隔符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已修改.

DROP FUNCTION IF EXISTS PersonName;
DELIMITER |;

CREATE FUNCTION PersonName( personID SMALLINT )
RETURNS CHAR(20)
BEGIN
  DECLARE pname CHAR(20) DEFAULT '';
  SELECT name INTO pname FROM family WHERE ID=personID;
  RETURN pname;
END;
|
DELIMITER ;

此代码有什么问题?我得到以下错误.

whats wrong with this code? i get following error with it.

错误:标点符号字符串未知@ 102 STR:|; SQL:DROP FUNCTION IF EXISTS PersonName;#MySQL返回了 空结果集(即零行).

ERROR: Unknown Punctuation String @ 102 STR: |; SQL: DROP FUNCTION IF EXISTS PersonName;# MySQL returned an empty result set (i.e. zero rows).

DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |;

DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |;

SQL查询:

DELIMITER |;

DELIMITER |;

MySQL说:文档 #1064-您的SQL语法有误;检查手册 对应于您的MySQL服务器 使用正确语法的版本 "DELIMITER |"附近在第1行

MySQL said: Documentation #1064 - 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 |' at line 1

推荐答案

我将在END之后删除分号.

I would remove the semicolon after END.

    ...
END
|
DELIMITER ;


关于您的评论,在声明新的定界符时不能使用当前的定界符.这听起来令人困惑,但是请考虑是否要这样做:


Re your comment, you can't use the current delimiter when declaring a new delimiter. That sounds confusing, but consider if you do this:

DELIMITER |;

现在,MySQL会认为分隔符为"|;". (两个字符,一个竖线和一个分号).如果考虑到这一点,MySQL客户端必须以特殊的方式对待DELIMITER .这是当前定界符后面不能加上 的唯一声明.

Now MySQL would think the delimiter is "|;" (two characters, a pipe and a semicolon). If you think about it, DELIMITER must be treated in a special way by the MySQL client. It's the only statement that can't be followed by the current delimiter.

因此,当将分隔符设置为管道时,请执行以下操作:

So when setting the delimiter to pipe, do this:

DELIMITER |

将其设置回分号时,请执行以下操作:

When setting it back to semicolon, do this:

DELIMITER ;


FWIW,我在MySQL 5.0.75上的本地测试数据库上运行了以下命令,没有错误:


FWIW, I ran the following with no error on my local test database on MySQL 5.0.75:

DROP FUNCTION IF EXISTS PersonName;
DELIMITER |

CREATE FUNCTION PersonName( personID SMALLINT )
RETURNS CHAR(20)
BEGIN
  DECLARE pname CHAR(20) DEFAULT '';
  SELECT name INTO pname FROM family WHERE ID=personID;
  RETURN pname;
END
|
DELIMITER ;

这篇关于mysql分隔符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 17:06