Package DBMS_XMLGEN now supports hierarchical queries. PL/SQL package DBMS_XMLGEN creates XML documents from SQL query results.
It retrieves an XML document as a CLOB or XMLType value.
Converts the query results from the passed in SQL query string to XML format, and returns the XML as a CLOB.
Syntax:
FUNCTION DBMS_XMLGEN.getXML
(
sqlQuery IN VARCHAR2,
dtdOrSchema IN NUMBER := NONE
) RETURN CLOB;
Converts the query results from the passed in SQL query string to XML format, and returns the XML as a XMLTYPE.
Syntax:
FUNCTION DBMS_XMLGEN.getXMLType
(
sqlQuery IN VARCHAR2,
dtdOrSchema IN NUMBER := NONE
) RETURN XMLType;
Package DBMS_XMLGEN also provides options for changing tag names for ROW, ROWSET, and so on.
setRowTag() : Sets the name of the element separating all the rows. The default name is ROW.
setRowSetTag() : Sets the name of the document root element. The default name is ROWSET
Example1:
SELECT dbms_xmlgen.getxml('select * from emp where rownum<6') data FROM dual --RETURNS CLOB
Example2:
SELECT dbms_xmlgen.getxmltype ('select * from emp where rownum<6') data FROM dual --RETURNS XMLTYPE
Output:
<ROWSET>
<ROW>
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>17-Dec-1980</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>20-Feb-1981</HIREDATE>
<SAL>1600</SAL>
<COMM>300</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
</ROWSET>
For More Info : DBMS_XMLGEN
No comments:
Post a Comment