<bdo id='z84DJ'></bdo><ul id='z84DJ'></ul>
  1. <legend id='z84DJ'><style id='z84DJ'><dir id='z84DJ'><q id='z84DJ'></q></dir></style></legend>
    1. <i id='z84DJ'><tr id='z84DJ'><dt id='z84DJ'><q id='z84DJ'><span id='z84DJ'><b id='z84DJ'><form id='z84DJ'><ins id='z84DJ'></ins><ul id='z84DJ'></ul><sub id='z84DJ'></sub></form><legend id='z84DJ'></legend><bdo id='z84DJ'><pre id='z84DJ'><center id='z84DJ'></center></pre></bdo></b><th id='z84DJ'></th></span></q></dt></tr></i><div id='z84DJ'><tfoot id='z84DJ'></tfoot><dl id='z84DJ'><fieldset id='z84DJ'></fieldset></dl></div>

      <small id='z84DJ'></small><noframes id='z84DJ'>

      <tfoot id='z84DJ'></tfoot>

      如何在 SQL 语句中将变量传递到 XQuery 的 XPath

      时间:2023-06-05
    2. <legend id='XGFzc'><style id='XGFzc'><dir id='XGFzc'><q id='XGFzc'></q></dir></style></legend>

        <small id='XGFzc'></small><noframes id='XGFzc'>

          <tbody id='XGFzc'></tbody>
        <i id='XGFzc'><tr id='XGFzc'><dt id='XGFzc'><q id='XGFzc'><span id='XGFzc'><b id='XGFzc'><form id='XGFzc'><ins id='XGFzc'></ins><ul id='XGFzc'></ul><sub id='XGFzc'></sub></form><legend id='XGFzc'></legend><bdo id='XGFzc'><pre id='XGFzc'><center id='XGFzc'></center></pre></bdo></b><th id='XGFzc'></th></span></q></dt></tr></i><div id='XGFzc'><tfoot id='XGFzc'></tfoot><dl id='XGFzc'><fieldset id='XGFzc'></fieldset></dl></div>

        <tfoot id='XGFzc'></tfoot>
          <bdo id='XGFzc'></bdo><ul id='XGFzc'></ul>

                本文介绍了如何在 SQL 语句中将变量传递到 XQuery 的 XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                场景:我在 MSSQL 数据库中有一个 xml 列,我必须使用 XQuery 解析该单元格的 XML 数据.

                Scenario: I have an xml column in MSSQL database which I have to parse the XML data of that cell using XQuery .

                     Xml content : <AnchoredXml xmlns="urn:schema:Microsoft.Rtc.Management.ScopeFramework.2008" SchemaWriteVersion="2">
                  <Key ScopeClass="Global">
                    <SchemaId Namespace="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" ElementName="Topology" />
                    <AuthorityId Class="Host" InstanceId="00000000-0000-0000-0000-000000000000" />
                  </Key>
                  <Dictionary Count="1">
                    <Item>
                      <Key />
                      <Value Signature="b1ac04f7-d8f0-4300-86cf-fb2b3383536c">
                        <Topology xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008">
                          <InternalDomains AllowAllDomains="false" DefaultDomain="ocsqa.com">
                            <InternalDomain Name="ocsqa.com" Authoritative="false" AllowSubDomains="false" />
                          </InternalDomains>
                          <Sites>
                            <CentralSite SiteId="1">
                              <Name>LyncSite</Name>
                              <Location />
                            </CentralSite>
                          </Sites>
                          <Clusters>
                

                这是该单元格中xml内容的一段数据.

                This is a piece of data of the xml content in that one cell.

                我使用下面的查询来遍历上面xml的节点:

                I am using below query to traverse the nodes of above xml:

                select @cluster = @Items.query('/DocItemSet/DocItem/Data/*[@SchemaWriteVersion="2"]/*[2]/*[1]/*[2]/*[1]/*[3]') 
                

                上述查询的输出是:

                    <p1:Cluster xmlns:p1="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" RequiresReplication="true" RequiresSetup="true" Fqdn="XXXX.ocsqa.com">
                  <p1:ClusterId SiteId="1" Number="1" />
                  <p1:Machine OrdinalInCluster="1" Fqdn=" XXXX.ocsqa.com">
                    <p1:NetInterface InterfaceSide="Primary" InterfaceNumber="1" IPAddress="0.0.0.0" />
                    <p1:NetInterface InterfaceSide="External" InterfaceNumber="1" IPAddress="0.0.0.0" />
                    <p1:NetInterface InterfaceSide="Pstn" InterfaceNumber="1" IPAddress="0.0.0.0" />
                  </p1:Machine>
                </p1:Cluster>
                <p2:Cluster xmlns:p2="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" RequiresReplication="true" RequiresSetup="true" Fqdn=" XXXX2.ocsqa.com">
                  <p2:ClusterId SiteId="1" Number="2" />
                  <p2:Machine OrdinalInCluster="1" Fqdn=" XXXX2.ocsqa.com">
                    <p2:NetInterface InterfaceSide="Primary" InterfaceNumber="1" IPAddress="0.0.0.0" />
                    <p2:NetInterface InterfaceSide="External" InterfaceNumber="1" IPAddress="0.0.0.0" />
                    <p2:NetInterface InterfaceSide="Pstn" InterfaceNumber="1" IPAddress="0.0.0.0" />
                  </p2:Machine>
                </p2:Cluster>
                <p3:Cluster xmlns:p3="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" RequiresReplication="true" RequiresSetup="true" Fqdn=" XXXX2.ocsqa.com">
                  <p3:ClusterId SiteId="1" Number="3" />
                  <p3:Machine OrdinalInCluster="1" Fqdn=" XXXX2.ocsqa.com" />
                </p3:Cluster>
                

                现在使用下面提到的查询:

                Now using query mentioned as below :

                select @fqdn = @cluster.value('(./*/*/@Fqdn)[1]','nvarchar(20)') Select @fqdn
                

                注意上面查询中突出显示的索引号.使用这个查询,我们将能够获得第一个可用的 xml 集群,同样我也想寻找其他集群.

                Note the highlighted index no in above query. Using this query we will be able to achieve the first Cluster available in xml, similarly I wanted to look for other Clusters as well.

                所以我想在 while 循环中使用这个查询.为此,我必须传递一个变量而不是硬编码的 int 值.类似于以下内容:

                So I wanted to use this query in while loop. For which I have to pass a variable instead of hardcoded int value. Something similar as below :

                select @fqdn = @cluster.value('(./*/*/@Fqdn)[sql:variable("@test")]','nvarchar(20)')
                

                我参考了一些帖子如何将 XPath 与 Oracle XMLTable 中的变量一起使用?http://www.jasonstrate.com/2011/01/xquery-for-the-non-expert-variable-use/

                但我收到如下错误:

                消息 2389,级别 16,状态 1,第 35 行XQuery [value()]: 'value()' 需要一个单例(或空序列),找到类型为 'xdt:untypedAtomic *' 的操作数如何将变量传递到 SQL 语句的 XQuery 中?

                Msg 2389, Level 16, State 1, Line 35 XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *' How to pass a variable into a XQuery of SQL statement?

                推荐答案

                你需要告诉 SQL Server 你只对单个节点感兴趣.在末尾添加 [1].

                You need to tell SQL Server that you are only interested in the a single node. Add a [1] at the end.

                @cluster.value('(./*/*/@Fqdn)[sql:variable("@test")][1]','nvarchar(20)')
                

                这篇关于如何在 SQL 语句中将变量传递到 XQuery 的 XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 XQuery 获取这些数据 下一篇:将具有相同标记的 XML 值分成不同的行 SQL Server

                相关文章

                最新文章

                <legend id='tRrTY'><style id='tRrTY'><dir id='tRrTY'><q id='tRrTY'></q></dir></style></legend>
                <tfoot id='tRrTY'></tfoot>

                  • <bdo id='tRrTY'></bdo><ul id='tRrTY'></ul>

                    <i id='tRrTY'><tr id='tRrTY'><dt id='tRrTY'><q id='tRrTY'><span id='tRrTY'><b id='tRrTY'><form id='tRrTY'><ins id='tRrTY'></ins><ul id='tRrTY'></ul><sub id='tRrTY'></sub></form><legend id='tRrTY'></legend><bdo id='tRrTY'><pre id='tRrTY'><center id='tRrTY'></center></pre></bdo></b><th id='tRrTY'></th></span></q></dt></tr></i><div id='tRrTY'><tfoot id='tRrTY'></tfoot><dl id='tRrTY'><fieldset id='tRrTY'></fieldset></dl></div>

                    <small id='tRrTY'></small><noframes id='tRrTY'>