之前的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的效率?为什么存储过程执行的时候速度就变得很慢呢?
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的效率?为什么存储过程执行的时候速度就变得很慢呢?
from tableA b
where instr(b.ani,v_callno) >=1
from tableA b
where instr(b.ani,v_callno) >=1
用instr 函数要好些 like的效率太低了
count(*) 改成count(1)这样也好些
这样试下。。