首页 文章

使用Oracle中的CLOB列提取查询xml

提问于
浏览
0

我们将xml存储在oracle数据库中 . 列类型是CLOB . 我可以使用以下查询从xml标记中获取数据 . 当我执行查询时,我得到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>

表名:test_table列名:input_xml列类型:CLOB

Query:

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

Result:

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

1 回答

  • 1

    你需要指定命名空间,请尝试下一个查询

    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 .

    更新尝试

    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
    

相关问题