Ваш XML-документ должен иметь один элемент XML в качестве корневого элемента документа :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<message>Hi Hello</message>
<channel>XYZ</channel>
<sentiment-score>5.0</sentiment-score>
<structured-fields>
<structured-field><name>NA_score</name><value>5</value></structured-field>
<structured-field><name>NPS_score</name><value>10</value></structured-field>
</structured-fields>
</root>
Как только это будет исправлено, просто используйте XMLTable
и XPath:
SELECT *
FROM XMLTABLE(
'/root'
PASSING XMLType( '<?xml version="1.0" encoding="UTF-8"?><root><message>Hi Hello</message><channel>XYZ</channel><sentiment-score>5.0</sentiment-score><structured-fields><structured-field><name>NA_score</name><value>5</value></structured-field><structured-field><name>NPS_score</name><value>10</value></structured-field></structured-fields></root>' )
COLUMNS
MESSAGE VARCHAR2(200) PATH '//message',
CHANNEL VARCHAR2(200) PATH '//channel',
SENTIMENT_SCORE NUMBER(3,1) PATH '//sentiment-score',
NA_SCORE NUMBER(3,0) PATH '//structured-fields/structured-field[name/text()="NA_score"]/value',
NPS_SCORE NUMBER(3,0) PATH '//structured-fields/structured-field[name/text()="NPS_score"]/value'
);
выход :
MESSAGE | CHANNEL | SENTIMENT_SCORE | NA_SCORE | NPS_SCORE
:------- | :------ | --------------: | -------: | --------:
Hi Hello | XYZ | 5 | 5 | 10
дБ <> скрипка здесь