优化Oracle XML查询

时间:2016-07-18 08:54:22

标签: sql xml oracle

我有一个Oracle类型XMLType的XML行,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<Agregat xmlns:DGE="urn:ops:rncps:dge" xmlns:SNGI="urn:cnav:sngi">
<DGE:Document>
  <DGE:Donnee>
     <ns4:SignalementRetraite xmlns:ns4="http://dge.isic.cnav/Signalement">
        <Emetteur>
           <CdOrgGestionnaire>0006</CdOrgGestionnaire>
        </Emetteur>
        <Demandeur>
           <NumAsrDem>2530197302056</NumAsrDem>
           <CodeCertifECL>0</CodeCertifECL>
           <NmAsrDem>PRUDENT</NmAsrDem>
           <PrnAsrDem>MUGUETTE</PrnAsrDem>
           <DtNaiAss>19530120</DtNaiAss>
           <DtCertNum>1988-01-01+01:00</DtCertNum>
        </Demandeur>
        <DemandeDP>
           <CodeModeDeLiquidation>01</CodeModeDeLiquidation>
        </DemandeDP>
        <AdresseCommunication>
           <AdrTyp>A</AdrTyp>
           <AdrCivil>Mme</AdrCivil>
           <AdrRaisSoc />
           <AdrNmComm>PRUDENT</AdrNmComm>
           <AdrPrnComm>MUGUETTE</AdrPrnComm>
           <AdrNumVoie>119 RESIDENCE DES ALIZES</AdrNumVoie>
           <AdrCdPostal>97354</AdrCdPostal>
           <AdrCdCommune>97309</AdrCdCommune>
           <AdrLocBurDistributeur>REMIRE MONTJOLY</AdrLocBurDistributeur>
           <AdrPays />
           <AdrCdPays>FR</AdrCdPays>
        </AdresseCommunication>
        <PremiereManifestation>
           <DtPremiereManifestation>2008-12-18+01:00</DtPremiereManifestation>
           <CodeCanalPremiereManifestation>02</CodeCanalPremiereManifestation>
           <DtDelivCerfa>2008-12-18+01:00</DtDelivCerfa>
           <CodeCanalDelivCerfa>02</CodeCanalDelivCerfa>
           <CodeRegimeCompetentPresume>2294</CodeRegimeCompetentPresume>
        </PremiereManifestation>
     </ns4:SignalementRetraite>
  </DGE:Donnee>
</DGE:Document>
</Agregat>

以下查询需要花费太多时间来执行,您对如何优化它有任何想法吗?

SELECT DISTINCT RPAD(NVL(extractValue(Emetteur.column_value, '//Emetteur//CdOrgGestionnaire'),' '),4,' ')               AS CdOrgGestionnaire,
    RPAD(NVL(extractValue(Demandeur.column_value, '//Demandeur//NumAsrDem'),' '),13,' ')                                   AS NumAsrDem, 
    RPAD(NVL(extractValue(Demandeur.column_value, '//Demandeur//CodeCertifECL'),' '),1,' ')                               AS CodeCertifECL,
    RPAD(NVL(extractValue(Demandeur.column_value, '//Demandeur//NmAsrDem'),' '),63,' ')                                    AS NmAsrDem, 
    RPAD(NVL(extractValue(Demandeur.column_value, '//Demandeur//PrnAsrDem'),' '),50,' ')                                   AS PrnAsrDem, 
    RPAD(NVL(extractValue(Demandeur.column_value, '//Demandeur//DtNaiAss'),' '),10,' ')                                    AS DtNaiAss, 
    RPAD(NVL(extractValue(Demandeur.column_value, '//Demandeur//NmMarAssDem'),' '),63,' ')                                 AS NmMarAssDem, 
    RPAD(NVL(extractValue(Demandeur.column_value, '//Demandeur//DtCertNum'),' '),10,' ')                                   AS DtCertNum, 
    RPAD(NVL(extractValue(DemandeDP.column_value, '//DemandeDP//IdentifiantDemande'),' '),16,' ')                          AS IdentifiantDemande,
    RPAD(NVL(extractValue(DemandeDP.column_value, '//DemandeDP//CodeModeDeLiquidation'),' '),2,' ')                       AS CodeModeDeLiquidation ,
    RPAD(NVL(extractValue(PremiereManifestation.column_value, '//PremiereManifestation//DtPremiereManifestation'),' '),10,' ')                       AS DtPremiereManifestation, 
    RPAD(NVL(extractValue(PremiereManifestation.column_value, '//PremiereManifestation//CodeCanalPremiereManifestation'),' '),2,' ')                       AS CdCanalPremiereManif, 
    RPAD(NVL(extractValue(PremiereManifestation.column_value, '//PremiereManifestation//DtDelivCerfa'),' '),10,' ')                       AS DtDelivCerfa, 
    RPAD(NVL(extractValue(PremiereManifestation.column_value, '//PremiereManifestation//CodeCanalDelivCerfa'),' '),2,' ')                       AS CodeCanalDelivCerfa, 
    RPAD(NVL(extractValue(PremiereManifestation.column_value, '//PremiereManifestation//CodeRegimeCompetentPresume'),' '),4,' ')                       AS CodeRegimeCompetentPresume 

    FROM COMMUN.SESSION_TEMP_XML s , TABLE( XMLSequence( extract( s.xml_data , '//Emetteur' , 'xmlns:ns4="http://dge.isic.cnav/Signalement"' ) ) ) Emetteur,
    TABLE( XMLSequence( extract( s.xml_data , '//Demandeur' , 'xmlns:ns4="http://dge.isic.cnav/Signalement"' ) ) ) Demandeur,
    TABLE( XMLSequence( extract( s.xml_data , '//DemandeDP' , 'xmlns:ns4="http://dge.isic.cnav/Signalement"' ) ) ) DemandeDP,
    TABLE( XMLSequence( extract( s.xml_data , '//PremiereManifestation' , 'xmlns:ns4="http://dge.isic.cnav/Signalement"' ) ) ) PremiereManifestation

所选列的数量是否会降低性能?

知道如何改进吗?

问候。

1 个答案:

答案 0 :(得分:0)

我像这样重写了这个查询并且它可以工作,不需要连接。

SELECT DISTINCT RPAD(NVL(extractValue(s.xml_data, '//Emetteur//CdOrgGestionnaire'),' '),4,' ')               AS CdOrgGestionnaire, 
    RPAD(NVL(extractValue(s.xml_data, '//Demandeur//NumAsrDem'),' '),13,' ')                                   AS NumAsrDem, 
    RPAD(NVL(extractValue(s.xml_data, '//Demandeur//CodeCertifECL'),' '),1,' ')                               AS CodeCertifECL, 
    RPAD(NVL(extractValue(s.xml_data, '//Demandeur//NmAsrDem'),' '),63,' ')                                    AS NmAsrDem, 
    RPAD(NVL(extractValue(s.xml_data, '//Demandeur//PrnAsrDem'),' '),50,' ')                                   AS PrnAsrDem, 
    RPAD(NVL(extractValue(s.xml_data, '//Demandeur//DtNaiAss'),' '),10,' ')                                    AS DtNaiAss, 
    RPAD(NVL(extractValue(s.xml_data, '//Demandeur//NmMarAssDem'),' '),63,' ')                                 AS NmMarAssDem, 
    RPAD(NVL(extractValue(s.xml_data, '//Demandeur//DtCertNum'),' '),10,' ')                                   AS DtCertNum, 
    RPAD(NVL(extractValue(s.xml_data, '//DemandeDP//IdentifiantDemande'),' '),16,' ')                          AS IdentifiantDemande, 
    RPAD(NVL(extractValue(s.xml_data, '//DemandeDP//CodeModeDeLiquidation'),' '),2,' ')                       AS CodeModeDeLiquidation, 
    RPAD(NVL(extractValue(s.xml_data, '//PremiereManifestation//DtPremiereManifestation'),' '),10,' ')                       AS DtPremiereManifestation, 
    RPAD(NVL(extractValue(s.xml_data, '//PremiereManifestation//CodeCanalPremiereManifestation'),' '),2,' ')                       AS CdCanalPremiereManif, 
    RPAD(NVL(extractValue(s.xml_data, '//PremiereManifestation//DtDelivCerfa'),' '),10,' ')                       AS DtDelivCerfa, 
    RPAD(NVL(extractValue(s.xml_data, '//PremiereManifestation//CodeCanalDelivCerfa'),' '),2,' ')                       AS CodeCanalDelivCerfa, 
    RPAD(NVL(extractValue(s.xml_data, '//PremiereManifestation//CodeRegimeCompetentPresume'),' '),4,' ')                       AS CodeRegimeCompetentPresume 
     FROM (select xml_data from COMMUN.SESSION_TEMP_XML where id=1 ) s

感谢您的帮助。