我有一个XML,其中根下面的每个元素都是一行;每行仅由一个列名及其列值组成。如何将所说的XML转换成XMLTable?
我试图从路径'/ root / line'构造XMLTable(请参见下面的代码)。
with myxml as
(select '<root><line><column>X</column><value_of_column>1</value_of_column></line><line><column>Y</column><value_of_column>2</value_of_column></line></root>' xml
from dual)
select * from xmltable('/root/line' passing (select xml from myxml) columns "Name" varchar2(255) path '/root/line/column', "Value" varchar2(255) path '/root/line/value_of_column');
我希望输出为:
Name | Value
------------
X | 1
Y | 2
但是实际输出是错误消息:ORA-19224:XPTY0004-XQuery静态类型不匹配:预期-node()*得到了-xs:string
答案 0 :(得分:0)
找到了解决方案。似乎这里的重点是在使用PASSING子句时传递XMLType:
with myxml as
(select '<root><line><column>X</column><value_of_column>1</value_of_column></line><line><column>Y</column><value_of_column>2</value_of_column></line></root>' xml
from dual)
select *
from xmltable('/root/line' passing xmltype((select xml from myxml)) columns "Name" varchar2(255) path 'column',
"Value" varchar2(255) path 'value_of_column');