很奇怪的么;我测试了下就算有空用in也一样能查出来; 你的语句没问题;你再试试这样呢 select * from t1 where lbbh in (002,003,004,009)
select * from t1 where lbbh = '002' union all select * from t1 where lbbh = '003' union all select * from t1 where lbbh = '004' union all select * from t1 where lbbh = '009' 可以使用索引
简单问题搞这么复杂 select * from t1 where lbbh ='002' or lbbh ='003' or lbbh ='004' or lbbh ='009' 谁说用OR不能使用索引!!!!自已试试就知道了,如果没有用到索引,请检查看你的其它条件是否有限制了,注意不要在表达式左边写函数,如to_number('x')='002' 这样是不会用到索引的,还有什么not 、 is 、 like 都不会用索引.
不好意思,上面有个地方没写清,用LIKE 时用 'xx%' 能用索引, '%xx%'不能用索引
看一下执行计划,另外,要是真想用索引,用这个测试一下: select /*+ index(表名 索引名)*/ from table
你的语句没问题;你再试试这样呢
select * from t1 where lbbh in (002,003,004,009)
union all
select * from t1 where lbbh = '003'
union all
select * from t1 where lbbh = '004'
union all
select * from t1 where lbbh = '009'
可以使用索引
select * from t1
where lbbh ='002' or lbbh ='003' or lbbh ='004' or lbbh ='009'
谁说用OR不能使用索引!!!!自已试试就知道了,如果没有用到索引,请检查看你的其它条件是否有限制了,注意不要在表达式左边写函数,如to_number('x')='002' 这样是不会用到索引的,还有什么not 、 is 、 like 都不会用索引.
select /*+ index(表名 索引名)*/ from table
or 可以