3

我正在查看 SQL 的语法,特别是字符串文字

<character string literal> ::=
    [ <introducer> <character set specification> ]
    <quote> [ <character representation> ... ] <quote>
    [ { <separator> <quote> [ <character representation> ... ] <quote> }... ]

忽略[ <introducer> <character set specification> ]部分,这是否意味着一个或多个<quote> [ <character representation> ... ] <quote>s 由 a 分隔<separator>

如果是这样,这是否意味着'hello' 'world'应该将其解析为 one <character string literal>

对于查询SELECT 'hello' 'world',Microsoft SQL Server 2005 返回:

+-------+
| world |
+-------+
| hello |
+-------+

MySQL 5.0 返回:

+------------+
| hello      |
+------------+
| helloworld |
+------------+

我知道每种 SQL 风格都是不同的,而且它们并不都遵循标准。我只是想确定我是否正确解释了 BNF。谢谢。

4

3 回答 3

2

如果是这样,这是否意味着 'hello' 'world' 应该被解析为一个?

根据 ANSI SQL,是的。

于 2010-10-26T22:38:07.453 回答
0

为了澄清 SQL Server 中发生的事情,您实际上正在做的是返回列名为“world”的“hello”。您的示例与以下内容相同:

SELECT 'hello' AS 'world'

如果你试图进一步扩展你的想法,你会得到一个错误:

SELECT 'hello' 'world' 'now'

Line 1: Incorrect syntax near 'now'.
于 2010-10-26T19:09:21.253 回答
0

查看 BNF 的<separator> ::=.

于 2010-10-26T19:13:11.773 回答