以补丁的形式,将hint 打入到指定SQL     也可以参考sqlt 下面的​coe_gen_sql_patch.sql
 
常用的HINT :   hint_text (一般是bind_aware/monitor/)   
 
注意: bind_aware/monitor /gather_plan_statistics  是sql  profile 是用不了的 
             如果sql  profile 可以用的,建议用sql  profile  
# 12.2之前版本
–需要用sys用户执行: sys.dbms_sqldiag_internal
–相关视图: DBA_SQL_PATCHES,hint 在description字段
–常用几个hint: GATHER_PLAN_STATISTICS / MONITOR / BIND_AWARE / IGNORE_OPTIM_EMBEDDED_HINTS

begin
sys.dbms_sqldiag_internal.i_create_patch( sql_text  => V_SQL,
                                           hint_text => 'BIND_AWARE',
                                           name      => 'sql_djzfp4cy24dx3');
end ;
/

# 12.2及以后版本

#创建sql patch
declare
  patch_name varchar2(30);
begin
  patch_name:=dbms_sqldiag.create_sql_patch(sql_id=>'&sql_id' , hint_text=>'&hint_text');
end ;
/

注意:hint_text的写法,要体符合 Outline Data
可能选执行 explain plan for + hint
然后通过display 的advanced 方式查询 , 注意要加引号 例: hint_text=>'index("T"@"SEL$1")'   或  'index(@"SEL$1" "T")'
explain plan for select /*+ index(t) */ OBJECT_NAME,OBJECT_TYPE from t where OBJECT_TYPE='JAVA CLASS';
select * from table(dbms_xplan.display(null,null,'advanced'));


#查看sql patch

col description format a40
col name format a30
set linesize 200
select name,to_char(created,'yyyy-mm-dd hh24:mi:ss') as created
,status,force_matching,description,substr(sql_text,1,50)  as sql_text
from dba_sql_patches
order by created;


#删除sql patch
exec  dbms_sqldiag.drop_sql_patch(name=>'&patch_name')
 
 
 

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

 
 
 
 
12-22 21:48