我必须从xml文件中提取数据并将其插入表

时间:2016-05-30 05:53:01

标签: xml plsql xml-parsing

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:rocs.001.001.06">
<pokus>
 <RchEntry>
      <PstlAdr>
      <Ctry>IT</Ctry>
     <AdrLine>VIA SARDEGNA, 12</AdrLine>
      <AdrLine>00019TIVOLI RM</AdrLine>
      </PstlAdr>
    </RchEntry>
    <RchEntry>
     <PstlAdr>
      <Ctry>IT1</Ctry>
      <AdrLine>VIA SARDEGNA1, 12</AdrLine>
      <AdrLine>00019TIVOLI11 RM</AdrLine>
      </PstlAdr>
    </RchEntry>
    </pokus>
</Document>

这是我需要提取值的xml文件。每个RchEntry都被视为一行。如何使用plsql提取AdrLine标记的值?

1 个答案:

答案 0 :(得分:0)

WITH t AS
  (SELECT column_value
  FROM TABLE(xmlsequence(extract(xmltype('<Document>
<rocs.001.001.06> 
<RchEntry>      
<PstlAdr>      
<Ctry>IT</Ctry>     
<AdrLine>VIA SARDEGNA, 12</AdrLine>      
<AdrLine>00019TIVOLI RM</AdrLine>      
</PstlAdr>    
</RchEntry>    
<RchEntry>     
<PstlAdr>      
<Ctry>IT1</Ctry>      
<AdrLine>VIA SARDEGNA1, 12</AdrLine>      
<AdrLine>00019TIVOLI11 RM</AdrLine>      
</PstlAdr>    
</RchEntry>    
</rocs.001.001.06>
</Document>'),'/Document/rocs.001.001.06/*')))
  )
SELECT t1.*
FROM t,
  xmltable('/RchEntry' passing t.column_value columns Ctry VARCHAR2(100) path '/RchEntry/PstlAdr/Ctry', AdrLine1 VARCHAR2(100) path '/RchEntry/PstlAdr/AdrLine[1]', AdrLine2 VARCHAR2(100) path '/RchEntry/PstlAdr/AdrLine[2]') t1;