The SQL*Plus auto trace is another method to get actual execution plan with some additional statistics. When set to ON automatically display execution plan after each SQL statement with Statistics

What is SQL*Plus Auto-Trace?

The SQL*Plus auto trace is another method to get actual execution plan with some additional statistics. When set to ON automatically display execution plan after each SQL statement with Statistics

  • You should be connected to a SQL*Plus session.
  • Statement is required to run to get execution plan plan.

Syntax of SQL*Plus Auto-Trace

SET AUTOTRACE
OFF|ON| SET ON OR off SQL*Plus Auto-Trace FOR current session.
TRACEONLY Trace only without DATA
[EXPLAIN] Execution plan without statistics
[STATISTICS] Statistics without execution plan

Set SQL*Plus Auto Trace

--[Step-1:]  Make sure that following script is already executed.
CONNECT SYS/DEV@DEVDB AS SYSDBA
@C:\ORACLE\PRODUCT\10.2.0\DB_1\SQLPLUS\ADMIN\PLUSTRCE.SQL

Note: You will get the following error IF the script IS NOT executed.
SP2-0618:Cannot find the Session Identifier.CHECK PLUSTRACE role IS enabled
SP2-0611: Error enabling STATISTICS report

--[Step-2:] Grants are given to the user.
GRANT PLUSTRACE TO SCOTT;
CONNECT SCOTT/TIGER@DEVDB

--[Step-3:]--
SET AUTOTRACE ON

Output of SQL*Plus Auto-Trace.

SELECT * FROM emp;

Output of query

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- -----
1111 SAM MANAGER 7839 04-MAR-01 45000 2150 10
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10

Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 15 | 1305 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 15 | 1305 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Note
-----
- dynamic sampling used FOR this statement Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
1407 bytes sent via SQL*Net TO client
381 bytes received via SQL*Net FROM client
2 SQL*Net roundtrips TO/FROM client
0 sorts (memory)
0 sorts (disk)
15 rows processed

Statistics created by Auto-Trace

Recursive calls
DB block – gets number of times a CURRENT block was requested
Consistent – gets number of times a consistent read was requested for a block
Physical reads – number of datablocks read from disk
Redo size – Amount of redo generated
SQL*Net round-trips to and from clients

Go to top
JSN Boot template designed by JoomlaShine.com