Solved

Convert Oracle data into XML document

Posted on 2016-11-09
2
39 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 31

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 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now