我们将xml存储在oracle数据库中。列类型是CLOB。 我可以使用以下查询从xml标记中获取数据。当我执行查询时,我变为空。
列中的XML:
<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
查询:
select extract(xmltype(input_xml),'//reviewYear/text()').getStringVal() as data
from test_table
where id = 1;
结果:
DATA
------------------------------------
答案 0 :(得分: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