您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

SQLServer XML数据的五种基本操作

2024/10/18 2:10:17发布35次查看
sqlserver 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 = '
windows step by step
bill zack
49.99
developing ado .net
andrew brust
39.93
windows cluster server
stephen forte
59.99
'
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')
结果集分别为:
windows step by step
bill zack
49.99
developing ado .net
andrew brust
39.93
windows cluster server
stephen forte
59.99
windows step by step
bill zack
49.99
andrew brust
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)
结果集分别为:
windows step by stepbill …………
developing ado .netandrew …………
windows cluster serverstephen …………
windows step by step
developing ado .net
windows cluster server
5.xml.modify
关于modify内容,请参见下一篇文章。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product