1. 程式人生 > 其它 >oracle檢視執行計劃explain plan FOR

oracle檢視執行計劃explain plan FOR

轉載:https://www.cnblogs.com/ataoxz/p/15107456.html

oracle要進行檢視執行計劃,可以使用explain plan FOR命令

使用方式就是在要檢視計劃的sql前面加上explain plan FOR

然後執行後會生成執行計劃要檢視需要使用

select plan_table_output from TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE'));

進行檢視

要注意的是

explain plan FOR

select plan_table_output from TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE'));

兩個命令需要在同一個視窗下執行

否則會報錯,

Error: cannot fetch last explain plan from PLAN_TABLE

在同一個視窗下執行後沒有該報錯.

例子:

explain plan FOR select 1 from dual;

select plan_table_output from TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE'));


Plan hash value: 1388734953

-----------------------------------------------------------------

| Id | Operation | Name | Rows | Cost (%CPU)| Time |

-----------------------------------------------------------------

| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |

| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |

-----------------------------------------------------------------