Oracle provides plenty of XML generation methods, I’ll try to demonstrate two of them: SYS_XMLGEN and DBMS_XMLQUERY.

I’ll start with creating a simple table and fill it with sample data:

To be able to use SYS_XMLGEN, I’ll create an object to map our data:

Now I can easily convert my data to XML:

It will convert each row as a separate XML, so I’ll use SYS_XMLAGG to aggregate all rows:

If I can use UTL_FILE to write this output to a file:

Here’s the content of the “test.xml” file:

As you see, it’s very easy to generate XML file from the Oracle databases with using SYS_XMLGEN. On the other hand, DBMS_XMLQUERY package provides much more simply way to generate XML:

Here’s the result:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>