Solved

Return all XML elements in separate columns

Posted on 2010-11-22
1
1,075 Views
Last Modified: 2012-05-10
SELECT XMLELEMENT("Cust", XMLFOREST(d.ID,
                                    d.request_id,
                                    d.first_name,
                                    d.last_name)) "Cust Element"
FROM  MyTable d
;

This query returns these 4 fields in XML. If I want to write a query that will get all the columns into the XML without being explicitly named...

This seems to work, but I'm not sure if it is the most elegant solution...

select value (e).GETCLOBVAL() as "xmltype"
FROM TABLE(XMLSequence(Cursor(SELECT * FROM MYTABLE))) e;

Thanks for your advice...
0
Comment
Question by:gswitz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 500 total points
ID: 34194219
I do not see any issue with this.  My table lookup had 2 fields.

select value (e).GETCLOBVAL() as "xmltype"
FROM TABLE(XMLSequence(Cursor(SELECT * FROM lookup))) e;

but you need to note that it is giving a ROW tag for each record if you use this.

 <ROW>
  <CODE>INDEFLY</CODE>
  <CODEWORD>indefinitely</CODEWORD>
 </ROW>

but if you do it with this "SELECT XMLELEMENT("MYOWNTAG", XMLFOREST(code, codeword)) "Cust Element" FROM  lookup", we can get it with the tag name wanted as we wanted.

<MYOWNTAG>
  <CODE>INDEFLY</CODE>
  <CODEWORD>indefinitely</CODEWORD>
</MYOWNTAG>

Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question