删除oracle中的XML标记

时间:2015-05-22 11:10:57

标签: xml oracle

create or replace
PROCEDURE GETJOBDETAILS_SP
(
i_ID IN number ;
) 
AS
 l_refcursor SYS_REFCURSOR;

   qryCtx DBMS_XMLGEN.ctxHandle;
   o_Clob CLOB;
   o_xmltype xmltype;


BEGIN

 OPEN l_refcursor FOR SELECT XMLROOT(
         XMLELEMENT("dept_list",
           XMLAGG (
             XMLELEMENT("dept",
               XMLATTRIBUTES(d.deptno AS "deptno"),
               XMLFOREST(
                 d.deptno AS "deptno",
                 d.dname AS "dname",
                 d.loc AS "loc",
                 (SELECT XMLAGG(
                           XMLELEMENT("emp",
                             XMLFOREST(
                               e.empno AS "empno",
                               e.ename AS "ename",
                               e.job AS "job",
                               e.mgr AS "mgr",
                               e.hiredate AS "hiredate",
                               e.sal AS "sal",
                               e.comm AS "comm"
                             )
                           )
                         )
                  FROM   emp e
                  WHERE  e.deptno = d.deptno
                 ) "emp_list"
               )
             )
           )
         )
       ) AS "depts"
FROM   dept d
WHERE  d.deptno = i_ID;



 qryCtx := DBMS_XMLGEN.newContext(l_refcursor);

 DBMS_XMLGEN.setRowSetTag(qryCtx,null);
 DBMS_XMLGEN.SetRowTag (qryCtx, null );
 DBMS_XMLGEN.setNullHandling( qryCtx, DBMS_XMLGEN.EMPTY_TAG );

  o_Clob := DBMS_XMLGEN.getXML( qryCtx );        
  o_xmltype := xmltype(o_Clob);

    DBMS_OUTPUT.PUT_LINE(o_xmltype.getClobVal) ;
    DBMS_XMLGEN.closeContext( qryCtx );

END GETJOBDETAILS_SP;

大家好,

我有两个表一个是'emp',第二个是'dept'我创建了获取xml数据的过程,如上所示。

给出如下输出,

<?xml version="1.0" encoding="US-ASCII"?>
<depts>
<dept_list>
  <dept deptno="10">
    <deptno>10</deptno>
    <dname>ACCOUNTING</dname>
    <loc>NEW YORK</loc>
    <emp_list>
      <emp>
        <empno>7782</empno>
        <ename>CLARK</ename>
        <job>MANAGER</job>
        <mgr>7839</mgr>
        <hiredate>1981-06-09</hiredate>
        <sal>2450</sal>
      </emp>
      <emp>
        <empno>7839</empno>
        <ename>KING</ename>
        <job>PRESIDENT</job>
        <hiredate>1981-11-17</hiredate>
        <sal>5000</sal>
      </emp>
      <emp>
        <empno>7934</empno>
        <ename>MILLER</ename>
        <job>CLERK</job>
        <mgr>7782</mgr>
        <hiredate>1982-01-23</hiredate>
        <sal>1300</sal>
      </emp>
    </emp_list>
  </dept>
</dept_list>
<depts>

但是在这个xml中我不需要根<depts> 当我尝试简单的选择程序声明时,我没有得到<depts>为什么呢?

我只需要输出如下所示的那个根,

<?xml version="1.0" encoding="US-ASCII"?>
<dept_list>
  <dept deptno="10">
    <deptno>10</deptno>
    <dname>ACCOUNTING</dname>
    <loc>NEW YORK</loc>
    <emp_list>
      <emp>
        <empno>7782</empno>
        <ename>CLARK</ename>
        <job>MANAGER</job>
        <mgr>7839</mgr>
        <hiredate>1981-06-09</hiredate>
        <sal>2450</sal>
      </emp>
      <emp>
        <empno>7839</empno>
        <ename>KING</ename>
        <job>PRESIDENT</job>
        <hiredate>1981-11-17</hiredate>
        <sal>5000</sal>
      </emp>
      <emp>
        <empno>7934</empno>
        <ename>MILLER</ename>
        <job>CLERK</job>
        <mgr>7782</mgr>
        <hiredate>1982-01-23</hiredate>
        <sal>1300</sal>
      </emp>
    </emp_list>
  </dept>
</dept_list>

请帮忙......! 感谢。

0 个答案:

没有答案