Solved

Return all XML elements in separate columns

Posted on 2010-11-22
1
1,069 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now