之前的SQL如下:
select count(*) into v_count from tableA b where b.ani like '%'||v_callno(v_callno存入数据库的值不定,有事是123,有时是0123或者1123或者10123。)
表中的数据量比较大,为了提高查询效率不使用like查询将SQL修改如下:
select count(*) into v_count from tableA b where b.ani = v_callno or b.ani = '1'||v_callno or b.ani = '0'||v_callno or b.ani = '10'||v_callno 
单独执行的时候速度比之前的SQL快了一点。但是放到存储过程中执行的时候,知道到修改后的SQL时速度变的很慢。远不如之前使用like时候的速度。
请教各位如何提高该SQL的效率?为什么存储过程执行的时候速度就变得很慢呢?

解决方案 »

  1.   

    这样试试呢 select count(*) into v_count 
    from tableA b 
    where instr(b.ani,v_callno) >=1
      

  2.   

    试试在存储过程中执行select count(*) into v_count from tableA b where b.ani = v_callno 看会不会慢, 如果不慢的话就分开执行吧
      

  3.   

    select count(1) into v_count 
    from tableA b 
    where instr(b.ani,v_callno) >=1
    用instr 函数要好些 like的效率太低了 
    count(*) 改成count(1)这样也好些
      

  4.   

    这个可以,再加个多线程parallel 就可以了。
      

  5.   

    select count(1) from table num in (10123,0123,123)
    这样试下。。