AUTOTRACE in SQL*Plus:
SQL*Plus provides an AUTOTRACE facility that allows us to see the execution plans of the queries we’ve executed and the resources they used. The report is generated after successful SQL DML.There is more than one way to configure the AUTOTRACE facility,
But the following is a recommended route:
1. Access cd $ORACLE_HOME/rdbms/admin.
2. Log into SQL*Plus as any user with CREATE TABLE and CREATE PUBLIC
SYNONYM privileges.
3. Run @UTLXPLAN to create a PLAN_TABLE for use by AUTOTRACE.
4. Run CREATE PUBLIC SYNONYM PLAN_TABLE FOR PLAN_TABLE, so that everyone
can access this table without specifying a schema.
5. Run GRANT ALL ON PLAN_TABLE TO PUBLIC, so that everyone can use this
table.
6. Exit SQL*Plus and change directories as follows:
cd $ORACLE_HOME/sqlplus/admin.
7. Log into SQL*Plus as a SYSDBA.
8. Run @PLUSTRCE.
9. Run GRANT PLUSTRACE TO PUBLIC.
You can test your setup by enabling AUTOTRACE and executing a simple query:
SQL> set AUTOTRACE traceonly
SQL> select * from emp, dept
2 where emp.deptno=dept.deptno;
14 rows selected.
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 MERGE JOIN
Setting Up
xxii
2 1 SORT (JOIN)
3 2 TABLE ACCESS (FULL) OF 'DEPT'
4 1 SORT (JOIN)
5 4 TABLE ACCESS (FULL) OF 'EMP'
Statistics
----------------------------------------------------------
0 recursive calls
8 db block gets
2 consistent gets
0 physical reads
0 redo size
2144 bytes sent via SQL*Net to client
425 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
14 rows processed
SQL> set AUTOTRACE off