在Oracle中具有命名空间的xmlexists

时间:2016-11-07 14:29:21

标签: sql oracle xmltable oracle-xml-db

我在解决如何将名称空间集成到具有xmlexists的where子句时遇到了问题。查询如下:

SELECT sing_d1.sing_info_text1, sing_d1.sing_info_text2
FROM XMLTABLE(
      xmlnamespaces (
                       'http://www.abccompany.com/Canonical' AS "abc",
                       'http://abccompany.com/PmtInfo' AS "pmt",
                       'http://abccompany.com/CommonTypes' AS "cmn",
                       'http://www.w3.org/2001/XMLSchema-instance' AS "xsi"),
                   '/abc:abc/abc:Pmt/pmt:Payments/pmt:PayInfo/pmt:Single/pmt:SingAddInfo'
                    PASSING payXml
                    COLUMNS 
                                  sing_info_type VARCHAR2(4000)
                                  PATH 'cmn:AddInfoCmpType',
                                  sing_info_text1 VARCHAR2(4000)
                                  PATH 'cmn:AddInfoCmpText[1]',
                                  sing_info_text2 VARCHAR2(4000)
                                  PATH 'cmn:AddInfoCmpText[2]'
              )sing_d1
WHERE 
                       XMLExists(

                   '/abc:abc/abc:Pmt/pmt:Payments/pmt:PayInfo/pmt:Single/pmt:SingAddInfo[AddInfoCmpType = "IATCode"]'

);

任何线索都会受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

   XMLExists('   declare namespace xsi="http://www.w3.org/2001/XMLSchema-instance";
                declare namespace abc="http://www.abccompany.com/Canonical";
                        declare namespace pmt="http://abccompany.com/PmtInfo";
                        declare namespace cmn="http://abccompany.com/CommonTypes";
                          /abc:abc/abc:Pmt/pmt:Payments/pmt:PayInfo/pmt:Single/pmt:SingAddInfo[AddInfoCmpType = "IATCode"]' passing payXml)

对于xmlns(默认),请使用declare default element namespace "http.url.url"。对于其他declare namespace xyz