MySQL is not supporting single line comments here. What would be the reason?

删除回忆录丶 提交于 2019-12-01 15:34:49

问题


Here is what I am getting when I use single line comment (using --):

ERROR 1064 (42000): You have an error in your SQL syntax

Actually I am using these comments in a procedure to show what exactly a line does. Then I checked directly at the MySQL command line, but I got this error:

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 a file to support this? It is working fine if I use multi-line comments (using /* Something */).

I googled and went through MySQL documentation. In that it has shown me it supports ( -- ). What could be the error?


回答1:


From MySQL documentation:

From a “-- ” sequence to the end of the line. In MySQL, the “-- ” (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on).

You need some space character after --, for example:

mysql> select 1;-- test select



回答2:


Your syntax is wrong - read about comment syntax.

Just add a space after --:

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


来源:https://stackoverflow.com/questions/14435989/mysql-is-not-supporting-single-line-comments-here-what-would-be-the-reason

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!