开发者

How to select a particular Node name in XML using Oracle SQL query?

开发者 https://www.devze.com 2023-01-07 16:36 出处:网络
I need to select a particular Node name in the XML file using sql string? Sample XML structure <Root>

I need to select a particular Node name in the XML file using sql string?

Sample XML structure

  <Root>
   <Body>
      <Car>  // This can be "Bike", "ship", "Train"... ect
       <name value="figo"/>
      </Car>
   </Body>
 </Root>

I want to run a query which which will fetch w开发者_StackOverflow中文版hat Node name is present in XML "car" or "Train" or "Bike".. etc.

Select * from TableA where.....?

TableA has column "Message" of type CLOB which stores the XML.

-Praveen


You can cast the CLOB type to XMLTYPE (or consider using an XMLTYPE column on the table). When dealing with XMLTYPEs you can then run XPATHs e.g:

SELECT extractvalue(xml_col, '/*/Body/*/name/@value')
FROM TableA

or extract for xml fragments.

EDIT: changed the 'Car' to * in XPath, having re-read the question.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号