从XML中提取数据并将其加载到表中

时间:2014-01-01 06:24:49

标签: sql oracle plsql xml-parsing oracle11g

如何从XML中获取数据(加载到Oracle表中)并创建一个表来加载提取的数据。

我正在尝试创建一个表,列如下,下面提到的列是xml中的标记

ID,  Provider_Name,  Index, Provider_ID_description, Provider_ID
 1,  Provider_P107,  1,     GNRCN,                   GNRCN
 1,  Provider_P107,  2,     INDF1,                   INDF1
 2,  Provider_EGUT,  1,     EGUT,                    EGUT

XML是:

    <?xml version="1.0" encoding="us-ascii"?>
<AuxiliaryType auxiliaryTypeId="1617309" base="Value list" hasImplementation="false" isShared="true" masteredIn="false" name="ID list" type="String">
    <AuxiliaryObject id="1" name="Provider_P107">
        <Row>
            <Index>1</Index>
            <Provider_ID_description>GNRCN</Provider_ID_description>
            <Provider_ID>GNRCN</Provider_ID>
        </Row>
        <Row>
            <Index>2</Index>
            <Provider_ID_description>INDF1</Provider_ID_description>
            <Provider_ID>INDF1</Provider_ID>
        </Row>
    </AuxiliaryObject>
    <AuxiliaryObject id="2" name="Provider_EGUT">
        <Row>
            <Index>1</Index>
            <Provider_ID_description>EGUT</Provider_ID_description>
            <Provider_ID>EGUT</Provider_ID>
        </Row>
    </AuxiliaryObject>
</AuxiliaryType>

我尝试过使用以下查询:

SELECT w.ID,
       p.Name,
       s.Index,
       q.P_Desc,
       q.P_ID
from  traptabclob t
left join xmltable ('/AuxiliaryType/AuxiliaryObject/'
                   passing t.testclob
                   columns ID      XmlType path '/AuxiliaryType/AuxiliaryObject/@id',
                   columns Name    XmlType path '/AuxiliaryType/AuxiliaryObject/@name',
                   columns Index   XmlType path 'Row/Index',
                   columns P_Desc  varchar2(201) path 'Row/Provider_ID_description',
                   columns P_ID    varchar2(21) path 'Row/Provider_ID',
                   ) q
on (1=1)
  left join xmltable('/Index'
                      passing q.Index
                      columns Index number path '.') s
    on (1=1)
  left join  xmltable('/AuxiliaryType/AuxiliaryObject/'
                        passing q.ID
                        columns ID number path '.') w
    on (1=1)
  left join   xmltable('/AuxiliaryType/AuxiliaryObject/'
                        passing q.Name
                        columns Name varchar2(21) path '.') p
    on (1=1);

我试过这个http://www.sqlfiddle.com/#!4/1a672/7/0。这是我可以获取更多数据http://www.sqlfiddle.com/#!4/1a672/8/0的新内容,但我仍在苦苦挣扎。当我有多个索引或行时,这不起作用。怎么做如果我有AuxiliaryObject id的计数?

0 个答案:

没有答案