使用alter session set current_schema=scott用explain plan for檢視scott使用者的sql
某Q友問題
explain沒有思路,除了切換到sql的使用者下面我知道使用者也不知道密碼
這也切不過去啊
結論
1,學會檢視官方手冊,前提就是要多看多思考,其碼熟悉官方手冊的知識結構構成,方可針對性查閱資料2, alter session set current_schema可以切換到對應指定的使用者,相當於在指定使用者進行檢視相關操作
測試
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
SQL> show user
USER is "SCOTT"
SQL> explain plan for select count(a) from t_plan;
Explained.
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY(NULL, NULL, 'ADVANCED -PROJECTION'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 4286448300
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | TABLE ACCESS FULL| T_PLAN | 1 | 13 | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T_PLAN@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
FULL(@"SEL$1" "T_PLAN"@"SEL$1")
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
DB_VERSION('11.2.0.1')
OPTIMIZER_FEATURES_ENABLE('11.2.0.1')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/
Note
-----
- dynamic sampling used for this statement (level=2)
33 rows selected.
SQL>
----現在我們回到開頭的Q友問題,無非就是想讓在SYS使用者這個會話可以檢視SCOTT使用者的建立的sql執行計劃,所以我想肯定是到官方手冊 Oracle? Database SQL Language Reference
去找,找哪塊呢,是和會話相關,那麼只能是alter session,經查閱發現
alter session set current_schema可以達到這個目標,現摘錄相關資訊於此,供大家參考:
Syntax:
CURRENT_SCHEMA = schema
The CURRENT_SCHEMA parameter changes the current schema of the session to the specified schema. Subsequent unqualified references to schema objects during the session will resolve to objects in the specified schema. The setting persists for the duration of the session or until you issue another ALTER SESSION SET CURRENT_SCHEMA statement.
This setting offers a convenient way to perform operations on objects in a schema other than that of the current user without having to qualify the objects with the schema name. This setting changes the current schema, but it does not change the session user or the current user, nor does it give the session user any additional system or object privileges for the session.
SQL> show user
USER is "SYS"
SQL> explain plan for select count(a) from t_plan;
explain plan for select count(a) from t_plan
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> alter session set current_schema=scott;
Session altered.
SQL> explain plan for select count(a) from t_plan;
Explained.
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY(NULL, NULL, 'ADVANCED -PROJECTION'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 4286448300
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | TABLE ACCESS FULL| T_PLAN | 1 | 13 | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T_PLAN@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
FULL(@"SEL$1" "T_PLAN"@"SEL$1")
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
DB_VERSION('11.2.0.1')
OPTIMIZER_FEATURES_ENABLE('11.2.0.1')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/
Note
-----
- dynamic sampling used for this statement (level=2)
33 rows selected.
SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-1872040/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 以scott使用者執行set autotrace 出錯
- 【Explain Plan】檢視SQL的執行計劃AISQL
- Oracle資料庫scott使用者建立view檢視許可權Oracle資料庫View
- 建立scott使用者及物件物件
- 新增scott使用者與其物件物件
- AUTHID DEFINER\authid current_user與alter session set current_schemaSession
- 使用EXPLAIN PLAN來檢視執行計劃AI
- Oracle 12c 建立 SCOTT 使用者Oracle
- alter session setSession
- Oracle 12c如何建立scott使用者Oracle
- 用EXPLAIN PLAN 分析SQL語句AISQL
- ALTER SESSION SET EVENTSSession
- 使用V$SQL_PLAN檢視SQL
- oracle手工建庫後建立scott使用者的emp表,conn scott/tiger報錯解決Oracle
- 恢復oracle的scott使用者初始狀態操作Oracle
- alter session|system set eventsSession
- 向資料庫中新增HR使用者和SCOTT使用者資料庫
- EXPLAIN PLAN FOR 和 SET AUTOTRACE之間的差別AI
- Oracle裡scott的由來Oracle
- Oracle通過scott使用者中的emp練習單表操作Oracle
- 為什麼我的logminer分析不出scott使用者的dml操作?
- Scott使用者及其物件和資料初始化指令碼物件指令碼
- Talk with Mr. Scott (轉)
- alter session set events /Oracle跟蹤SessionOracle
- v$sql_plan 檢視解析SQL
- Oracle scott/tiger的由來Oracle
- set autot traceonly與explain plan for的一點小區別AI
- Explain PlanAI
- sql中使用函式導致explain plan for和set autotrace得到執行計劃不準確SQL函式AI
- explain plan VS execution planAI
- explain plan 的用法AI
- 檢視執行計劃方法總結之一:explain plan命令AI
- 【實驗】利用系統自帶指令碼utlsampl.sql建立scott使用者及樣本資料指令碼TLSSQL
- USE EXPLAIN PLANAI
- oracle基表使用小記(一)_更新col$調整scott使用者表test的排列次序Oracle
- v$sql_plan這個檢視解析SQL
- Oracle-解鎖scott賬戶Oracle
- EXPLAIN PLAN and SQL*PLUS AUTOTRACE may not generate actual plansAISQL