If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Returning XML from Stored Procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-28-04, 14:05
scottb scottb is offline
Registered User
 
Join Date: Oct 2003
Posts: 60
Cool Returning XML from Stored Procedure

I am not very familiar with db2.

I know in SQL server if I had 2 tables and wanted to return XML, I would use Tag & Parents followed by XML EXPLICT. How can I accomplish this in db2..

Example

Table1 (
ID int,
NAME varchar(100)
)
table2 (
ID int,
FIRST_NAME varchar(100)
)

query output...

<root>
<TABLE1 ID="1" NAME = "SCOTT GROUP">
<TABLE2 ID ="1" FIRST_NAME = "SCOTT"/>
</TABLE1>
</root>

How can I accomplish this?
Reply With Quote
  #2 (permalink)  
Old 05-28-04, 15:28
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by scottb
I am not very familiar with db2.

I know in SQL server if I had 2 tables and wanted to return XML, I would use Tag & Parents followed by XML EXPLICT. How can I accomplish this in db2..

Example

Table1 (
ID int,
NAME varchar(100)
)
table2 (
ID int,
FIRST_NAME varchar(100)
)

query output...

<root>
<TABLE1 ID="1" NAME = "SCOTT GROUP">
<TABLE2 ID ="1" FIRST_NAME = "SCOTT"/>
</TABLE1>
</root>

How can I accomplish this?
Look at REC2XML, I've not used it but I believe it's what you're looking for.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 05-31-04, 11:54
scottb scottb is offline
Registered User
 
Join Date: Oct 2003
Posts: 60
sp

How Can I change this into a stored procedure?


select XML2CLOB(
XMLELEMENT(NAME "CLIENT",
XMLATTRIBUTES(A.ID as "CLIENT_ID", A.NAME as "CLIENT_NAME"),
XMLAGG(
XMLELEMENT( NAME "EMAIL",
XMLATTRIBUTES( B.ADD as "EMAIL_ADDRESS")
)
)
))
FROM CLIENT A, EMAIL B
where A.ID = B.ID
group by A.ID, A.NAME
Reply With Quote
  #4 (permalink)  
Old 05-31-04, 12:25
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by scottb
How Can I change this into a stored procedure?


select XML2CLOB(
XMLELEMENT(NAME "CLIENT",
XMLATTRIBUTES(A.ID as "CLIENT_ID", A.NAME as "CLIENT_NAME"),
XMLAGG(
XMLELEMENT( NAME "EMAIL",
XMLATTRIBUTES( B.ADD as "EMAIL_ADDRESS")
)
)
))
FROM CLIENT A, EMAIL B
where A.ID = B.ID
group by A.ID, A.NAME
Same as usual, this returns it as a result set:

CREATE PROCEDURE GET_CLIENTINFO ()
RESULT SETS 1
LANGUAGE SQL
BEGIN

DECLARE C2 CURSOR WITH RETURN FOR
select XML2CLOB(
XMLELEMENT(NAME "CLIENT",
XMLATTRIBUTES(A.ID as "CLIENT_ID", A.NAME as "CLIENT_NAME"),
XMLAGG(
XMLELEMENT( NAME "EMAIL",
XMLATTRIBUTES( B.ADD as "EMAIL_ADDRESS")
)
)
))
FROM CLIENT A, EMAIL B
where A.ID = B.ID
group by A.ID, A.NAME
;

OPEN C2;
end
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #5 (permalink)  
Old 06-08-04, 09:46
scottb scottb is offline
Registered User
 
Join Date: Oct 2003
Posts: 60
Thanks...

How can you sending in parameters in XML format?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On