SqlServer2005 操作XML 实战
2007-10-26 21:07
274 查看
XML 大兴其道。文件越来越大。在SqlServer中查询检索,会使工作得心应手。
常用SQL:
1. 提取关心数据。以表行的形式列出。要注意的是。Xquery在解析 XML 文档里,无素内容是和关键字是区分大小写的。
create table #t (id int ,xm xml)
insert into #t(id,xm)
select 1 , * from OpenRowSet( Bulk 'D:\Program Files\StormII\config.xml', Single_Blob ) as x
--只关心 其他视频/音频文件
insert into #t(id,xm)
select 2,xm.query('for $f in /config/association/type[@category="其他视频/音频文件"] return $f') as result from #t
declare @x xml
select @x=xm from #t where id = 2
insert into #t select 3,t.c.query('.')from @x.nodes('/type/item') t(c)
select xm.value('(/item/@format)[1]','varchar(30)' ) as format ,xm.value('(/item/@description)[1]','varchar(30)' ) as description
from #t where id = 3
go
2.XML中的查询。既然已经查出了表的结果集,就可以按表来操作,进行查询。如:查询 其它视频/音频文件 中包含音频的。
select xm.value('(/item/@format)[1]','varchar(30)' ) as format ,xm.value('(/item/@description)[1]','varchar(30)' ) as description
from #t where id = 3
and xm.value('(/item/@description)[1]','varchar(30)' ) like '%音频%'
常用SQL:
1. 提取关心数据。以表行的形式列出。要注意的是。Xquery在解析 XML 文档里,无素内容是和关键字是区分大小写的。
create table #t (id int ,xm xml)
insert into #t(id,xm)
select 1 , * from OpenRowSet( Bulk 'D:\Program Files\StormII\config.xml', Single_Blob ) as x
--只关心 其他视频/音频文件
insert into #t(id,xm)
select 2,xm.query('for $f in /config/association/type[@category="其他视频/音频文件"] return $f') as result from #t
declare @x xml
select @x=xm from #t where id = 2
insert into #t select 3,t.c.query('.')from @x.nodes('/type/item') t(c)
select xm.value('(/item/@format)[1]','varchar(30)' ) as format ,xm.value('(/item/@description)[1]','varchar(30)' ) as description
from #t where id = 3
go
2.XML中的查询。既然已经查出了表的结果集,就可以按表来操作,进行查询。如:查询 其它视频/音频文件 中包含音频的。
select xm.value('(/item/@format)[1]','varchar(30)' ) as format ,xm.value('(/item/@description)[1]','varchar(30)' ) as description
from #t where id = 3
and xm.value('(/item/@description)[1]','varchar(30)' ) like '%音频%'
相关文章推荐
- SQLServer2005中利用xml类型实现批量操作的存储过程[原]
- sqlserver2005 xml字段的读写操作
- sqlserver2005 xml字段的读写操作
- sqlserver2005提供的xml数据类型操作xml串
- SQLSERVER2005中的 XML 及基本操作
- 第21课:scala文件和xml操作实战及spark源码鉴赏
- sqlserver2005 xml字段的读写操作
- sqlserver2005提供的xml数据类型操作xml串
- sqlserver2005 xml字段的读写操作
- sqlserver2005操作XML类型数据
- SQLServer2005 XML数据类型操作
- SQLServer2005 XML数据操作代码
- LINQ - 操作XML
- C#对XML操作:建立XML(2)
- C#中XML的基本操作
- 用javascript操作xml
- C#对XML操作:写入一笔XML记录(2)
- .NET下几种XML操作方式的性能对比
- Android XML的操作(SAX)
- 【vuejs路由】vuejs 路由基础入门实战操作详细指南