Simplifying, I produce a set of XML elements with a SQL query such as:
SELECT XMLELEMENT(NAME "project", project) FROM project;
<project>project1</project>
<project>project2</project>
...
Now I need to wrap this sequence into a main "projects" element, and output this in a nice indented XML file.
I've tried as follows:
db2 -x "SELECT XMLSERIALIZE(CONTENT XMLELEMENT(NAME "projects", XMLAGG(XMLELEMENT(NAME "project", project))) AS CLOB INCLUDING XMLDECLARATION) FROM project" >output.xml
And I get something like:
<projects><project>project1</project><project>project2</project>...</projects>
The XMLAGG works (it has wrapped everything into a main projects element). However, with 100k thousand projects, db2 complains with "SQL0433N Value "... is too long. SQLSTATE=22001"
Also, output.xml is not indented (everything is in one line).
What is the correct way to achieve this?
Regards, David