如何啟用sqlplus的AutoTrace功能

paulyibinyi發表於2008-01-09

D:\oracle\ora92>sqlplus /nolog
SQL*Plus: Release 9.2.0.1.0 - Production on 星期二 6月 3 15:16:03 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> connect sys as sysdba
請輸入口令:
已連線。
SQL> @?\rdbms\admin\utlxplan
表已建立。
SQL> create public synonym plan_table for plan_table;
同義詞已建立。
SQL> grant all on plan_table to public ;
授權成功。
SQL> @?\sqlplus\admin\plustrce
SQL> drop role plustrace;
drop role plustrace
*
ERROR 位於第 1 行:
ORA-01919: 角色'PLUSTRACE'不存在
SQL> create role plustrace;
角色已建立
SQL> grant select on v_$sesstat to plustrace;
授權成功。
SQL> grant select on v_$statname to plustrace;
授權成功。
SQL> grant select on v_$session to plustrace;
授權成功。
SQL> grant plustrace to dba with admin option;
授權成功。
DBA使用者首先被授予了plustrace角色,然後我們可以把plustrace授予public
這樣所有使用者都將擁有plustrace角色的許可權.
SQL> grant plustrace to public ;
授權成功。
然後我們就可以使用AutoTrace的功能了.
C:\Documents and Settings\Paul Yi>sqlplus paul/paul
SQL*Plus: Release 9.2.0.1.0 - Production on 星期四 6月 28 16:14:03 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
連線到:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> set autotrace on
SQL> set timing on
SQL> select * from t_receive;

ID TELENO LOG_DATA U_
---------- ---------- ------------------- --
1 1234 2007-06-28 15:33:56 注
1 1234 2007-06-28 15:34:19 取
1 1235 2007-06-28 15:34:43 注
1 1235 2007-06-28 15:34:53 取
1 1235 2007-06-28 15:35:03 變

已用時間: 00: 00: 00.00

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'T_RECEIVE'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
644 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed
關於Autotrace幾個常用選項的說明:
SET AUTOTRACE OFF ---------------- 不生成AUTOTRACE 報告,這是預設模式
SET AUTOTRACE ON EXPLAIN ------ AUTOTRACE只顯示最佳化器執行路徑報告
SET AUTOTRACE ON STATISTICS -- 只顯示執行統計資訊
SET AUTOTRACE ON ----------------- 包含執行計劃和統計資訊
SET AUTOTRACE TRACEONLY ------ 同set autotrace on,但是不顯示查詢輸出

補充兩個AUTOTRACE
set autotrace traceonly exp
set autotrace traceonly exp stat

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7199859/viewspace-120034/,如需轉載,請註明出處,否則將追究法律責任。

相關文章