CREATE TABLE TEST1
(
STATUS NUMBER NOT NULL
);
CREATE INDEX IXTEST1 ON TEST1(STATUS);
insert into test1
select MOD(level,10)
from dual
connect by level <= 10000;
select * from TEST1 where status in (0,1,2,3,4);
select * from TEST1 where status not in (5,6,7,8,9);
如果列上有索引,IN 子句可以更好地利用它。你可以自己测试一下:
如果我们为这两个语句运行 oracle tuning advisor,我们首先得到:
但对于第二个: