Solved

XML Forest,XML Concat

Posted on 2009-07-14
17
1,669 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
[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
  • 4
  • 3
  • 3
17 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 500 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
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to recover a database from a user managed backup
Suggested Courses

630 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