解释 SQL 的 BNF
我正在研究 SQL 的语法,特别是 字符串文字。
<character string literal> ::=
[ <introducer> <character set specification> ]
<quote> [ <character representation> ... ] <quote>
[ { <separator> <quote> [ <character representation> ... ] <quote> }... ]
忽略 [
部分,这是否意味着一个或多个
由 ? [ <字符表示> ...]
分隔?
如果是这样,是否意味着 'hello' 'world'
应该被解析为一个
?
对于查询 SELECT 'hello' 'world',Microsoft SQL Server 2005 返回:
+-------+
| world |
+-------+
| hello |
+-------+
而 MySQL 5.0 返回:
+------------+
| hello |
+------------+
| helloworld |
+------------+
我知道每种 SQL 风格都是不同的,并且它们并不都遵循标准。我只是想确定我是否正确解释了 BNF。谢谢。
I'm looking at the syntax of SQL, specifically the character string literal.
<character string literal> ::=
[ <introducer> <character set specification> ]
<quote> [ <character representation> ... ] <quote>
[ { <separator> <quote> [ <character representation> ... ] <quote> }... ]
Ignoring the [ <introducer> <character set specification> ]
part, does this mean one or more <quote> [ <character representation> ... ] <quote>
s separated by a <separator>
?
If so, does that mean that 'hello' 'world'
should be parsed as one <character string literal>
?
For the query SELECT 'hello' 'world'
, Microsoft SQL Server 2005 returns:
+-------+
| world |
+-------+
| hello |
+-------+
and MySQL 5.0 returns:
+------------+
| hello |
+------------+
| helloworld |
+------------+
I understand that every flavor of SQL is different, and that they don't all follow the standard. I'm just trying to determine whether I'm interpreting the BNF correctly. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 ANSI SQL,是的。
According to ANSI SQL, yes.
为了澄清 SQL Server 中发生的情况,您实际上要做的是返回列名为“world”的“hello”。你的例子是一样的:
如果你试图进一步扩展你的想法,你会得到一个错误:
To clarify what is happening in SQL Server, what you're actually doing is returning 'hello' with a column name of 'world'. Your example is the same as:
If you tried to extend your thought further, you'd get an error:
查看的 BNF ::=。
Look at the BNF for
<separator> ::=
.