ramlicious Blogs by Tina & Prabhu

February 20, 2015

Extracting XML Element and Attribute values in Oracle

Filed under: Oracle,Programming — Prabhuram @ 12:03 pm

Let’s assume that you have a XML (xmltype) table column.

<?xml version="1.0" encoding="UTF-8"?>
     <data k="a1">
        <value>row 1</value>
     <data k="a2">
       <value>row 2</value>

One way to easily extract data is given below

Select Xmltype(t.Col).Extract('//form/data[@k="a1"]/value/text()').Getstringval()  a1
From Mytable t

and reading an attribute value can be like this:

Select Xmltype(t.Col).Extract('//form/data[1]/@k').Getstringval()  k
From Mytable t

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

Powered by WordPress