在xmltype列和子查询之间预形成集合理论



我正在使用一个遗留应用程序上的oracle db,并且在为它提出特定查询时遇到麻烦。

基本上我有一个表T_Selected,其中有一个数字列(主键)和一个xmltype列。XML的格式为

<countries>
    <country>England</country>
    <country>Ireland</country>
    <country>Scotland</country>
    <country>Wales</country>
</countries>

我还有另一个表,我需要查询和使用结果

select country from T_Countries where language = 'English'

我需要三个查询和它们的否定。

  1. xml∈子查询中的所有国家

  2. 子查询∈xml中的所有国家

  3. xml中的所有国家=所有子查询

最接近的是

select id from 
        T_Selected ts, 
        XMLTABLE('/countries/country'                  
                 passing ts.Values        
                 columns                                     
                 Country  path '//country'
                ) XML
        where XML.country in (select country from T_Countries 
                                                  where language ='English');

这将返回子查询中任何xml国家的id,而不是所有国家的id。

我该怎么做呢?

谢谢你的帮助,

尼尔

  1. SUB的XML子集选择id从(选择id从T_Selected ts,XMLTABLE('/国家/国家'通过ts.Values列国家路径'//国家') XML (XML右外连接(select country from T_Countrieswhere language ='English') SUB) SUB on SUB.country=xml.country在XML。

  2. XML的子子集选择xml.id从(select id fromT_Selected ts,XMLTABLE('/国家/国家'通过ts.Values列国家路径'//国家'XML) q1左外连接(select country from T_Countrieswhere language ='English') SUB on SUB.country=xml。国家)q2 on q2. Country =q1.countryq2。

  3. UNION XML和SUB选择id,国家T_Selected ts,XMLTABLE('/国家/国家'通过ts.Values列国家路径'//国家') XMLUNION ALLselect id, country from t_nationswhere language ='English') SUB on SUB.country=xml.country,

最新更新