SQL XML 成员是否区分大小写?
Case sensitivity in SQL XML member?
我正在处理存储过程,我遇到了一个小部分,其中成员名称 value
似乎区分大小写:
SELECT @Property1 = CONVERT(INT, C.value('(*:NodeName)[1]','INT'))
FROM @XML.nodes('/*') AS T(C)
当我将 value
更新为 Value
时,出现以下错误:
"Value" is not a valid function, property, or field.
如果我将 @XML.nodes
更改为 @XML.Nodes
,也会出现同样的错误。
为什么会出现这个错误?
我认为这是因为对象的定义方式,但我认为 SQL 不区分大小写。
XQUERY 区分大小写。 xml
对象没有 Value
函数,它是 value
,就像没有 Nodes
或 NODES
函数,它是 nodes
.
documentation 也证实了这一点:
XQuery Language Reference (SQL Server)
Transact-SQL supports a subset of the XQuery language that is used for querying the xml data type. This XQuery implementation is aligned with the July 2004 Working Draft of XQuery. The language is under development by the World Wide Web Consortium (W3C), with the participation of all major database vendors and also Microsoft. Because the W3C specifications may undergo future revisions before becoming a W3C recommendation, this implementation may be different from the final recommendation. This topic outlines the semantics and syntax of the subset of XQuery that is supported in SQL Server.
For more information, see the W3C XQuery 1.0 Language Specification.
上面的语言规范继续说明:
2 Basics
...
Like XML, XQuery is a case-sensitive language. Keywords in XQuery use lower-case characters and are not reserved—that is, names in XQuery expressions are allowed to be the same as language keywords—except for the list of reserved function-names in A.3 Reserved Function Names.
在最后一段强调我的。
我正在处理存储过程,我遇到了一个小部分,其中成员名称 value
似乎区分大小写:
SELECT @Property1 = CONVERT(INT, C.value('(*:NodeName)[1]','INT'))
FROM @XML.nodes('/*') AS T(C)
当我将 value
更新为 Value
时,出现以下错误:
"Value" is not a valid function, property, or field.
如果我将 @XML.nodes
更改为 @XML.Nodes
,也会出现同样的错误。
为什么会出现这个错误?
我认为这是因为对象的定义方式,但我认为 SQL 不区分大小写。
XQUERY 区分大小写。 xml
对象没有 Value
函数,它是 value
,就像没有 Nodes
或 NODES
函数,它是 nodes
.
documentation 也证实了这一点:
XQuery Language Reference (SQL Server)
Transact-SQL supports a subset of the XQuery language that is used for querying the xml data type. This XQuery implementation is aligned with the July 2004 Working Draft of XQuery. The language is under development by the World Wide Web Consortium (W3C), with the participation of all major database vendors and also Microsoft. Because the W3C specifications may undergo future revisions before becoming a W3C recommendation, this implementation may be different from the final recommendation. This topic outlines the semantics and syntax of the subset of XQuery that is supported in SQL Server.
For more information, see the W3C XQuery 1.0 Language Specification.
上面的语言规范继续说明:
2 Basics
...
Like XML, XQuery is a case-sensitive language. Keywords in XQuery use lower-case characters and are not reserved—that is, names in XQuery expressions are allowed to be the same as language keywords—except for the list of reserved function-names in A.3 Reserved Function Names.
在最后一段强调我的。