【问题标题】:Could Not Get Columns with XMLTABLE in Oracle PL/SQL在 Oracle PL/SQL 中无法使用 XMLTABLE 获取列
【发布时间】:2017-08-11 06:11:25
【问题描述】:

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

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

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

如果有人能帮助理解从这个XML 中提取值的问题出在哪里,那就太好了。谢谢你的时间 :) 代码写在 Oracle PL/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;

【问题讨论】:

    标签: oracle plsql xmltable


    【解决方案1】:

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

    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" 更改了默认的命名空间。

    【讨论】:

      猜你喜欢
      • 2020-03-10
      • 2016-02-28
      • 2018-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-28
      • 2021-09-11
      相关资源
      最近更新 更多