通过profile绑定执行计划

本文介绍了一个SQLT脚本,用于通过调用dbms_sqltune.import_sql_profile过程来绑定特定的执行计划到SQL语句。该脚本展示了如何从v$sql视图中获取SQL全文,并从v$sql_plan视图中收集执行计划的概要提示,最终创建一个SQL配置文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值