> I have previously posted in this subject, but this is different, and,
> I hope, easier:
[quoted text clipped - 12 lines]
>
> Does anyone know how to do this?
Personally, I'm on DB2 v8 which had limited XML support, but DB2 9
includes a whole bunch [1] of XML stuff which ought to be of use to you
here (including XQuery support).
Still, even in v8 one could probably produce useful XML output
(although I'm not sure what you mean by an "acceptable XML format").
See for example the XMLELEMENT function [2] (which was present in v8,
and is still there in 9). Here's one of the example queries against the
SAMPLE database:
SELECT XMLELEMENT(
NAME "Department", XMLATTRIBUTES(
E.WORKDEPT AS "name"
),
XMLAGG(
XMLELEMENT(
NAME "emp", E.FIRSTNME
)
ORDER BY E.FIRSTNME
)
)
AS "dept_list"
FROM EMPLOYEE E
WHERE E.WORKDEPT IN ('A00', 'B01')
GROUP BY WORKDEPT
Which produces the following output:
<Department name="A00">
<emp>CHRISTINE</emp>
<emp>SEAN</emp>
<emp>VINCENZO</emp>
</Department>
<Department name="B01">
<emp>MICHAEL</emp>
</Department>
Even though this isn't a "proper" XML document (it would need to be
wrapped in a root element and have an XML PI stuck on the front), it's
a good start (adding the necessary tags could be easily done by
UNIONing the query with a couple of VALUES statements, or could be
handled by the application logic).
[1]
http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb
.rn.doc/doc/c0023113.htm
[2]
http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb
.admin.doc/doc/r0022188.htm
HTH,
Dave.
--
2803stan@gmail.com - 27 Jul 2007 23:16 GMT
> > I have previously posted in this subject, but this is different, and,
> > I hope, easier:
[quoted text clipped - 69 lines]
>
> - Show quoted text -
________
Thanks, Dave.
Whole new world! Using the XML commands is a new language.
Stan