Home  >  Article  >  Database  >  Oracle中LIKE语句优化

Oracle中LIKE语句优化

WBOY
WBOYOriginal
2016-06-07 16:59:591171browse

1。尽量不要使用 like

1。尽量不要使用 like '%%'

2。对于 like '%' (不以 % 开头),Oracle可以应用 colunm上的index

3。对于 like '%…' 的 (不以 % 结尾),可以利用reverse + function index 的形式,变化成 like '%'

建测试表和Index,注意,,重点在于带reverse的function index。同时,一定要使用CBO才行

create table test_like as select object_id,object_name from dba_objects;

-------建立测试表

create index test_like__name on test_like(object_name);

------建立索引

create index test_like__name_reverse on test_like(reverse(object_name));

------建立反向索引

analyze table test_like compute statistics for table for all indexes;

------对表进行分析

都过SQLPLUS连接到数据,一定是SQLPLUS,因为下面有写命令在PLSQL的命令行中不被支持;

set autotrace trace exp

-----设定SQL跟踪

set linesize 2000

-------设定输出宽度

select * from test_like where object_name like 'AS%';

使用了索引

select * from test_like where object_name like '%S';

未使用索引

select * from test_like where reverse(object_name)like reverse('%AS');

使用了索引

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