I have a query such as this-
WITH xtbl AS (SELECT xmltype ('<root>
<parent>
<item>
<item_detail>AAA</item_detail>
<item_amount>1000</item_amount>
</item>
<item>
<item_detail>BBB</item_detail>
<item_amount>2000</item_amount>
</item>
</parent>
</root>') AS xcol FROM dual)
SELECT xmlcast (
xmlquery ('root/parent/string-join[item/item_detail/text()]' PASSING xcol RETURNING CONTENT) AS VARCHAR2 (2000))
AS item_details
FROM xtbl;
Although the example specified above contains an node, in my real problem not every <parent> node will contain an <item> node. Thus I cannot use the XMLTable solution as described in this answer.
The SELECT xmlcast(... query is what I have tried so far above and it isn't working. My expected output is this-
ITEM_DETAILS
------------------
AAA 1000, BBB 2000
Please suggest how I can modify my XMLQuery.