Search This Blog

Sunday, May 20, 2012

Create Explain Plan Automatically


create or replace
function createplan
(
  sql_text in varchar2
)
return varchar2
as
     plan_stmt_id_ varchar2(4000);
begin
  select to_char(plan_stmt_id.nextval) into plan_stmt_id_ from dual;
  execute immediate  ( 'EXPLAIN PLAN SET STATEMENT_ID = '''||plan_stmt_id_||''' INTO plan_table FOR '||sql_text);
  return plan_stmt_id_;
end createplan;