Home >Database >Mysql Tutorial >使用Oracle的instr函数与索引配合提高模糊查询的效率

使用Oracle的instr函数与索引配合提高模糊查询的效率

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:19:041957browse

一般来说,在Oracle数据库中,我们对tb表的name字段进行模糊查询会采用下面两种方式:1.select * from tb where name like

一般来说,在Oracle数据库中,我们对tb表的name字段进行模糊查询会采用下面两种方式:
1.select * from tb where name like '%XX%';
2.select * from tb where instr(name,'XX')>0;

若是在name字段上没有加索引,两者效率差不多,基本没有区别。

为提高效率,我们在name字段上可以加上非唯一性索引:
create index idx_tb_name on tb(name);

这样,再使用
select * from tb where instr(name,'XX')>0;
这样的语句查询,效率可以提高不少,,表数据量越大时两者差别越大。但也要顾及到name字段加上索引后DML语句会使索引数据重新排序的影响。

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn