Home » Developer & Programmer » JDeveloper, Java & XML » dbms_xmlgen.getxml problem
dbms_xmlgen.getxml problem [message #129522] Mon, 25 July 2005 10:20 Go to next message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Hi all,
following is the out put of the following query:-

select dbms_xmlgen.getxml('select * from emp e,dept d where e.deptno=d.deptno AND e.deptno=10 and e.job=''PRESIDENT''') from dual;

output:--
<?xml version="1.0"?>
<ROWSET>
<ROW>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
<JOB>PRESIDENT</JOB>
<HIREDATE>17-NOV-81</HIREDATE>
<SAL>5000</SAL>
<DEPTNO>10</DEPTNO>
<DEPTNO>10</DEPTNO>
<DNAME>ACCOUNTING</DNAME>
<LOC>NEW YORK</LOC>
</ROW>
</ROWSET>


But we need an output as below:-
<?xml version="1.0"?>
<ROWSET>
<ROW>
<EMP>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
<JOB>PRESIDENT</JOB>
<HIREDATE>17-NOV-81</HIREDATE>
<SAL>5000</SAL>
<DEPTNO>10</DEPTNO>
</EMP>
<DEPT>
<DEPTNO>10</DEPTNO>
<DNAME>ACCOUNTING</DNAME>
<LOC>NEW YORK</LOC>
</DEPT>
</ROW>
</ROWSET>

THAT IS WE NEED THE XML OUTPUT AS SEPARATE FOR EACH TABLE.

how it is possible.
FYI ,we are using 9.2 database and w2k os.

Thanks
dinesh
Re: dbms_xmlgen.getxml problem [message #129670 is a reply to message #129522] Tue, 26 July 2005 04:16 Go to previous messageGo to next message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Do anyone have idea of XMLAgg() function.

Pls give some example.

Thanks
Dinesh
Re: dbms_xmlgen.getxml problem [message #130123 is a reply to message #129670] Thu, 28 July 2005 05:21 Go to previous messageGo to next message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Hi all,
here is a query i got to execute after a two 2 days experiment:

SELECT XMLELEMENT("ROOT",
XMLCONCAT(
XMLELEMENT("DEPT",
XMLFOREST(D.DEPTNO,D.DNAME)),
XMLELEMENT("EMP",
XMLFOREST(E.EMPNO,E.ENAME)))) AS XMLDOC
FROM EMP E,DEPT D
WHERE
E.DEPTNO=D.DEPTNO
AND E.JOB='PRESIDENT'
AND D.DEPTNO=10
/

The output is as below:
XMLDOC
------------------------------------------
<ROOT>
<DEPT>
<DEPTNO>10</DEPTNO>
<DNAME>ACCOUNTING</DNAME>
</DEPT>
<EMP>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
</EMP>
</ROOT>

It is giving everything except one important row:-
that is
<?xml version="1.0"?>

So can any one pls give some idea this time how i will add the above line to the above output.

Thanks
Dinesh

[Updated on: Thu, 28 July 2005 05:22]

Report message to a moderator

Re: dbms_xmlgen.getxml problem [message #131004 is a reply to message #129522] Wed, 03 August 2005 16:45 Go to previous messageGo to next message
mchadder
Messages: 224
Registered: May 2005
Location: UK
Senior Member
Hello,

the basic SQL/XML (or SQLX) functions will not give you the XML prolog, you'd have to "add" it manually.

Some of Oracle's proprietary SQLX functions do put it on however,
i.e.
SQL> SELECT SYS_XMLAGG(XMLELEMENT("dummy", dummy)) FROM dual;

SYS_XMLAGG(XMLELEMENT("DUMMY",DUMMY))
-------------------------------------------------------------------------
<?xml version="1.0"?>
<ROWSET>
<dummy>X</dummy></ROWSET>

So you could look into this, probably using XMLFORMAT object to change the name of your root element, i.e.
SQL> SELECT SYS_XMLAGG(XMLELEMENT("dummy", dummy),
  2                       XMLFORMAT('XYZ'))
  3  FROM dual;

SYS_XMLAGG(XMLELEMENT("DUMMY",DUMMY),XMLFORMAT('XYZ'))
----------------------------------------------------------
<?xml version="1.0"?>
<XYZ>
  <dummy>X</dummy>
</XYZ>


Rgds
Re: dbms_xmlgen.getxml problem [message #131335 is a reply to message #131004] Fri, 05 August 2005 07:18 Go to previous message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Thnaks

Ragds
Dinesh
Previous Topic: Dumb Question: My fields are behind my frame
Next Topic: JDeveloper Web Apps without iAS?
Goto Forum:
  


Current Time: Mon Nov 25 10:25:16 CST 2024