Let's say that we need to produce something like this for all departments.
<departments>
<accounting>
<employee>Clark</employee>
<employee>King</employee>
<employee>Miller</employee>
</accounting>
...
</departments>
select xmlelement("department",
xmlagg(xmlelement("employee", initcap(e.ename))))
from dept d
left outer join emp e on (e.deptno = d.deptno)
group by d.deptno;
Result (4 rows):
<department>
<employee>King</employee>
<employee>Miller</employee>
<employee>Clark</employee>
</department>
<department>
<employee>Jones</employee>
<employee>Adams</employee>
<employee>Smith</employee>
<employee>Ford</employee>
<employee>Scott</employee>
</department>
<department>
<employee>Blake</employee>
<employee>James</employee>
<employee>Turner</employee>
<employee>Martin</employee>
<employee>Ward</employee>
<employee>Allen</employee>
</department>
<department>
<employee></employee>
</department>
select xmlelement("departments",
xmlagg(
xmlelement("department",
xmlagg(xmlelement("employee", initcap(ename))))))
from dept d
left outer join emp e on (e.deptno = d.deptno)
group by d.deptno, d.dname;
Result:
<departments>
<department>
<employee>King</employee>
<employee>Miller</employee>
<employee>Clark</employee>
</department>
<department>
<employee>Jones</employee>
<employee>Adams</employee>
<employee>Smith</employee>
<employee>Ford</employee>
<employee>Scott</employee>
</department>
<department>
<employee>Blake</employee>
<employee>James</employee>
<employee>Turner</employee>
<employee>Martin</employee>
<employee>Ward</employee>
<employee>Allen</employee>
</department>
<department>
<employee></employee>
</department>
</departments>
select xmlelement("departments",
xmlagg(
xmlelement(dname,
xmlagg(xmlelement("employee", initcap(ename))))))
from dept d
left outer join emp e on (e.deptno = d.deptno)
group by d.deptno, d.dname;
Result:
<departments>
<DNAME>
<employee>King</employee>
<employee>Miller</employee>
<employee>Clark</employee>
</DNAME>
<DNAME>
<employee>Jones</employee>
<employee>Adams</employee>
<employee>Smith</employee>
<employee>Ford</employee>
<employee>Scott</employee>
</DNAME>
<DNAME>
<employee>Blake</employee>
<employee>James</employee>
<employee>Turner</employee>
<employee>Martin</employee>
<employee>Ward</employee>
<employee>Allen</employee>
</DNAME>
<DNAME>
<employee></employee>
</DNAME>
</departments>
select xmlelement("departments",
xmlagg(
xmlelement(evalname lower(dname),
xmlagg(xmlelement("employee", initcap(ename))))))
from dept d
left outer join emp e on (e.deptno = d.deptno)
group by d.deptno, d.dname;
Result:
<departments>
<accounting>
<employee>King</employee>
<employee>Miller</employee>
<employee>Clark</employee>
</accounting>
<research>
<employee>Jones</employee>
<employee>Adams</employee>
<employee>Smith</employee>
<employee>Ford</employee>
<employee>Scott</employee>
</research>
<sales>
<employee>Blake</employee>
<employee>James</employee>
<employee>Turner</employee>
<employee>Martin</employee>
<employee>Ward</employee>
<employee>Allen</employee>
</sales>
<operations>
<employee></employee>
</operations>
</departments>
No comments:
Post a Comment