一般來說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 .... ;