0

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                  
------------------------------------

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

How to update the tag if we have namespace? can you help with a sampl query? thanks in advance.
what tag do you want to change? tag or its value?
For example, i need to update <reviewYear>2014-2015</reviewYear> to <reviewYear>2013-2014</reviewYear>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.