变形并存在合并

时间:2019-07-15 13:15:05

标签: sql oracle sql-merge

我想将此请求转换为Merge into太慢,但是我有两个条件,并且存在无法正确转换请求的情况

初始请求

UPDATE DR_POS pos
  set MtIntInterPer = (select max(MtFlx) from DR_ECH_OPE ech
                       where ech.DateCurrent = '03/01/2019' AND ech.IdOpe = pos.IdOpe AND ech.IdJmb = pos.IdJmb AND ech.CdTypOpe = pos.CdTypOpe AND ech.CdTypFlx in ('INT', 'IPR') 
                       and ech.DtVal=pos.DtProPaiInt)
  where datecurrent = '03/01/2019'  AND CdEtab = 'BPCE'
  AND exists (select 1 from DR_ECH_OPE ech
              where ech.DateCurrent = '03/01/2019' AND ech.IdOpe = pos.IdOpe AND ech.IdJmb = pos.IdJmb AND ech.CdTypOpe = pos.CdTypOpe AND ech.CdTypFlx in ('INT', 'IPR') 
              and ech.DtVal=pos.DtProPaiInt )
  AND exists (select 1 from DR_ECH_OPE ech
              where ech.DateCurrent = '03/01/2019' AND ech.IdOpe = pos.IdOpe AND ech.IdJmb = pos.IdJmb AND ech.CdTypOpe = pos.CdTypOpe AND ech.CdTypFlx in ('INT', 'IPR')   
              and DtFinPer=pos.DTARRETE);

我尝试测试的请求,但没有返回相同行数:

 MERGE INTO dr_pos pos USING (
                                SELECT
                                    MAX(ech.mtflx) max_mtflx,
                                    ech.datecurrent,
                                    ech.idope,
                                    ech.idjmb,
                                    ech.cdtypope,
                                    ech.cdtypflx,
                                    ech.dtval,
                                    ech.dtfinper
                                FROM
                                    dr_ech_ope ech
                                WHERE
                                    ech.datecurrent = '03/01/2019'
                                    AND ech.cdtypflx IN (
                                        'INT',
                                        'IPR'
                                    )
                                GROUP BY
                                    ech.datecurrent,
                                    ech.idope,
                                    ech.idjmb,
                                    ech.cdtypope,
                                    ech.cdtypflx,
                                    ech.dtval,
                                    ech.dtfinper
                            )
ech ON ( pos.datecurrent = '03/01/2019'
         AND pos.cdetab = 'BPCE'
         AND ech.idope = pos.idope
         AND ech.idjmb = pos.idjmb
         AND ech.cdtypope = pos.cdtypope
         AND ech.dtval = pos.dtpropaiint
         AND ech.dtfinper = pos.dtarrete )
WHEN MATCHED THEN UPDATE SET mtintinterper = max_mtflx;

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,并且在性能方面花了很多时间

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/PersonData">
    <xsl:copy>
        <xsl:apply-templates select="Person"/>
     </xsl:copy>
</xsl:template>

<xsl:template match="Person">
    <xsl:copy>
        <xsl:copy-of select="*/*"/>
     </xsl:copy>
</xsl:template>

</xsl:stylesheet>