2013-01-21 90 views
6

这是我在使用单行注释时使用的内容(使用-)。错误1064(42000):您的SQL语法有错误;实际上,我在一个程序中使用这些注释来显示一条线的功能。然后我直接在mysql命令行中检查,但是我得到了这个错误。Mysql在这里不支持单行注释。这是什么原因?

mysql> select 1;--test select 
+---+ 
| 1 | 
+---+ 
| 1 | 
+---+ 
1 row in set (0.00 sec) 

    -> ; 
check the manual that corresponds to your MySQL server version for the right syntax to use near '--test select' at line 1 
Do I need to configure any file to support this. It is working fine, If I use Multi-line comments(Using /*something*/). 

我用Google搜索,并通过MySQL文档去的,因为它表明我,它supoppots(-)。 什么可能是错误?

回答

11

从MySQL文档:

从一个“ - ”序列到行的结尾。在MySQL中,“ - ”(双短划线)注释样式要求第二个破折号至少包含一个空格或控制字符(例如空格,制表符, 换行符等) 。

所以,你需要一些空格字符--之后,例如:

mysql> select 1;-- test select 
4

你的语法是错误的 - 了解Comment Syntax

刚过增加空间 -

mysql> select 1; -- test select 
+---+ 
| 1 | 
+---+ 
| 1 | 
+---+ 
1 row in set (0.00 sec)