简体   繁体   中英

what does — and -— mean in mysql?

I know -- means starting of comment in mysql. But what does --- and ---- mean?? See my console log.

mysql> --
mysql> ---
    -> 
    -> ;
ERROR 1064 (42000): 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 1
mysql> ----
    -> 
    -> ;
Query OK, 0 rows affected (0.00 sec)
  • First one seems a comment.
  • Second one is NOT
  • Third one is not too. They are expecting something.

I wrote an sql file that contains header comments started with --- characters. Due to this next query does not run. It throws error. Like this.

ERROR 1064 (42000): 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 1

There needs to be whitespace or a control character after the second dash. From the MySQL manual :

MySQL Server supports three comment styles:

  • From a # character to the end of the line.

  • 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). This syntax differs slightly from standard SQL comment syntax, as discussed in Section 1.8.5.5, “ -- as the Start of a Comment”.

  • From a /* sequence to the following */ sequence, as in the C programming language. This syntax enables a comment to extend over multiple lines because the beginning and closing sequences need not be on the same line.

(Emphasis mine.) And, as usual, this only applies to MySQL. :P

This nothing but syntax check error,

Other than '--', mysql considering everything as sql statement. Since
'---' is not a valid statement it's showing error.
that means there should be at least one space after '--' then only it will be considered as valid comment.

Hope this helps you,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM