Retrieving XML element name using t-SQL(使用 t-SQL 检索 XML 元素名称)
本文介绍了使用 t-SQL 检索 XML 元素名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有:
<quotes>
<quote>
<name>john</name>
<content>something or other</content>
</quote>
<quote>
<name>mary</name>
<content>random stuff</content>
</quote>
</quotes>
如何使用 T-SQL 获取元素名称名称"和内容"的列表?
How do I get a list of the element names 'name' and 'content' using T-SQL?
到目前为止我得到的最好的是:
The best I've got so far is:
declare @xml xml
set @xml = ...
select r.value('quotes/name()[1]', 'nvarchar(20)' as ElementName
from @xml.nodes('/quotes') as records(r)
但是,当然,我不能让它工作.
But, of course, I can't get this to work.
推荐答案
实际上,抱歉,我得到的最好的是:
Actually, sorry, the best I've got is:
select distinct r.value('fn:local-name(.)', 'nvarchar(50)') as t
FROM
@xml.nodes('//quotes/*/*') AS records(r)
猜猜我回答了我自己的问题...
Guess I answered my own question...
这篇关于使用 t-SQL 检索 XML 元素名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:使用 t-SQL 检索 XML 元素名称


基础教程推荐
猜你喜欢
- 在多列上分布任意行 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01