Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Convert Oracle data into XML document

Posted on 2016-11-09
2
Medium Priority
?
95 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
[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
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 77

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

636 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