Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 转换并存在以合并到_Sql_Oracle_Sql Merge - Fatal编程技术网

Sql 转换并存在以合并到

Sql 转换并存在以合并到,sql,oracle,sql-merge,Sql,Oracle,Sql Merge,我想将这个请求转换为Merge-to的速度太慢,但是我有两个条件,并且存在无法正确转换请求的问题 初始请求 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 e

我想将这个请求转换为Merge-to的速度太慢,但是我有两个条件,并且存在无法正确转换请求的问题

初始请求

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;

我找到了解决方案,在性能方面我赢得了很多时间

Merge into  DR_POS pos
using (select max(ech.MtFlx) max_mtflx ,ech.IdOpe,ech.IdJmb ,ech.CdTypOpe,ech.DtVal 
                       from DR_ECH_OPE ech 
                       where ech.DateCurrent = '03/01/2019'   AND ech.CdTypFlx in ('INT', 'IPR')  
                       group by  ech.IdOpe, ech.IdJmb, ech.CdTypOpe,ech.DtVal 
                       ) 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 exists (select 1 from DR_ECH_OPE ech2
              where ech2.DateCurrent = '03/01/2019' AND ech2.IdOpe = pos.IdOpe AND ech2.IdJmb = pos.IdJmb AND ech2.CdTypOpe = pos.CdTypOpe   AND ech2.CdTypFlx in ('INT', 'IPR') 
              and ech2.DtFinPer=pos.DTARRETE))
when matched then 
update set pos.MtIntInterPer= ech.max_mtflx  ;

我找到了解决方案,在性能方面我赢得了很多时间

Merge into  DR_POS pos
using (select max(ech.MtFlx) max_mtflx ,ech.IdOpe,ech.IdJmb ,ech.CdTypOpe,ech.DtVal 
                       from DR_ECH_OPE ech 
                       where ech.DateCurrent = '03/01/2019'   AND ech.CdTypFlx in ('INT', 'IPR')  
                       group by  ech.IdOpe, ech.IdJmb, ech.CdTypOpe,ech.DtVal 
                       ) 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 exists (select 1 from DR_ECH_OPE ech2
              where ech2.DateCurrent = '03/01/2019' AND ech2.IdOpe = pos.IdOpe AND ech2.IdJmb = pos.IdJmb AND ech2.CdTypOpe = pos.CdTypOpe   AND ech2.CdTypFlx in ('INT', 'IPR') 
              and ech2.DtFinPer=pos.DTARRETE))
when matched then 
update set pos.MtIntInterPer= ech.max_mtflx  ;

我希望将我的请求与2和现有的合并到一起,以改善性能,第一个requesoracle数据库11gi希望将我的请求与2和现有的合并到一起,以改善性能,第一个requesoracle数据库11g