[Oracle] Convert Table to XML format in Oracle

[How To] Convert Table to XML format in Oracle

Oracle provides a unique feature to convert any given table into its equivalent XML format. The output that Oracle provides is in CLOB format. The package DBMS_XMLGEN is used for this purpose.

One can also provide where clause conditions, group by, order by clause etc. in the query.

The XML generation using Oracle used as below:
Syntax:
SELECT DBMS_XMLGEN.GETXML('<query_to_get_data_from_table_or_view>') TEST_XML FROM DUAL;


Example:SELECT DBMS_XMLGEN.GETXML('select * from employee') TEST_XML FROM DUAL;

Example with screenshots:

Vishal Lambe - Employee Table

Vishal Lambe - CLOB form of generated XML

Vishal Lambe - XML generated from Employee table