?
Solved

Convert Oracle data into XML document

Posted on 2016-11-09
2
Medium Priority
?
101 Views
Last Modified: 2016-11-18
Hi Experts

I need to create a generic stored procedure which will take table name as input parameter and create xml file with below format. Xml file name should be table name and I've never done this before. Could you please help?

I tried few methods in Oracle but the output is not coming as expected.

<?xml version="1.0" encoding="UTF-8"?>
<MessageData>
      <Category>NewSubmission</Category>
      <TimeStamp>2016-07-22T12:11:00Z</TimeStamp>
      <ProdID>1234567890</ProdID>
</MessageData>
<Submission>
      <ReportingPeriod>2015-12-31</ReportingPeriod>      
      <Replacement>
            <MessageRef>12345678902016082313392REP</MessageRef>
            <ReplacedMessageRef>12345678902016072212110NEW</ReplacedMessageRef>
      </Replacement>
</Submission>
<Person>
      <FirstName>a</FirstName>
      <LastName>a</LastName>
      <Address>
      <City>a</City>
      <CountryCode>AF</CountryCode>
      <ResCountryCode>AF</ResCountryCode>
      </Address>
</Person>
0
Comment
Question by:Ram Karthik
2 Comments
 
LVL 32

Expert Comment

by:awking00
ID: 41880533
Can you show the table structures and the data that would be used to produce your example xml file?
0
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 41880551
It looks like that data would come from different tables.  Do you have a one-to-many relation in there?

You sample XML you posted is also incorrect.  There is no root node.

Generating the XML is pretty easy.  I would suggest looking at the XML functions in SQL.

Here is the MessageData part of your XML:
/*
drop table tab1 purge;
create table tab1(category varchar2(20), time_stamp timestamp, prodid number);

insert into tab1 values('NewSubmission',to_timestamp('2016-07-22 12:11:00','YYYY-MM-DD HH24:MI:SS'),1234667890);
commit;
*/

select xmlelement("MessageData",
	xmlforest(
		category as "Category",
		to_char(time_stamp,'YYYY-MM-DD"T"HH24:MI:SS"Z"') as "TimeStamp",
		prodid as "ProdId"
	)
)
from tab1
/

Open in new window


If you can provide more detail about your tables, we can probably provide an expanded example.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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 syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

830 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