Solved

Return all XML elements in separate columns

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
ORA-00923: FROM keyword not found where expected 3 80
Repeat query 13 62
How to Gracefuly recover in Racle stored procedure 1 34
return value in based on value passed 6 28
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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
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…

821 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