2

假设我在 sql plus 中执行我的脚本,如下所示

sql>set autotrace traceonly;
sql>select * from employees;


Execution Plan
----------------------------------------------------------
   0       SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=2 Card=14 Bytes=1 K)
   1    0    TABLE ACCESS FULL T416493.EMPLOYEE (Cost=2 Card=14 Bytes=1 K)

Statistics
----------------------------------------------------------
      6  user calls
      0  physical read total multi block requests
      0  physical read total bytes
      0  cell physical IO interconnect bytes
      0  commit cleanout failures: block lost
      0  IMU commits
      0  IMU Flushes
      0  IMU contention
      0  IMU bind flushes
      0  IMU mbu flush
     14  rows processed

我正在创建一个包,我在其中传递查询,它将为我提供具有此统计信息的执行计划。我该如何实现这个包?

4

1 回答 1

1

这是 DMBS_XPLAN 的基本包装器。

CREATE OR REPLACE PROCEDURE print_plan(p_sql IN VARCHAR2)
IS
BEGIN
  EXECUTE IMMEDIATE 'explain plan for '||p_sql;

  FOR r_plan IN (SELECT * 
                 FROM table(DBMS_XPLAN.DISPLAY))
  LOOP
    dbms_output.put_line(r_plan.plan_table_output);
  END LOOP;
END;
/

BEGIN
  print_plan('select 1 from dual');
END;
/
于 2012-07-25T08:12:40.877 回答