优化PL / SQL过滤器

时间:2018-11-02 19:08:01

标签: optimization plsql filter

我对PL / SQL不太熟悉,但是我在一个伙伴的项目中发现了很多代码,这些代码对我来说似乎很不对劲,我能找到一个更好的选择吗?

SET filter_conditions = 
  '
  AND 
  (
    ((
      processes.get_main_GC_id(nov.GCID) IN ('''', ''01'',''02'',''03'',''04'',''05'',''07'',''08'',''09'',''10'',''12'',''13'',''14'',''16'')
      OR (processes.get_main_GC_id(nov.idGrupoCliente) IN (''23'', ''29'') AND ExtraNumber != 0)
      OR (processes.get_main_GC_id(nov.idGrupoCliente) IN (''28'',''35'',''36'',''37''))
      OR (processes.get_main_GC_id(nov.idGrupoCliente) IN (''40'') AND ExtraNumber != 0)
      OR (processes.get_main_GC_id(nov.idGrupoCliente) IN (''151'', ''152'', ''153''))
    ) AND Cortesia !=  ''S'')
    OR
    (Cortesia =  ''S'' AND cortesiaGrupo = 6 AND cortesiaCampania = 5 AND calle != '''')
  )
  ';

尤其是数量惊人的OR-IN。我编辑了很多,但相信我有数百个。有没有办法使用向量或其他方法检查变量是否匹配?

1 个答案:

答案 0 :(得分:0)

declare
  l_filter_conditions VARCHAR2(2000) := q'{
                                            AND (
                                                 (
                                                   (processes.get_main_GC_id(nov.GCID) IN ( '01','02','03','04','05','07','08','09','10','12','13','14','16') OR processes.get_main_GC_id(nov.GCID) is NULL)
                                                OR (processes.get_main_GC_id(nov.idGrupoCliente) IN ('23', '29','40') AND ExtraNumber != 0) 
                                                OR (processes.get_main_GC_id(nov.idGrupoCliente) IN ('28','35','36','37','151','152','153')) 
                                                ) 
                                                AND Cortesia !=  'S' OR (Cortesia,cortesiaGrupo,cortesiaCampania) =  (('S',6,5)) AND calle IS NOT NULL
                                                )
                                        }';
begin
DBMS_OUTPUT.PUT_LINE(l_filter_conditions); 
end;
  

陈述已处理。

     

AND((((processes.get_main_GC_id(nov.GCID)IN(   '01','02','03','04','05','07','08','09','10','12','13','14','16 ') 要么   process.get_main_GC_id(nov.GCID)为NULL)或   (processes.get_main_GC_id(nov.idGrupoCliente)IN('23','29','40')和   ExtraNumber!= 0)或(processes.get_main_GC_id(nov.idGrupoCliente)IN   ('28','35','36','37','151','152','153')))和Cortesia!='S'OR   (Cortesia,cortesiaGrupo,cortesiaCampania)=(('S',6,5))AND被叫是   NOT NULL)

我不知道这是否能回答您的问题,但我花了一些时间重新设计您的代码。