• 技术文章 >数据库 >mysql教程

    为快捷显示Oracle执行计划创建存储过程

    2016-06-07 17:27:15原创546

    为快捷显示Oracle执行计划创建存储过程 第一种:不设置输出格式参数,即用默认的 SQLgt; create or replace procedure sql_expl

    为快捷显示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.

    linux

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:Oracle RAC 更改instance name完整步骤 下一篇:MySQL死锁导致无法查询
    20期PHP线上班

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• MySQL的rollback(总结分享)• 一起来聊聊数据库拉链表• mysql中去掉空格的函数有哪些• mysql怎么取字符串前几位• mysql中有if吗
    1/1

    PHP中文网