本篇记录一些Oracle表访问操作
Oracle显示执行计划的存储过程请参考
(1)TABLE ACCESS FULL
全表扫表,使用全表扫描的方式访问表。示例:
SQL> exec sql_explain('select * from t1');
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 80 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T1 | 10 | 80 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
PL/SQL procedure successfully completed.
(2)TABLE ACCESS BY INDEX ROWID
通过索引获得的ROWID访问表。示例:
SQL> exec sql_explain('select * from t1 where id=1');
Plan hash value: 2347959165
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 1 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 8 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | T1_PK | 1 | | 0 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=1)
PL/SQL procedure successfully completed.