Saturday, January 17, 2009

DBMS_XMLGEN

DBMS XMLGEN is a PL/SQL package that allows programmers to extract XML data from Oracle database tables. It might be useful when you need a XML file to create XML publisher layouts. Here are 2 examples on how to use it;

SELECT DBMS_XMLGEN.getXML('SELECT * FROM emp') FROM dual;

or
DECLARE
ctx DBMS_XMLGEN.ctxHandle;
xml CLOB;
BEGIN
ctx := dbms_xmlgen.newcontext('select * from emp');
dbms_xmlgen.setrowtag(ctx, 'MY-ROW-START-HERE');
xml := dbms_xmlgen.getxml(ctx);
dbms_output.put_line(substr(xml,1,255));
END;
/