Welcome 微信登录

首页 / 数据库 / MySQL / 为快捷显示Oracle执行计划创建存储过程

为快捷显示Oracle执行计划创建存储过程第一种:不设置输出格式参数,即用默认的SQL> create or replace procedure sql_explain(v_sql varchar2)
  2  is
  3  type explain_cursor_type is ref cursor;
  4  explain_cursor explain_cursor_type;
  5  a varchar2(2048);
  6  begin
  7    execute immediate "explain plan for "||v_sql;
  8    open explain_cursor for select PLAN_TABLE_OUTPUT  from table(dbms_xplan.display());
  9    loop
 10      fetch explain_cursor into a;
 11      exit when explain_cursor%NOTFOUND;
 12   dbms_output.put_line(a);
 13    end loop;
 14  end;
 15  /Procedure created.
SQL> exec sql_explain("select a.name,b.name from t1 a,t2 b where a.id=b.id and a.id=1");
Plan hash value: 2680223496
--------------------------------------------------------------------------------------
| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time   |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT           |     |   1 |    17 |   4 (0)| 00:00:01 |
| 1 |  NESTED LOOPS                |     |   1 |    17 |   4 (0)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| T1    |   1 |   8 |   1 (0)| 00:00:01 |
|*  3 |    INDEX UNIQUE SCAN       | T1_PK |   1 |     |   0 (0)| 00:00:01 |
|*  4 | TABLE ACCESS FULL          | T2    |   1 |   9 |   3 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("A"."ID"=1)
4 - filter("B"."ID"=1)PL/SQL procedure successfully completed.SQL> exec sql_explain("select a.name,b.name from t1 a,t2 b where a.id=b.id and a.id=""1""");
Plan hash value: 2680223496
--------------------------------------------------------------------------------------
| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time   |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT           |     |   1 |    17 |   4 (0)| 00:00:01 |
| 1 |  NESTED LOOPS                |     |   1 |    17 |   4 (0)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| T1    |   1 |   8 |   1 (0)| 00:00:01 |
|*  3 |    INDEX UNIQUE SCAN       | T1_PK |   1 |     |   0 (0)| 00:00:01 |
|*  4 | TABLE ACCESS FULL          | T2    |   1 |   9 |   3 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("A"."ID"=1)
4 - filter("B"."ID"=1)PL/SQL procedure successfully completed.
  • 1
  • 2
  • 下一页
Oracle 10g SID dump目录Oracle 执行计划之表访问操作相关资讯      Oracle存储过程  Oracle执行计划  Oracle创建存储过程 
  • Oracle存储过程拼接in语句 & 自定  (今 09:21)
  • 【PL/SQL系列】Oracle存储过程使用  (04月23日)
  • 执行计划出现COLLECTION ITERATOR   (07/23/2015 16:25:04)
  • Java调用Oracle存储过程返回多条结  (04月29日)
  • Oracle中的存储过程简单应用  (04月10日)
  • Oracle存储过程及Java调用  (05/28/2015 20:29:33)
本文评论 查看全部评论 (0)
表情: 姓名: 字数


评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的