Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Looping and querying data from XML clob

Author  Topic 

baggettms01
Starting Member

2 Posts

Posted - 2013-10-05 : 13:11:01
Hello,

Using a code snippet borrowed from a co-worker, I have put together a query that, among other things, pulls a list value out of an xml clob field and displays it in the query results. My query as it stands right now is below, followed by a snippet from the xml clob that I am pulling from.
select * from 
(Select Wtr_Service_Tag, Wtr_Tran_Origin, Wtr_Send_Date, Wtr_Receive_Date,
to_char(substr(wtr_req_xml,instr(substr(wtr_req_xml,1,8000),'SID')+8,12)) Asset_Tag
from ws_transactions
Where Wtr_Service_Tag In ('20458749610')
And Wtr_Req_Xml Like ('%CSM%')
Order By Wtr_Receive_Date Desc)
where rownum = 1;

<ASSETTAGDATA>
<LIST NAME="AssetTag">
<VALUE SID="1">186037</VALUE>
<VALUE SID="2">186038</VALUE>
</LIST>


This query is only able to pull the first value in the list.

I have two questions that I am hoping I can get some help with.
    [1]How can I edit this query to pull all of the list items when there are more than 1? I have another field, in a separate table, that I can pull from to get that number.

    [2]This one may be more complex. As currently written, the query pulls a fixed number of characters from the xml clob and either returns not enough data, or too much because the values I need to pull could be of varying lengths. I have no way to query what those lengths might be.


Thank you in advance for your help. I hope I have provided enough information. I have I have not, I will gladly respond back with anything else that is needed.

-Matt

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-06 : 08:31:07
Are you using Microsoft SQL Server? If you are not, you might want to post the question in a forum specific to your DBMS provider. This forum is for Microsoft SQL Server. I was going to write a query for you, but then I realized that the "CROSS APPLY" operator that I would be using is not available in some of the other DBMS systems.
Go to Top of Page

baggettms01
Starting Member

2 Posts

Posted - 2013-10-06 : 13:13:37
Thanks James.

I somehow missed that this forum was that specific. We use and oracle database and SQL developer to do our querying.

Sorry the for the intrusion.
Go to Top of Page
   

- Advertisement -