Moves a SQL Profile from one statement to another


set sqlblanklines on

declare
ar_profile_hints sys.sqlprof_attr;
cl_sql_text clob;
version varchar2(3);
l_category varchar2(30);
l_force_matching varchar2(3);
b_force_matching boolean;
begin
 select regexp_replace(version,’..*’) into version from v$instance;

if version = ’10’ then

— dbms_output.put_line(‘version: ‘||version);
   execute immediate — to avoid 942 error
   ‘select attr_val as outline_hints ‘||
   ‘from dba_sql_profiles p, sqlprof$attr h ‘||
   ‘where p.signature = h.signature ‘||
   ‘and name like (”&&profile_name”) ‘||
   ‘order by attr#’
   bulk collect
   into ar_profile_hints;

elsif version = ’11’ then

— dbms_output.put_line(‘version: ‘||version);
   execute immediate — to avoid 942 error
   ‘select hint as outline_hints ‘||
   ‘from (select p.name, p.signature, p.category, row_number() ‘||
   ‘      over (partition by sd.signature, sd.category order by sd.signature) row_num, ‘||
   ‘      extractValue(value(t), ”/hint”) hint ‘||
   ‘from sqlobj$data sd, dba_sql_profiles p, ‘||
   ‘     table(xmlsequence(extract(xmltype(sd.comp_data), ‘||
   ‘                               ”/outline_data/hint”))) t ‘||
   ‘where sd.obj_type = 1 ‘||
   ‘and p.signature = sd.signature ‘||
   ‘and p.name like (”&&profile_name”)) ‘||
   ‘order by row_num’
   bulk collect
   into ar_profile_hints;

end if;

/*
declare
ar_profile_hints sys.sqlprof_attr;
cl_sql_text clob;
begin
select attr_val as outline_hints
bulk collect
into
ar_profile_hints
from dba_sql_profiles p, sqlprof$attr h
where p.signature = h.signature
and name like (‘&&profile_name’)
order by attr#;
*/

select
sql_fulltext
into
cl_sql_text
from
v$sqlarea
where
sql_id = ‘&&sql_id’;

dbms_sqltune.import_sql_profile(
sql_text => cl_sql_text
, profile => ar_profile_hints
, category => ‘&&category’
, name => ‘PROFILE_’||’&&sql_id’||’_moved’
— use force_match => true
— to use CURSOR_SHARING=SIMILAR
— behaviour, i.e. match even with
— differing literals
, force_match => &&force_matching
);
end;
/

undef profile_name
undef sql_id
undef category
undef force_matching

  • April 11, 2018 | 14 views
  • Comments