---
title: "在oracle中如何优化像 like '%abd%'之类的查询"
author: "stop_"
date: "2007-11-13T16:31:12Z"
tags: []
slug: "oracle-like-abd"
draft: false
lastmod: "2007-11-13T16:31:12Z"
id: 140285
url: "https://stop.iteye.com/blog/140285"
---

象like '%abc%'之类的查询对于大表来说是个致命的性能瓶颈。下面说说如何优化.

该文的内容来自[www.oracle.com.cn](http://www.oracle.com.cn).原文是英文的。

1.如何优化 like '%abc'.

这种优化建立反序索引就可以了。

2.如何优化  like 'abc%'

这种比较好办，直接建立索引就可以了

3.如何优化 like '%abc%'

比如：

a.建立测试表mytable

 create table mytable   as select a.\*,rpad('0',400,'0') dummy from all\_objects a;

b.然后建立起索引作用的表mytable\_myind

 create table mytable\_myind      as select a.rowid rid,a.object\_name from mytable a

c.把起索引作用的表mytable\_myind钉到内存里面

alter table mytable\_myind storage (buffer\_pool keep);

alter table mytable\_myind  cache;

d.执行如下的sql语句：如果对于数据量大的表，那么速度有很大的提高。

select /\*+rule\*/ owner from mytable  where rowid in    
    ( select rid from mytable\_myind   
          where object\_name like '%DUAL%'   
      );

**当然，可以使用触发器来更新表mytable\_myind**