2014-10-29 3 views
0

에 아래 쿼리를 작성했습니다. 일부 수동 XML 태그를 추가하려고합니다.oracle xml 쿼리에 수동 xml 태그 추가

select 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" 
      ) 
     ) 
     ) 
    ).extract('*') as "depts" 
from dept d 
where d.deptno = 10; 

출력

<dept_list> 
    <dept deptno="10"> 
    <deptno>10</deptno> 
    <dname>ACCOUNTING</dname> 
    <loc>NEW YORK</loc> 
    <emp_list> 
     <emp> 
     <empno>7934</empno> 
     <ename>MILLER</ename> 
     <job>CLERK</job> 
     <mgr>7782</mgr> 
     <hiredate>1982-01-23</hiredate> 
     <sal>1300</sal> 
     </emp> 
     <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> 
     <comm>100</comm> 
     </emp> 
    </emp_list> 
    </dept> 
    </dept_list> 

하지만 난 오라클 데이터베이스 10g를 사용하고이

**<?xml version="1.0"?>       
<batch xmlns="urn:mclsoftware.co.uk:hunterII"> 
<header><count>2</count> 
<originator>KALPATARU</originator> 
<suppress>y</suppress> 
</header>** 
<dept_list> 
<dept deptno="10"> 
<deptno>10</deptno> 
<dname>ACCOUNTING</dname> 
<loc>NEW YORK</loc> 
<emp_list> 
    <emp> 
    <empno>7934</empno> 
    <ename>MILLER</ename> 
    <job>CLERK</job> 
    <mgr>7782</mgr> 
    <hiredate>1982-01-23</hiredate> 
    <sal>1300</sal> 
    </emp> 
    <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> 
    <comm>100</comm> 
    </emp> 
</emp_list> 
</dept> 
</dept_list> 
**</batch>** 

같은 출력이 필요합니다.

답변

0

dbmsxml 프로 시저가 상위 요소 (버전 태그)를 제공하지만 태그에 속성을 추가 할 수 없음을 발견했습니다. 이를 위해서는 dbms_xmldom을 사용해야합니다. 여기에 하나의 example이 있지만 더 자세한 문서를 보려면 Oracle을 검색하십시오.