XMLFOREST function in PL/SQL

The XMLFOREST function allows you to read values from Oracle tables and present them in XML format. The general format for the XMLFOREST function is:

SELECT XMLFOREST(TABLE.field_name1, TABLE.field_name2, ...)
"alias"
FROM TableName;

This function converts each of its argument parameters (field names from tables) to XML and returns an XML fragment that is a concatenation of each of the arguments (field names) converted to XML. The “alias” is a required part of the XMLFOREST function.

Example:

SELECT XMLFOREST(s.stno, s.sname) "Student name and number"
FROM Student s;

Output:

Student name and number
--------------------------------------------------------------------
<STNO>2</STNO>
<SNAME>kaka</SNAME>
 
<STNO>3</STNO>
<SNAME>bunny</SNAME>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.