mysql 分隔符错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1267172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql delimiter error
提问by Basit
Modifed.
修改。
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.
这段代码有什么问题?我收到以下错误。
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
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 |;
SQL query:
DELIMITER |;
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
您的 SQL 查询中似乎有错误。下面的MySQL服务器错误输出,如果有的话,也可以帮助你诊断问题
错误:未知标点字符串@ 102 STR:|;SQL: DROP FUNCTION IF EXISTS PersonName;# MySQL 返回一个空的结果集(即零行)。
分隔符 |; 分隔符 |; 分隔符 |; 分隔符 |; 分隔符 |; 分隔符 |; 分隔符 |;
SQL查询:
分隔符 |;
MySQL 说:文档 #1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在“DELIMITER |”附近使用的正确语法 在第 1 行
回答by Bill Karwin
I would remove the semicolon after END
.
我会在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 |;
Now MySQL would think the delimiter is "|;" (two characters, a pipe and a semicolon). If you think about it, DELIMITER
mustbe treated in a special way by the MySQL client. It's the only statement that can'tbe followed by the current delimiter.
现在 MySQL 会认为分隔符是“|;” (两个字符,一个管道和一个分号)。仔细想想,DELIMITER
肯定是被MySQL客户端特殊对待了。它是唯一不能跟在当前分隔符后面的语句。
So when setting the delimiter to pipe, do this:
因此,当将分隔符设置为管道时,请执行以下操作:
DELIMITER |
When setting it back to semicolon, do this:
将其设置回分号时,请执行以下操作:
DELIMITER ;
FWIW, I ran the following with no error on my local test database on MySQL 5.0.75:
FWIW,我在 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 ;
回答by Babak
Try this:
尝试这个:
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 ; /* <-- add a space between DELIMITER and the semicolon */
回答by chh
Try this if you are using phpMyAdmin:
如果您使用的是 phpMyAdmin,请尝试此操作:
http://dotnetfish.blogspot.com/2009/07/1064-you-have-error-in-your-sql-syntax.html
http://dotnetfish.blogspot.com/2009/07/1064-you-have-error-in-your-sql-syntax.html
回答by Chad
I was have problems with the delimiter. I was using Navicat, then I rolled over to MySql workbench and the problem is solved. Workbench inserts the delimiter into code...
我对分隔符有问题。我使用的是 Navicat,然后我转到了 MySql 工作台,问题就解决了。Workbench 将分隔符插入到代码中...
回答by gnr
Best solution is, which I tried after getting the above error. The code should be like
最好的解决方案是,我在收到上述错误后尝试过。代码应该像
Delimiter //
Create function or procedure
Write your function or procedure here...
End (without semicolon)
//
Delimiter ; (semicolon with space)
回答by mikej
In your last line where you're restoring the delimiter to semicolon you need a space between DELIMITER
and ;
i.e.
在您将分隔符恢复为分号的最后一行中,您需要在DELIMITER
和之间留一个空格,;
即
DELIMITER ;
回答by user2586714
You have to add delimiter $$
in the beginning and in the last of the mysql script you should to end by the delimiter
你必须delimiter $$
在 mysql 脚本的开头和最后添加你应该以delimiter
回答by techdude
I'm going to throw this in the mix because it may help other people with this issue.
我将把它放在一起,因为它可能会帮助其他人解决这个问题。
If you are using phpMyAdmin, below the SQL entry box there is a delimiter box where you can type the delimiter to use for the query. You can put the outside delimiter here if you want to and then you don't need the delimiter directives.
如果您使用的是 phpMyAdmin,则 SQL 输入框下方有一个分隔符框,您可以在其中键入用于查询的分隔符。如果需要,您可以将外部定界符放在这里,然后您就不需要定界符指令了。
For example, if you put the delimiter $$ inside the box you could use the following format for your query.
例如,如果您将分隔符 $$ 放在框中,您可以使用以下格式进行查询。
CREATE FUNCTION
blah blah...
END
$$
Some people may find this easier.
有些人可能会觉得这更容易。