我的问题与这个问题相同,但我使用的是 Oracle 12.1 而不是 SQL Server。
我想从以下 xml 文档中提取所有名称元素:
<ci5>
<employee>
<name>George Cowley</name>
<salary via="B">80000</salary>
</employee>
<employee>
<name>William Bodie</name>
<salary via="C">40000</salary>
</employee>
<employee>
<name>Ray Doyle</name>
<salary via="C">40000</salary>
</employee>
</ci5>
我想要的输出是三个单独的行,例如:
<name>George Cowley</name>
<name>William Bodie</name>
<name>Ray Doyle</name>
使用以下查询
SELECT XMLQUERY('ci5/employee/name'
PASSING BY VALUE XMLTYPE.CREATEXML('<ci5><employee><name>George Cowley</name><salary via="B">80000</salary></employee><employee><name>William Bodie</name><salary via="C">40000</salary></employee><employee><name>Ray Doyle</name><salary via="C">40000</salary></employee></ci5>') RETURNING CONTENT) x
FROM dual;
SELECT XMLQUERY('for $i in /ci5
return $i/employee/name'
PASSING BY VALUE XMLTYPE.CREATEXML('<ci5><employee><name>George Cowley</name><salary via="B">80000</salary></employee><employee><name>William Bodie</name><salary via="C">40000</salary></employee><employee><name>Ray Doyle</name><salary via="C">40000</salary></employee></ci5>') RETURNING CONTENT) x
FROM dual;
显示了名称,但输出都在一行上:
<name>George Cowley</name><name>William Bodie</name><name>Ray Doyle</name>
看起来我需要使用该NODE
函数,但我不知道如何在 Oracle 上下文中使用它。