Oracle XMLForest
The example below shows the use of Oracle function XMLElement together with XMLForest to get XML output from an Oracle database table (query table qt_ph as shown below).

SELECT
  XMLElement("Phone",
   XMLForest(qt_ph.area_code "Area_Code",
     qt_ph.city "City",
     qt_ph.st_cd "State")).getstringval() AS xml_out
FROM
  (SELECT 212 area_code, 'New York' city, 'NY' st_cd FROM DUAL UNION
   SELECT 213 area_code, 'Los Angeles' city, 'CA' st_cd FROM DUAL UNION
   SELECT 214 area_code, 'Dallas' city, 'TX' st_cd FROM DUAL UNION
   SELECT 215 area_code, 'Philadelphia' city, 'PA' st_cd FROM DUAL
  ) qt_ph;


Back

Oracle registered trademark of Oracle Corporation.

Last Revised On: November 17, 2013

  1420