Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XML Forest,XML Concat

Posted on 2009-07-14
17
Medium Priority
?
1,681 Views
Last Modified: 2012-05-07
Hi,

I have a wo function in oracle which returns XML type.

Sample XML From First Function
<customer>
<Fname>testFname</Fname>
<Lname>testLname</Lname>
</customer>

Sample XML From Second Function
<PostalAddress>
<address1>testaddress1</Fname>
<address2>testaddress2</Lname>
</PostalAddress>

I need to add postal address tag under customer tag.

Oupt Put

<Customers>
<customer>
<Fname>testFname</Fname>
<Lname>testLname</Lname>
<PostalAddress>
<address1>testaddress1</Fname>
<address2>testaddress2</Lname>
</PostalAddress>
</customer>
</Customers>

how to achieve this ?

Regards,
Chandan N




--Presenly i am using the below code
--but not able to generate the required XMl structure
SELECT  XMLElement("Customers",function1(),Function2()) INTO xml_temp FROM dual;
please find the attachment for the present code

Open in new window

query.txt
0
Comment
Question by:Chandan_Gowda
  • 4
  • 3
  • 3
10 Comments
 
LVL 48

Expert Comment

by:schwertner
ID: 24849170
Curious what will give you
SELECT  XMLElement("Customers",function1() || Function2()) INTO xml_temp FROM dual;
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 24850001
you don't want to use xmelement or any of the xml aggregation functions,
you are simply inserting nodes within other nodes.

use INSERTCHILDXML to do that...


select INSERTCHILDXML(
           xmltype('<Customers></Customers>'),
           '/Customers',
           'customer',
           INSERTCHILDXML(function1, '/customer', 'PostalAddress', function2)
       ) from dual
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24852430
Thanks!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Author Comment

by:Chandan_Gowda
ID: 24877023
Finally by some R & D,made this working
find the attachment for  solution

select insertChildXML(xml_cust, '/Customer', 'PostalAddress', xml_postal, null) into xml_temp 
from dual;

Open in new window

0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24878264
that appears to be what I posted except you have removed the outer <Customers>  node
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24878355
Thanks!
0
 
LVL 7

Author Comment

by:Chandan_Gowda
ID: 24921849
i resolved it myself....Please refund my points back
0
 
LVL 7

Author Comment

by:Chandan_Gowda
ID: 24921885
The core part is to get the nodes;sdstuber solution didnt had that part correct.That is the main element of the solution.How can this comment be considered as a correct one if it is not working,I had to do lot of work around to get the solution,Only the syntax is correct,But the logic is not correct,
Before accepcting the solution forcibly,The solution has to be checked for its logic.
Please refund my points back.
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24924637
I will suggest to delete the whole question.

Also please regard the will of the Asker.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24931088
Chandan_Gowda,

Sorry, I was gone on vacation for several days and just got back to see the comments.

I didn't have the your functions to work with so I wrote my own that returned the xml presented in the original question (except I corrected the address1 and address2 closing tags)
The post I made above is exactly what I tested with and it returned exactly the xml you requested.

The query I posted returns the requested xml, if this does not work, please post what did not work about it.
I've attached the functions from my test case.

<Customers>
  <customer>
    <Fname>testFname</Fname>
    <Lname>testLname</Lname>
    <PostalAddress>
      <address1>testaddress1</address1>
      <address2>testaddress2</address2>
    </PostalAddress>
  </customer>
</Customers>

 
create or replace function function1 return xmltype
is
begin
  return xmltype('<customer>
<Fname>testFname</Fname>
<Lname>testLname</Lname>
</customer>');
end;
 
--  Note, address1 and address2  closing tags have been corrected, from the original question's sample data.
create or replace function function2 return xmltype
is
begin
  return xmltype('<PostalAddress>
<address1>testaddress1</address1>    
<address2>testaddress2</address2>
</PostalAddress>');
end;

Open in new window

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to recover a database from a user managed backup
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

824 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