Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Return all XML elements in separate columns

Posted on 2010-11-22
1
Medium Priority
?
1,078 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

722 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