Repository navigation
Expand file tree
/
Copy pathcreate_1_hint_sql_profile.sql
More file actions
94 lines (81 loc) · 2.54 KB
/
Copy pathcreate_1_hint_sql_profile.sql
File metadata and controls
94 lines (81 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
----------------------------------------------------------------------------------------
--
-- File name: create_1_hint_sql_profile.sql
--
-- Purpose: Prompts for a hint and makes a profile out of it.
-
-- Author: Kerry Osborne
--
-- Usage: This scripts prompts for four values.
--
-- profile_name: the name of the profile to be attached to a new statement
--
-- sql_id: the sql_id of the statement to attach the profile to (must be in theshared pool)
--
-- category: the category to assign to the new profile
--
-- force_macthing: a toggle to turn on or off the force_matching feature
--
-- Description: This script prompt for a hint. It does not validate the hint. It creates a
-- SQL Profile with the single hint and attaches it to the provided sql_id.
-- This script should now work with all flavors of 10g and 11g.
--
--
-- See kerryosborne.oracle-guy.com for additional information.
-----------------------------------------------------------------------------------------
accept sql_id -
prompt 'Enter value for sql_id: ' -
default 'X0X0X0X0'
accept profile_name -
prompt 'Enter value for profile_name (PROFILE_sqlid_MANUAL): ' -
default 'X0X0X0X0'
accept category -
prompt 'Enter value for category (DEFAULT): ' -
default 'DEFAULT'
accept force_matching -
prompt 'Enter value for force_matching (false): ' -
default 'false'
set sqlblanklines on
declare
l_profile_name varchar2(30);
cl_sql_text clob;
l_category varchar2(30);
l_force_matching varchar2(3);
b_force_matching boolean;
begin
select
sql_fulltext
into
cl_sql_text
from
v$sqlarea
where
sql_id = '&&sql_id';
select decode('&&profile_name','X0X0X0X0','PROFILE_'||'&&sql_id'||'_MANUAL','&&profile_name')
into l_profile_name
from dual;
/*
don't forget to use Query Block name: "full(tab@sel$1)" for example
and aliases if in use
also, you can specify more than one hint: "full(tab@sel$1) first_rows_1" for example
comma separated hints also work in a direct call
profile => sqlprof_attr(‘ALL_ROWS’,'IGNORE_OPTIM_EMBEDDED_HINTS’)
*/
dbms_sqltune.import_sql_profile(
sql_text => cl_sql_text,
profile => sqlprof_attr('&hint'),
category => '&&category',
name => l_profile_name,
-- use force_match => true
-- to use CURSOR_SHARING=SIMILAR
-- behaviour, i.e. match even with
-- differing literals
force_match => &&force_matching
);
dbms_output.put_line('Profile '||l_profile_name||' created.');
end;
/
undef profile_name
undef sql_id
undef category
undef force_matching