SQLT中有个脚本是可以直接用的,主要是调用 dbms_sqltune.import_sql_profile来绑定执行计划。
declare
ar_profile_hints sys.sqlprof_attr;cl_sql_text clob;
l_profile_name varchar2(30);
begin
select sql_fulltext,'PROF_'||sql_id||'_'||plan_hash_value into cl_sql_text, l_profile_name
from v$sql
where sql_id = '&xxx' and child_number = 0;
select extractvalue(value(d), '/hint') as outline_hints bulk collect into ar_profile_hints
from xmltable('/*/outline_data/hint' passing (select xmltype(other_xml) as xmlval from v$sql_plan where sql_id = '&xxx' and child_number = 0 and other_xml is not null)
) d;
dbms_sqltune.import_sql_profile(
sql_text => cl_sql_text,
profile => ar_profile_hints,
category => 'DEFAULT',
name => l_profile_name,
force_match => false
-- replace => true
);
dbms_output.put_line(' ');
dbms_output.put_line('SQL Profile '||l_profile_name||' created.');
dbms_output.put_line(' ');
end;
/