oracle XML to Database表

时间:2017-02-19 12:53:55

标签: sql xml oracle oracle11g

我有这样的XML。我无法将其解析为表格

  <REQMST>
  <ROW>
    <REQ_ID>668 </REQ_ID>    
      <RequestDetails>
      <REQ_DTL_ID>845</REQ_DTL_ID>
      <INTERFACE_REFNUM>1</INTERFACE_REFNUM>
      </RequestDetails>
      <RequestDetails>
      <REQ_DTL_ID>846</REQ_DTL_ID>
      <INTERFACE_REFNUM>2</INTERFACE_REFNUM>
       </RequestDetails>     
    </ROW>
</REQMST>

我正在尝试使用

将其解析为表格
select *  
FROM XMLTABLE('/REQMST/ROW'  
         PASSING   
            xmltype('
           <REQMST>
  <ROW>
    <REQ_ID>668 </REQ_ID>    
      <RequestDetails>
      <REQ_DTL_ID>845</REQ_DTL_ID>
      <INTERFACE_REFNUM>1</INTERFACE_REFNUM>
      </RequestDetails>
      <RequestDetails>
      <REQ_DTL_ID>846</REQ_DTL_ID>
      <INTERFACE_REFNUM>2</INTERFACE_REFNUM>
       </RequestDetails>     
    </ROW>
</REQMST>')
         COLUMNS  
            --describe columns and path to them:  
            REQ_ID  varchar2(20)                 PATH './REQ_ID',
            REQ_DTL_ID  varchar2(20)           PATH './RequestDetails/REQ_DTL_ID',
            INTERFACE_REFNUM varchar2(20)      PATH './RequestDetails/INTERFACE_REFNUM'
     ) xmlt  
;  

我收到错误ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence

如果只有一个RequestDetails

,它会起作用

1 个答案:

答案 0 :(得分:1)

您需要再向下一级以使用与父级相同的技术从int main() { char *Words[NWORDS]; Initialize(Words); Cap(Words); //lowercase to uppercase Print(Words); Free(Words); return 0; } 标记获取详细信息。

使用列名RequestDetails将xml作为xmltype列,然后使用xmltable获取更多详细信息:

试试这个:

xml

产地:

select xmlt.req_id, x.REQ_DTL_ID, x.INTERFACE_REFNUM
FROM XMLTABLE('/REQMST/ROW'  
         PASSING   
            xmltype('
           <REQMST>
                <ROW>
                    <REQ_ID>668 </REQ_ID>    
                    <RequestDetails>
                        <REQ_DTL_ID>845</REQ_DTL_ID>
                        <INTERFACE_REFNUM>1</INTERFACE_REFNUM>
                    </RequestDetails>
                    <RequestDetails>
                        <REQ_DTL_ID>846</REQ_DTL_ID>
                        <INTERFACE_REFNUM>2</INTERFACE_REFNUM>
                    </RequestDetails>     
                </ROW>
            </REQMST>')
         COLUMNS  
            --describe columns and path to them:  
            REQ_ID  varchar2(20)                 PATH 'REQ_ID',
            xml  xmltype         PATH 'RequestDetails'
     ) xmlt,  xmltable('/RequestDetails'
        passing xmlt.xml
        columns
             REQ_DTL_ID  varchar2(20)           PATH 'REQ_DTL_ID',
            INTERFACE_REFNUM varchar2(20)      PATH 'INTERFACE_REFNUM'
     ) x;