gpt4 book ai didi

sql - SQL Server 中的 XML 查询

转载 作者:数据小太阳 更新时间:2023-10-29 01:53:39 24 4
gpt4 key购买 nike

我刚开始在 SQL Server 数据库中查询 XML。我在处理最基本的查询时遇到问题。这是一个简化的例子。我如何返回描述?下面的 SELECT 语句是我正在使用的,但它没有返回任何内容。

SELECT Incidents.IncidentXML.query
('data(/dsIncident/IncidentInformation/Description)') AS Description
FROM Incidents

这是我正在使用的 XML 文件的片段:

<dsIncident xmlns="http://tempuri.org/dsIncident.xsd">
<IncidentInformation>
<Description>This is the description.</Description>
<Country>Singapore</Country>
</IncidentInformation>
</dsIncident>

最佳答案

好吧,您错过了 XML 命名空间! :-)

试试这个:

SELECT 
Incidents.IncidentXML.query('declare namespace x="http://tempuri.org/dsIncident.xsd";
(/x:dsIncident/x:IncidentInformation/x:Description)') AS Description
FROM Incidents

神奇的是

declare namespace x="http://tempuri.org/dsIncident.xsd"

这里的部分 - 它声明了一个 namespace (带有您选择的前缀 - 可以是任何东西 - 这里是“x”)用于查询该 XML 数据的时间段。

希望这会有所返回! ;-)

马克

关于sql - SQL Server 中的 XML 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1302029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com