【发布时间】:2021-10-11 04:55:54
【问题描述】:
我正在尝试解析转换为 xml 的 SOAP 请求响应。 请注意,这是我第一次使用这种查询。 它的结构如下:
<soap:Body>
<ns2:findDocumentsResponse xmlns:ns2="http://www.datengut.de">
<ecmDocumentInfo>
<id>53CA3873CCFCC44FB5FE99047E5ED04E000000000000</id>
<fields>
<entry>
<key>SYSFILENAMES</key>
<value>
<name>SYSFILENAMES</name>
<type>STRING</type>
<values xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">test_file1.pdf</values>
<values xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">test_file2.pdf</values>
<values xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">test_file3.pdf</values>
<values xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">test_file4.pdf</values>
<isMulti>true</isMulti>
</value>
</entry>
</fields>
....
我使用的 SQL 查询如下:
SELECT
t."key", f."value"
FROM
XMLTABLE(
xmlnamespaces('http://schemas.xmlsoap.org/soap/envelope/' as "soap",'http://www.datengut.de' as "ns2"),
'/soap:Envelope/soap:Body/ns2:findDocumentsResponse/ecmDocumentInfo/fields/entry'
PASSING xmltype.createXML('[see structure above]')
COLUMNS
"key" varchar2(4000) PATH 'key',
"path" XMLType path 'value'
) t
CROSS JOIN XMLTABLE(
'value'
PASSING t."path"
COLUMNS
"value" varchar2(4000) PATH '.'
) f
我收到的输出:
KEY VALUE
------------------- ---------------------------------------
SYSFILENAMES SYSFILENAMESSTRINGtest_file1.pdftest_file2.pdftest_file3.pdftest_file4.pdftrue
我期望收到的输出:
KEY VALUE
------------------- ---------------------------------------
SYSFILENAMES test_file1.pdf
SYSFILENAMES test_file2.pdf
SYSFILENAMES test_file3.pdf
SYSFILENAMES test_file4.pdf
当我换行时:
"value" varchar2(4000) PATH '.'
到
"value" varchar2(4000) PATH 'values'
我收到“ORA-19279:XPTY0004 - XQuery 动态类型不匹配:预期的单例序列”错误消息。当 PATH 为 '.' 时不会出现错误但随后我在同一行中收到值条目的每个值。我只想显示预期结果部分中显示的文件名。 如何交叉加入第二个 XMLTABLE f 以接收我的预期输出。 非常感谢。
【问题讨论】: