sql-server - 某些 SSMS 版本中显示 SQL Server 错误 493
问题描述
我在 2016 年的 17.7 版(SP2)IntelliSense
中收到一条红色波浪线用于以下查询。经过一番研究,原来是错误 493 和严重性 16。查询中的错误是由 where 子句引起的。SSMS
Microsoft SQL Server
询问
SELECT
ClientID,
Person.query('..') AS Person
FROM ClientInfo CROSS APPLY
Info_untyped.nodes('/People/Person') AS People(Person)
where
Person.exist(
'/People/Person[@id=5678]') = 1
错误 493
从 nodes() 方法返回的列 'Person' 不能直接使用。它只能用于四种 XML 数据类型方法之一,exist()、nodes()、query() 和 value(),或者用于 IS NULL 和 IS NOT NULL 检查。
SSMS
版本 18 和2016 (SP1) 中的相同查询Microsoft SQL Server
没有问题。
知道为什么吗?如何解决它。
谢谢
CREATE XML SCHEMA COLLECTION ClientInfoCollection AS
'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:ClientInfoNamespace"
targetNamespace="urn:ClientInfoNamespace"
elementFormDefault="qualified">
<xsd:element name="People">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Person" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FirstName" type="xsd:string" minOccurs="1" maxOccurs="1" />
<xsd:element name="LastName" type="xsd:string" minOccurs="1" maxOccurs="1" />
<xsd:element name="FavoriteBook" type="xsd:string" minOccurs="0" maxOccurs="5" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:integer" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>'
GO
CREATE TABLE ClientInfo
(
ClientID INT PRIMARY KEY IDENTITY,
Info_untyped XML,
Info_typed XML(ClientInfoCollection)
);
INSERT INTO ClientInfo (Info_untyped, Info_typed)
VALUES
(
'<?xml version="1.0" encoding="UTF-8"?>
<People>
<Person id="1234">
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Person>
<Person id="5678">
<FirstName>Jane</FirstName>
<LastName>Doe</LastName>
</Person>
</People>',
'<?xml version="1.0" encoding="UTF-8"?>
<People xmlns="urn:ClientInfoNamespace">
<Person id="1234">
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Person>
<Person id="5678">
<FirstName>Jane</FirstName>
<LastName>Doe</LastName>
</Person>
</People>'
)
INSERT INTO ClientInfo (Info_untyped)
VALUES
(
'<?xml version="1.0" encoding="UTF-8"?>
<People>
<Person id="4321">
<FirstName>Jack</FirstName>
<LastName>Smith</LastName>
</Person>
<Person id="8765">
<FirstName>Jill</FirstName>
<LastName>Smith</LastName>
</Person>
</People>'
)
解决方案
推荐阅读
- encryption - 不同密钥为明文提供相同密文的可能性
- react-native - React 原生响应式侧边菜单
- c - UNIX域数据报套接字的核心同步问题
- spring-boot - 如何找出缓存管理器中是否存在密钥(org.springframework.cache.CacheManager)
- r - 计算多列中的值
- php - 在 Laravel 控制器的嵌套 foreach 循环中构建数组
- pcap - 如何将原始数据包数据转换为 PCAP 文件?
- javascript - V8:为什么我的函数不适用于 JavaScript 代码?
- php - Json返回[object object]而不是值
- spring-boot - 有没有办法为 Rest Template 提供动态超时?