给定的是“ XYZ”表中“ my_xml”列的值
<?xml version="1.0" encoding="UTF-8"?>
<India>
<city>
<string>ADI</string>
<string>Ahmedabad</string>
</city>
<city>
<string>GNR</string>
<string>Gandhinagar</string>
</city>
<city>
<string>PUN</string>
<string>Pune</string>
</city>
<city>
<string>RJT</string>
<string>Rajkot</string>
</city>
</India>
我正在尝试提取第二个string
节点的值,其中第一个string
节点的值是ADI
输出应仅是“艾哈迈达巴德”
尝试失败:
select t.my_xml.extract('/India/city/string[2]/text()').getStringVal() from XYZ t where t.my_xml.existsNode('/India/city[string[1] = "ADI"]') = 1;
以上查询的输出是 AhmedabadGandhinagarPuneRajkot
预期产量: Ahmedabad
这里如何为string
节点提取特定的节点值?
你要选择的节点具有ADI的文本作为第一个字符串。
试试这个:
select
t.my_xml.extract('//city[./string[1]/text() = "ADI"]/string[2]/text()').getStringVal()
from XYZ t
where t.my_xml.existsNode('/India/city[string[1] = "ADI"]') = 1;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句