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 > How to read XML string in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-09-09, 23:40
sj.j sj.j is offline
Registered User
 
Join Date: Mar 2009
Posts: 4
How to read XML string in DB2

Hi ,

I am new to DB2,i want to try the below sql stored procedure in DB2.

In sql,i am passing xml as text and inserting the needed element node values to temporary table like below.

For ex... xml string like

<Record>
<Employee>
<EMPNUM>
12345
</EMPNUM>
<EMPNAME>
ABC
</EMPNAME>
</Employee>
<Employee>
<EMPNUM>
67891
</EMPNUM>
<EMPNAME>
PQR
</EMPNAME>
</Employee>
</Record>

create procedure Getxmldata
(
//xml string
@xmlText ntext
)
AS

BEGIN

DECLARE @Doc int

//tempaoray table
DECLARE @temp table(
emp_num int,
name varchar(30)
);

EXEC sp_xml_preparedocument @Doc OUTPUT, @xmlText


INSERT INTO @temp

SELECT EMPNUM,EMPNAME FROM OPENXML

(@Doc, 'Record/Employee',2) WITH

(EMPNUM int,EMPNAME EMPNAME varchar(30))

SELECT * FROM @temp;

END

Expexted result should display all the employee records. for ex
-------------------
emp_num emp_name
12345 ABC
67891 PQR


Thanks in advance for your help
sj
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