我的xmltype数据集如下:
记录 1:
<row id=“1”>
<c1>test|10</c1>
<c2>teste|20</c2>
</row>
记录 2:
<row id=“2”>
<c1>2test|10</c1>
<c2>2teste|20</c2>
</row>
我需要以以下格式显示数据,列也不会修复 但列中的值将采用相同的语法。
Id Name Value
------------------
1 test 10
1 teste 20
2 2test 10
2 2teste 20
您可以使用xmltable
将 xml 转换为表格形式。在这里,我添加了一个根元素<R>
和其他一些测试元素。你也可以按原样获取 SELECT 的值,然后使用 substr(((而不是 tokenize(((。
select x.id, x.key, x.val from xmltable (
'//row/*'
passing xmltype (
'<R>
<row id="1">
<c1>test|10</c1>
<c2>teste|20</c2>
</row>
<row id="2">
<c1>2test|10</c1>
<c2>2teste|20</c2>
<c11>2test|11</c11>
<c22>2teste|22</c22>
<c33>2teste</c33>
<c44>|44</c44>
<c55></c55>
</row>
</R>')
columns
id number path './../@id',
key varchar2(30) path 'fn:tokenize(., "|")[1]',
val varchar2(30) path 'fn:tokenize(., "|")[2]'
) x
ID KEY VAL
---------- ------------------------------ ------------------------------
1 test 10
1 teste 20
2 2test 10
2 2teste 20
2 2test 11
2 2teste 22
2 2teste
2 44
2
9 rows selected.