在使用查询优化器产生的命名当中,首先,我们必须知道知道他们叫什么,我们可以使用SQL语句WXPLAIN PLAN和dbms_xplan包,来做!以下当中使用display的alias是为了保证查询块和别名都被输出。
SQL> ed
已写入 file afiedt.buf
1 explain plan for
2 with
3 emps as (select deptno,count(*) as cnt
4 from emp
5 group by deptno)
6 select dept.dname,emps.cnt
7 from dept,emps
8* where dept.deptno=emps.deptno
SQL> /
已解释。
SQL> select * from table(dbms_xplan.display(NULL,NULL,'basic +alias'));
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
Plan hash value: 2941989041
------------------------------------------------
| Id | Operation | Name |
------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | NESTED LOOPS | |
| 2 | VIEW | |
| 3 | HASH GROUP BY | |
| 4 | TABLE ACCESS FULL | EMP |
| 5 | TABLE ACCESS BY INDEX ROWID| DEPT |
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
| 6 | INDEX UNIQUE SCAN | PK_DEPT |
------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$2
2 - SEL$1 / EMPS@SEL$2
3 - SEL$1
4 - SEL$1 / EMP@SEL$1
5 - SEL$2 / DEPT@SEL$2
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
6 - SEL$2 / DEPT@SEL$2
已选择23行。
SQL>
主查询块为SEL$2,子查询块为SEL$1,!