我有一个包含以下内容的 XMLTYPE:
I have a XMLTYPE with the following content:
<?xml version="1.0"?>
<users>
<user>
<name>user1</name>
</user>
<user>
<name>user2</name>
</user>
<user>
<name>user3</name>
</user>
</users>
如何在 PL/SQL 中循环遍历所有元素user"?谢谢
How can I loop in PL/SQL through all the elements "user"? Thanks
您可以使用 EXTRACT
和 XMLSequence
遍历元素(将 XML 拆分为不同的块 --这里的用户)像这样:
You can loop through the elements using EXTRACT
and XMLSequence
(splits the XML into distinct chunks -- here users) like this:
SQL> SELECT extractvalue(column_value, '/user/name') "user"
2 FROM TABLE(XMLSequence(XMLTYPE(
3 '<?xml version="1.0"?>
4 <users>
5 <user>
6 <name>user1</name>
7 </user>
8 <user>
9 <name>user2</name>
10 </user>
11 <user>
12 <name>user3</name>
13 </user>
14 </users>').extract('/users/user'))) t;
user
--------
user1
user2
user3
这篇关于Oracle Pl/SQL:循环通过 XMLTYPE 节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!