无法在 Oracle PL/SQL 中使用 XMLTABLE 获取列

Could Not Get Columns with XMLTABLE in Oracle PL/SQL

我尝试从 XML 文件的列中获取值。

我收到 XML 文件,在我的函数中它被分配给 c_xml 但出于这个问题的目的,在下面的代码中用变量 c_xml 表示。

问题是我没有在 DBMS_OUTPUT 中打印任何内容。 PUT_LINE,所以我无法从 XML 文件中获取任何值,我无法继续开发。

如果有人能帮助理解从这个 XML 中提取值的问题在哪里,那就太好了。谢谢你的时间 :) 代码写在OraclePL/SQL上,如下:

    DECLARE
    c_xml     xmltype;
    BEGIN
    c_xml := 
    xmltype
    ('<?xml version=''1.0'' encoding=''utf-8''?>
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <env:Header/>
   <env:Body>
   <srvc:returnActStateByEgnResponse xmlns="http://curr_state_egn/CURR_STATE_EGNService" xmlns:srvc="http://curr_state_egn/CURR_STATE_EGNServiceService">
  <srvc:result>
    <consents_tblType>
      <item>
        <req_id>112</req_id>
        <purpose_code>CC0100</purpose_code>
        <consent_state>0</consent_state>
      </item>
      <item>
        <req_id>112</req_id>
        <purpose_code>CC0200</purpose_code>
        <consent_state>1</consent_state>
      </item>
      <item>
        <req_id>112</req_id>
        <purpose_code>CC0300</purpose_code>
        <consent_state>0</consent_state>
      </item>
    </consents_tblType>
  </srvc:result>
</srvc:returnActStateByEgnResponse>
</env:Body>
 </env:Envelope>');

  FOR consents_tblTypes IN
    ( SELECT 
          p_req_id             
          , p_purpose_code    
          , p_consent_state    
      FROM  xmltable(
                XMLNamespaces(
                                  'http://schemas.xmlsoap.org/soap/envelope/'               AS "env"
                                --, 'http://www.w3.org/2001/XMLSchema-instance'               AS "xsi"
                                , 'http://curr_state_egn/CURR_STATE_EGNServiceService'      AS "srvc"
                                ), 
                                  '/env:Envelope/env:Body/srvc:returnActStateByEgnResponse/srvc:result/consents_tblType/item'
                            PASSING  c_xml 
                     COLUMNS                         
                      p_req_id           NUMBER  PATH 'req_id' --/text()
                      , p_purpose_code     VARCHAR2(20) PATH 'purpose_code' --/text()
                      , p_consent_state    NUMBER PATH 'consent_state' --/text()
                )
    )
    LOOP         
        DBMS_OUTPUT.put_line('p_req_id = ' || to_char(consents_tblTypes.p_req_id))  ;
        DBMS_OUTPUT.put_line('p_purpose_code = ' || consents_tblTypes.p_purpose_code)  ;
        DBMS_OUTPUT.put_line('p_consent_state = ' || to_char(consents_tblTypes.p_consent_state))  ;
    END LOOP;  
 end;

默认命名空间必须包含在声明中。

XMLNamespaces('http://schemas.xmlsoap.org/soap/envelope/' AS "env"                             
            , 'http://curr_state_egn/CURR_STATE_EGNServiceService' AS "srvc"
            , default 'http://curr_state_egn/CURR_STATE_EGNService')

此语句xmlns="http://curr_state_egn/CURR_STATE_EGNService" 更改默认命名空间。