SQL 中是否存在与供应商无关的多行注释分隔符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/728172/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:38:44  来源:igfitidea点击:

Are there multiline comment delimiters in SQL that are vendor agnostic?

sqlcomments

提问by ojblass

While editing, building up, or cherry picking from SQL statements I can find myself interacting with one of four popular database tools. I have been resorting to single line commenting for DB2 and Informix. I have created macros in vim to make this slightly more efficient but I was wondering if I am working too hard.

在编辑、构建或从 SQL 语句中挑选时,我发现自己与四种流行的数据库工具之一进行交互。我一直对 DB2 和 Informix 使用单行注释。我在 vim 中创建了宏以使其效率更高,但我想知道我是否工作太努力了。

回答by Jonathan Leffler

C style comments are standard in SQL 2003 and SQL 2008 (but not in SQL 1999 or before). The following DBMS all support C style comments:

C 样式注释在 SQL 2003 和 SQL 2008 中是标准的(但不是在 SQL 1999 或之前)。以下 DBMS 都支持 C 风格的注释:

  • Informix
  • PostgreSQL
  • MySQL
  • Oracle
  • DB2
  • Sybase
  • Ingres
  • Microsoft SQL Server
  • SQLite (3.7.2 and later)
  • Teradata and Aster
  • Informix
  • PostgreSQL
  • MySQL
  • 甲骨文
  • 数据库2
  • 赛贝斯
  • 安格尔
  • 微软 SQL 服务器
  • SQLite(3.7.2 及更高版本)
  • Teradata 和 Aster

That is not every possible DBMS, but it is more or less every major SQL DBMS. (I'll willingly add notes about any other DBMS that does - or does not - support C style comments.)

这不是所有可能的 DBMS,但它或多或少是每个主要的 SQL DBMS。(我很乐意添加有关支持或不支持 C 样式注释的任何其他 DBMS 的注释。)

The SQL 2003 standard documents comment notations thus:

SQL 2003 标准文档注释符号如下:

<comment> ::= <simple comment> | <bracketed comment>

<simple comment> ::=
    <simple comment introducer> [ <comment character> ... ] <newline>

<simple comment introducer> ::=
    <minus sign> <minus sign> [ <minus sign> ... ]

<bracketed comment> ::=
    <bracketed comment introducer> <bracketed comment contents>
    <bracketed comment terminator>

<bracketed comment introducer> ::= <slash> <asterisk>

<bracketed comment terminator> ::= <asterisk> <slash>

<bracketed comment contents> ::= [ { <comment character> | <separator> }... ]

<comment character> ::= <nonquote character> | <quote>

IBM Informix Dynamic Server (IDS or Informix) supports C style comments. It also supports '{ ... }' as potentially multi-line comments, except in contexts where it means something else - that something else being a LIST or SET or MULTISET literal. (You might find that DB-Access gets confused by C style comments; that is a separate issue.)

IBM Informix Dynamic Server(IDS 或 Informix)支持 C 风格的注释。它还支持 ' { ... }' 作为潜在的多行注释,除非在它意味着其他内容的上下文中 - 其他内容是 LIST 或 SET 或 MULTISET 文字。(您可能会发现 DB-Access 被 C 风格的注释弄糊涂了;这是一个单独的问题。)

回答by Ben Hoffstein

The ISO standard only defines single-line comments beginning with two dashes. Some vendors support C-style commenting (i.e. multiline beginning with /* and ending with */), but it should not be considered "vendor agnostic".

ISO 标准只定义了以两个破折号开头的单行注释。一些供应商支持 C 风格的注释(即多行以 /* 开头并以 */ 结尾),但不应将其视为“供应商不可知”。