一般来说ORACLE的索引由系统自动启用的,也可以强制使用,方法如下:
/*假如表为Grade_xu 列名为(学号) 索引名为index1*/
--创建索引
create index index1 on Grade_xu(学号);
--查询Grade_xu中索引是否创建,名称要全大写!
select * from user_indexes where table_name='GRADE_XU';
--开启索引监控 注:目的是为了查看所以是否使用
alter index index1 monitoring usage;
--固定的格式强制使用索引其中的/**/不是注释,而是强制格式 注:一般索引由oracle自己决定是否调用
select /*+ INDEX(Grade_xu,index1) */ * from Grade_xu where 学号 = '2016198001';
--查看索引是否使用 USED列为YES表示使用过 NO表示没有 大家自己测试
select * from v$object_usage;
--关闭索引监控
alter index index1 nomonitoring usage;
--删除索引
drop index index1;
索引使用的格式为:
select /*+空格index(表名,索引名)空格*/空格 * from 表名 where .... ;
select /*+空格index(表名,索引名)空格*/空格 * from 表名 where .... ;