Solved

Return all XML elements in separate columns

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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ā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 how to recover a database from a user managed backup

734 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