Tuesday, October 30, 2012

Generate XML from SQL Query in Oracle

Use this one to generate XML


DECLARE
   qryCtx DBMS_XMLGEN.ctxHandle;
   result CLOB;
BEGIN
  qryCtx := dbms_xmlgen.newContext('SELECT * from scott.emp');

  -- set the row header to be EMPLOYEE
  DBMS_XMLGEN.setRowTag(qryCtx, 'EMPLOYEE');

  -- now get the result
  result := DBMS_XMLGEN.getXML(qryCtx);

  INSERT INTO temp_clob_tab VALUES(result); 

  --close context
  DBMS_XMLGEN.closeContext(qryCtx);
END;

Reference: http://docs.oracle.com/cd/B10501_01/appdev.920/a96620/xdb12gen.htm

No comments:

Post a Comment