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 > removing xml tag from result

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-27-11, 11:08
onida onida is offline
Registered User
 
Join Date: Jun 2011
Posts: 3
removing xml tag from result

Hi All,

I am using following query to retrieve Reference Id field value from varchar field (xmldata) containing data in xml format.

select xmlquery('$y/my-record/my-entry[name="Reference Id"]/value/text()'
passing xmlparse(document a.xmldata ) as "y")
from data a where a.dataky = 100200

the query output is as following

<?xml version="1.0" encoding="UTF-16" ?>12731293

How can just get the 12731293 value in result without that xmltag?

Thanks
Onida
Reply With Quote
  #2 (permalink)  
Old 06-27-11, 11:29
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I think you need to use XMLCAST() to convert the XML fragment to another datatype, e.g. VARCHAR or INT.
Reply With Quote
  #3 (permalink)  
Old 06-27-11, 11:37
onida onida is offline
Registered User
 
Join Date: Jun 2011
Posts: 3
removing xml tag from result

wow...thanks a lot

I modified it as -

select xmlcast(xmlquery('$y/my-record/my-entry[name="Reference Id"]/value/text()' passing xmlparse(document a.xmldata ) as "y") AS VARCHAR(30)) from data a where a.dataky = 100200

and it worked.

Regards,
Onida
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