最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

SQLServerXML数据的五种基本操作

来源:动视网 责编:小采 时间:2020-11-09 07:14:37
文档

SQLServerXML数据的五种基本操作

SQLServerXML数据的五种基本操作:1.xml.exist 输入为XQuery表达式,返回0,1或是Null。0表示不存在,1表示存在,Null表示输入为空 2.xml.value 输入为XQuery表达式,返回一个SQL Server标量值 3.xml.query 输入为XQuery表达式,返回一个SQL Server XML类型流 4.xml
推荐度:
导读SQLServerXML数据的五种基本操作:1.xml.exist 输入为XQuery表达式,返回0,1或是Null。0表示不存在,1表示存在,Null表示输入为空 2.xml.value 输入为XQuery表达式,返回一个SQL Server标量值 3.xml.query 输入为XQuery表达式,返回一个SQL Server XML类型流 4.xml


1.xml.exist
输入为XQuery表达式,返回0,1或是Null。0表示不存在,1表示存在,Null表示输入为空
2.xml.value
输入为XQuery表达式,返回一个SQL Server标量值
3.xml.query
输入为XQuery表达式,返回一个SQL Server XML类型流
4.xml.nodes
输入为XQuery表达式,返回一个XML格式文档的一列行集
5.xml.modify
使用XQuery表达式对XML的节点进行insert , update 和 delete 操作。
下面通过例子对上面的五种操作进行说明:
declare @XMLVar xml = '
<catalog>
<book category="ITPro">
<title>Windows Step By Step</title>
<author>Bill Zack</author>
<price>49.99</price>
</book>
<book category="Developer">
<title>Developing ADO .NET</title>
<author>Andrew Brust</author>
<price>39.93</price>
</book>
<book category="ITPro">
<title>Windows Cluster Server</title>
<author>Stephen Forte</author>
<price>59.99</price>
</book>
</catalog>'
1. xml.exist
select @XMLVar.exist('/catalog/book')-----返回1
select @XMLVar.exist('/catalog/book/@category')-----返回1
select @XMLVar.exist('/catalog/book1')-----返回0
set @XMLVar = null
select @XMLVar.exist('/catalog/book')-----返回null
2.xml.value
select @XMLVar.value('/catalog[1]/book[1]','varchar(MAX)')
select @XMLVar.value('/catalog[1]/book[2]/@category','varchar(MAX)')
select @XMLVar.value('/catalog[2]/book[1]','varchar(MAX)')
结果集为:
Windows Step By StepBill Zack49.99 Developer NULL
3.xml.query
select @XMLVar.query('/catalog[1]/book')
select @XMLVar.query('/catalog[1]/book[1]')
select @XMLVar.query('/catalog[1]/book[2]/author')
结果集分别为:
<book category="ITPro">
<title>Windows Step By Step</title>
<author>Bill Zack</author>
<price>49.99</price>
</book>
<book category="Developer">
<title>Developing ADO .NET</title>
<author>Andrew Brust</author>
<price>39.93</price>
</book>
<book category="ITPro">
<title>Windows Cluster Server</title>
<author>Stephen Forte</author>
<price>59.99</price>
</book>
<book category="ITPro">
<title>Windows Step By Step</title>
<author>Bill Zack</author>
<price>49.99</price>
</book>
<author>Andrew Brust</author>
4.xml.nodes
select T.c.query('.') as result from @XMLVar.nodes('/catalog/book') as T(c)
select T.c.query('title') as result from @XMLVar.nodes('/catalog/book') as T(c)
结果集分别为:
<book category="ITPro"><title>Windows Step By Step</title><author>Bill …………
<book category="Developer"><title>Developing ADO .NET</title><author>Andrew …………
<book category="ITPro"><title>Windows Cluster Server</title><author>Stephen …………
<title>Windows Step By Step</title>
<title>Developing ADO .NET</title>
<title>Windows Cluster Server</title>
5.xml.modify
关于modify内容,请参见下一篇文章。

您可能感兴趣的文章:

  • sqlserver2005 xml字段的读写操作
  • C#怎样才能将XML文件导入SQL Server
  • SQLServer XML查询快速入门(18句话)
  • SqlServer参数化查询之where in和like实现之xml和DataTable传参介绍
  • Sqlserver 2005使用XML一次更新多条记录的方法
  • 在SQL Server中将数据导出为XML和Json的方法
  • SQLServer XML查询18句话入门教程
  • SQL Server解析XML数据的方法详解
  • 文档

    SQLServerXML数据的五种基本操作

    SQLServerXML数据的五种基本操作:1.xml.exist 输入为XQuery表达式,返回0,1或是Null。0表示不存在,1表示存在,Null表示输入为空 2.xml.value 输入为XQuery表达式,返回一个SQL Server标量值 3.xml.query 输入为XQuery表达式,返回一个SQL Server XML类型流 4.xml
    推荐度:
    标签: 使用 xml sqlserver
    • 热门焦点

    最新推荐

    猜你喜欢

    热门推荐

    专题
    Top