Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Root element should return NULL if no data in source

user6314670Sep 27 2019 — edited Sep 27 2019

Hi All, Wrote the below query and per requirement, it is returning the result as expected but if there is no data into the table then it should not return anything, neither root element (second query output), should return NULL. Could you please help me correcting below query or the solution to resolve this issue. Thanks in advance for your help. with xml_data as (select XMLELEMENT("DailyTNA",                     XMLATTRIBUTES('USD' AS "Currency", '2014-12-18' as "Date"),                     to_char(3510000.0,                             'FM999999999999999999999999999990D0999999999')) as xmldoc,         1 as sort_ord,         '2014-12-18' as data_date     from dual   union all   select XMLELEMENT("SharesOutstanding",                     XMLATTRIBUTES('2013-12-31' as "Date"),                     to_char(17178383.0,                             'FM999999999999999999999999999990D0999999999')) as xmldoc,         2 sort_ord,         '2013-12-31' as data_date     from dual) select XMLELEMENT("Profile",                   XMLELEMENT("AssetValues",                             XMLAgg(xmldoc order by sort_ord, data_date desc)))   from xml_data Output 3510000.017178383.0 with xml_data as (select NULL as xmldoc, 1 as sort_ord, '2014-12-18' as data_date     from dual   union all   select NULL as xmldoc, 2 sort_ord, '2013-12-31' as data_date     from dual) select XMLELEMENT("Profile",                   XMLELEMENT("AssetValues",                             XMLAgg(xmldoc order by sort_ord, data_date desc)))   from xml_data Output Thanks

This post has been answered by cormaco on Sep 27 2019
Jump to Answer
Comments
Post Details
Added on Sep 27 2019
2 comments
481 views