xquery_在SQL Server中使用XQuery筛选XML列

本文介绍了如何在SQL Server中使用XQuery查询和提取XML数据。通过示例,展示了如何从XML节点获取值,应用过滤器,处理名称空间,以及使用EXIST和CONTAINS等功能来筛选XML列中的信息。
摘要由CSDN通过智能技术生成

xquery

XQuery in the SQL Server helps to query and extract data from XML documents. XQuery gives different approaches to get information from the XML document and the equivalent can be used on applying a data filter or where clause on XML elements as well.

SQL Server中的XQuery有助于查询和提取XML文档中的数据。 XQuery提供了不同的方法来从XML文档中获取信息,并且等效方法也可以用于在XML元素上应用数据过滤器或where子句。

SQL Server provides the XQuery feature to querying XML data type or querying with the XML column with the XPATH. Using XQuery, users can Insert, Update and Delete with the XML nodes and node values in an XML column. SQL Server 2005 or later editions, allows using XML data typed input parameter in the stored procedure and supports using different XML functions to extract the information from XML nodes and vice versa with getting attributed in the XML data type column as well.

SQL Server提供XQuery功能来查询XML数据类型或使用带有XPATH的XML列进行查询。 使用XQuery,用户可以在XML列中使用XML节点和节点值插入,更新和删除。 SQL Server 2005或更高版本允许在存储过程中使用XML数据类型的输入参数,并支持使用不同的XML函数从XML节点提取信息,反之亦然,并且在XML数据类型列中也具有属性。

In this article, we will exercise with the Querying XML data type using XQuery to channel the information with the XML nodes and attributes with a few examples. Here, we have utilized one example table with sample data for a better explanation.

在本文中,我们将使用XQuery来使用Querying XML数据类型进行练习,以通过一些示例将信息传递给XML节点和属性。 在这里,我们利用了一个带有示例数据的示例表来进行更好的解释。

List XML Data typed Column

Sample XML:

样本XML:

<EmployeeDetails>
  <BusinessEntityID>3</BusinessEntityID>
  <NationalIDNumber>509647174</NationalIDNumber>
  <JobTitle>Engineering Manager</JobTitle>
  <BirthDate>1974-11-12</BirthDate>
  <MaritalStatus>M</MaritalStatus>
  <Gender>M</Gender>
  <StoreDetail>
    <Store>
      <AnnualSales>800000</AnnualSales>
      <AnnualRevenue>80000</AnnualRevenue>
      <BankName>Guardian Bank</BankName>
      <BusinessType>BM</BusinessType>
      <YearOpened>1987</YearOpened>
      <Specialty>Touring</Specialty>
      <SquareFeet>21000</SquareFeet>
    </Store>
    <Store>
      <AnnualSales>300000</AnnualSales>
      <AnnualRevenue>30000</AnnualRevenue>
      <BankName>International Bank</BankName>
      <BusinessType>BM</BusinessType>
      <YearOpened>1982</YearOpened>
      <Specialty>Road</Specialty>
      <SquareFeet>9000</SquareFeet>
    </Store>
  </StoreDetail>
</EmployeeDetails>

从目标XML节点获取值 (Fetching value from target XML node)

The tabular format from an XML document with the bifurcation of XML node as the column name utilizing the SQL Server can be accomplished with the help of XQuery. XQuery will return the XML node value in the tabular model with a combination of nodes() and value() function on the XML column. nodes() function acknowledges XML node location as

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值