对SQL表中的列执行搜索会更好: -
喜欢或修剪。由于此列在起点或末尾都有空格,所以两者都有用,但哪一个会更快。
由于
答案 0 :(得分:0)
您应该设置测试并查看它们的效果。在下面的示例中,我使用了dbms_utility.get_time。我测试了两种功能的相同输入,并重复测试以排除任何外部影响。 它是一个“plsql环境”,如果我可以用这种方式调用它,你应该用实际的表和实际的测试替换查询,并进行更多的“sql”测试。
declare
v_start number;
v_end number;
time_trim number:=0;
time_like number:=0;
cnt_trim number:=0;
cnt_like number:=0;
begin
for N in 1..10 --repeat test
loop
for type_oper in 1..2
loop
v_start := dbms_utility.get_time;
for k in (
select 'abc ' as col from dual connect by level <= 100000
union all
select 'ccc ' as col from dual connect by level <= 100000
union all
select 'acbc ' as col from dual connect by level <= 100000
union all
select ' acbc ' as col from dual connect by level <= 100000
)
loop
if type_oper = 1 then
if trim(k.col) = 'abc' then cnt_trim := cnt_trim + 1; end if;
else
if k.col like '%abc%' then cnt_like := cnt_like + 1; end if;
end if;
end loop; --end loop table
v_end := dbms_utility.get_time;
if type_oper = 1 then
time_trim := time_trim + v_end-v_start;
else
time_like := time_like + v_end-v_start;
end if;
end loop; --end loop type
end loop; --end loop repeat test
dbms_output.put_line('time trim:'||time_trim/100);
dbms_output.put_line('time like:'||time_like/100);
end;
/
结果:
cnt trim:1000000 time trim:6.33
cnt喜欢:1000000时间如:5.83