XML 在 Oracle 上解析

XML parsing on Oracle

我有 XML 这样的数据:

<?xml version="1.0"?>
<CommunityResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.rigidcloud.com/">
<Situation>true</Situation>
<Information>Success Result</Information>
<Wrongs/>
</CommunityResult >

我尝试了这个 SQL 代码,但我无法得到结果:

select (select x.DURUM from table1, xmltable(
                        xmlnamespaces ('http://www.w3.org/2001/XMLSchema-instance' as "a",
                        'http://www.w3.org/2001/XMLSchema' as "b" ,
                       'http://www.rigidcloud.com/'  as "c " ,
                        default ''), 
                        '/a:/b:CommunityResult /c:Information'
                        passing XMLType(column1) 
                        columns "DURUM" VARCHAR2(1000) path 'Durum') x 
                where record_code = '11102006')               
                from dual;

Returns 全部为空。

请尝试以下解决方案。

PL/SQL

with tbl as
(
    select
        XMLType(
        '<CommunityResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 xmlns="http://www.rigidcloud.com/">
    <Situation>true</Situation>
    <Information>Success Result</Information>
    <Wrongs/>
</CommunityResult>'
        ) xmldata
    from dual
)
select Situation, Information
from   tbl,
       xmltable(
         xmlnamespaces('http://www.rigidcloud.com/' as "ns1"),
         '/ns1:CommunityResult'
         PASSING tbl.xmldata 
         COLUMNS Situation VARCHAR2(10) PATH 'ns1:Situation',
               Information VARCHAR2(50) PATH 'ns1:Information');

输出

+------------+----------------+
| SITUATION  |  INFORMATION   |
+------------+----------------+
| true       | Success Result |
+------------+----------------+