日期:2014-05-16 浏览次数:20425 次
oracle view 学习小结
视图的定义就是其使用的查询语句,Oracle 将这个定义以文本形式存储
在数据字典中。当用户在 SQL 语句中引用了视图时,Oracle 将进行以
下工作:
1. 将引用了视图的语句与视图的定义语句整合为(merge)一个语句
2. 在共享 SQL 区(shared SQL area)解析(parse)整合后的语句
3. 执行(execute)此语句
接下来用一个实验来证明下:
SQL> alter system flush shared_pool;
SQL> SELECT last_name
2 FROM hr.employees, hr.departments
3 WHERE employees.department_id = departments.department_id AND
4 departments.department_id = 10 AND
5 employees.employee_id = 9876;
no rows selected
Execution Plan
----------------------
Plan hash value: 1833546154
--------------------------------------------
-------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU
)| Time |
--------------------------------------------
-------------
| 0 | SELECT STATEMENT | | 1 | 15 | 1 (0
)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 15 | 1 (0
)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | | 0 (0
)| 00:00:01 |
--------------------------------------------
-------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("EMPLOYEES"."DEPARTMENT_ID"=10)
2 - access("EMPLOYEES"."EMPLOYEE_ID"=9876)
Statistics
----------------------
202 recursive calls
0 db block gets
290 consistent gets
1 physical reads
0 redo size
337 bytes sent via SQL*Net to client
512 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
13 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> alter system flush shared_pool;
System altered.
SQL> SELECT last_name
2 from hr.employees_view
3 WHERE employee_id = 9876;
no rows selected
Execution Plan
----------------------
Plan hash value: 1833546154
--------------------------------------------
-------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU
)| Time |
--------------------------------------------
-------------
| 0 | SELECT STATEMENT &nb