prabu
prabu

Reputation: 1277

Query xml using extract over CLOB column in Oracle

We are storing the xml in oracle database. The column type is CLOB. I could fetch data from the xml tag with below query. When i execute the query i am getting null.

XML in the column:

<input xmlns="http://google.com/testsystem" 
       xmlns:testsystem="http://test.com/testSystem"          
       xmlns:tns="http://google.com/testService/">
      <ProcessData>      
        <reviewYear>2014-2015</reviewYear>
      </ProcessData>
    </input>

Table name : test_table
Column name : input_xml
Column type : CLOB

Query:

select extract(xmltype(input_xml),'//reviewYear/text()').getStringVal() as data 
from test_table 
where id = 1;

Result:

DATA                  
------------------------------------

Upvotes: 0

Views: 2821

Answers (1)

user3278460
user3278460

Reputation:

you need to specify namespace, please, try next query

select extract(xmltype('<input xmlns="http://google.com/testsystem" 
       xmlns:testsystem="http://test.com/testSystem"          
       xmlns:tns="http://google.com/testService/">
      <ProcessData>      
        <reviewYear>2014-2015</reviewYear>
      </ProcessData>
    </input>'),'/input/ProcessData/reviewYear/text()', 'xmlns="http://google.com/testsystem" xmlns:testsystem="http://test.com/testSystem" xmlns:tns="http://google.com/testService/"').getStringVal() as data 
from dual

UPD.

for update try

select updatexml(xmltype('<input xmlns="http://google.com/testsystem" 
       xmlns:testsystem="http://test.com/testSystem"          
       xmlns:tns="http://google.com/testService/">
       <ProcessData>      
         <reviewYear>2014-2015</reviewYear>
       </ProcessData>
    </input>'), '/input/ProcessData/reviewYear/text()', '2013-2014', 
    'xmlns="http://google.com/testsystem" xmlns:testsystem="http://test.com/testSystem" xmlns:tns="http://google.com/testService/"').getclobval() as data 
from dual

Upvotes: 1

Related Questions