I am trying to used a stored proc to return an xml string from sysibm.sqltables formatted as follows:
<TABLES>
<schema name='schema1'>
<table>table1</table>
<table>table2</table>
</schema>
<schema name='schema2'>
<table>table3</table>
<table>table4></table>
</schema>
</TABLES>
The closest I can get is as follows:
SELECT XML2CLOB (XMLELEMENT (NAME "TABLES", XMLELEMENT (NAME "schema", XMLATTRIBUTES (table_schem AS "name"),
XMLAGG (XMLFOREST(table_name AS "table")))))
FROM sysibm.sqltables GROUP BY table_schem;
This produces a separate result for each schema because of the GROUP BY statement, but if this is left out an error occurs saying that table_schem needs to be in a GROUP BY statement.
Does anyone have any ideas?
Many thanks,
Ian
