3 RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
4 END IF;
5 END;
6 /
SQL>SET TERM OFF;
Execute coe_xfr_sql_profile_6chcc0pvvhqqm_3617692013.sql
on TARGET system in order to create a custom SQL Profile
with plan 3617692013 linked to adjusted sql_text.
COE_XFR_SQL_PROFILE completed.
从输出可以看出,生成一个名为coe_xfr_sql_profile_6chcc0pvvhqqm_3617692013.sql的脚本。
b. 用coe_xfr_sql_profile.sql生成索引扫描SQL对应的脚本
SQL>@scripts/coe_xfr_sql_profile.sql
Parameter 1:
SQL_ID (required)
Enter value for 1: 2ufquy7xs5nm5
PLAN_HASH_VALUE AVG_ET_SECS
--------------- -----------
1369807930 .001
Parameter 2:
PLAN_HASH_VALUE (required)
Enter value for 2: 1369807930
Values passed to coe_xfr_sql_profile:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID : "2ufquy7xs5nm5"
PLAN_HASH_VALUE: "1369807930"
SQL>BEGIN
2 IF :sql_text IS NULL THEN
3 RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
4 END IF;
5 END;
6 /
SQL>SET TERM OFF;
SQL>BEGIN
2 IF :other_xml IS NULL THEN
3 RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
4 END IF;
5 END;
6 /
SQL>SET TERM OFF;
Execute coe_xfr_sql_profile_2ufquy7xs5nm5_1369807930.sql
on TARGET system in order to create a custom SQL Profile
with plan 1369807930 linked to adjusted sql_text.
COE_XFR_SQL_PROFILE completed.
从输出可以看出,生成一个名为coe_xfr_sql_profile_2ufquy7xs5nm5_1369807930.sql的脚本。
c. 把后生成的脚本里的Outline Data部分的Hint组合替换到先生成的脚本里,即下图红框部分内容
d. 执行coe_xfr_sql_profile_6chcc0pvvhqqm_3617692013.sql脚本
zx@MYDB>@coe_xfr_sql_profile_6chcc0pvvhqqm_3617692013.sql
zx@MYDB>REM
zx@MYDB>REM $Header: 215187.1 coe_xfr_sql_profile_6chcc0pvvhqqm_3617692013.sql 11.4.4.4 2017/02/28 carlos.sierra $
zx@MYDB>REM
zx@MYDB>REM Copyright (c) 2000-2012, Oracle Corporation. All rights reserved.
zx@MYDB>REM
zx@MYDB>REM AUTHOR
zx@MYDB>REM carlos.sierra@oracle.com
zx@MYDB>REM
zx@MYDB>REM SCRIPT
zx@MYDB>REM coe_xfr_sql_profile_6chcc0pvvhqqm_3617692013.sql
zx@MYDB>REM
zx@MYDB>REM DESCRIPTION
zx@MYDB>REM This script is generated by coe_xfr_sql_profile.sql
zx@MYDB>REM It contains the SQL*Plus commands to create a custom
zx@MYDB>REM SQL Profile for SQL_ID 6chcc0pvvhqqm based on plan hash
zx@MYDB>REM value 3617692013.
zx@MYDB>REM The custom SQL Profile to be created by this script
zx@MYDB>REM will affect plans for SQL commands with signature
zx@MYDB>REM matching the one for SQL Text below.
zx@MYDB>REM Review SQL Text and adjust accordingly.
zx@MYDB>REM
zx@MYDB>REM PARAMETERS
zx@MYDB>REM None.
zx@MYDB>REM
zx@MYDB>REM EXAMPLE
zx@MYDB>REM SQL> START coe_xfr_sql_profile_6chcc0pvvhqqm_3617692013.sql;
zx@MYDB>REM
zx@MYDB>REM NOTES
zx@MYDB>REM 1. Should be run as SYSTEM or SYSDBA.
zx@MYDB>REM 2. User must have CREATE ANY SQL PROFILE privilege.
zx@MYDB>REM 3. SOURCE and TARGET systems can be the same or similar.
zx@MYDB>REM 4. To drop this custom SQL Profile after it has been created:
zx@MYDB>REM EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE('coe_6chcc0pvvhqqm_3617692013');
zx@MYDB>REM 5. Be aware that using DBMS_SQLTUNE requires a license
zx@MYDB>REM for the Oracle Tuning Pack.
zx@MYDB>REM 6. If you modified a SQL putting Hints in order to produce a desired
zx@MYDB>REM Plan, you can remove the artifical Hints from SQL Text pieces below.
zx@MYDB>REM By doing so you can create a custom SQL Profile for the original
zx@MYDB>REM SQL but with the Plan captured from the modified SQL (with Hints).
zx@MYDB>REM
zx@MYDB>WHENEVER SQLERROR EXIT SQL.SQLCODE;
zx@MYDB>REM
zx@MYDB>VAR signature NUMBER;
zx@MYDB>VAR signaturef NUMBER;
zx@MYDB>REM
zx@MYDB>DECLARE
2 sql_txt CLOB;
3 h SYS.SQLPROF_ATTR;
4 PROCEDURE wa (p_line IN VARCHAR2) IS
5 BEGIN
6 DBMS_LOB.WRITEAPPEND(sql_txt, LENGTH(p_line), p_line);
7 END wa;
8 BEGIN
9 DBMS_LOB.CREATETEMPORARY(sql_txt, TRUE);
10 DBMS_LOB.OPEN(sql_txt, DBMS_LOB.LOB_READWRITE);
11 -- SQL Text pieces below do not have to be of same length.
12 -- So if you edit SQL Text (i.e. removing temporary Hints),
13 -- there is no need to edit or re-align unmodified pieces.
14 wa(q'[select /*+no_index(t1 idx_t1) */ * from t1 where n=1 ]');
15 DBMS_LOB.CLOSE(sql_txt);
16 h := SYS.SQLPROF_ATTR(
17 q'[BEGIN_OUTLINE_DATA]',
18 q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
19 q'[OPTIMIZER_FEATURES_ENABLE('11.2.0.1')]',
20 q'[DB_VERSION('11.2.0.1')]',
21 q'[ALL_ROWS]',
22 q'[OUTLINE_LEAF(@"SEL$1")]',
23 q'[INDEX(@"SEL$1" "T1"@"SEL$1" ("T1"."N"))]',
24 q'[END_OUTLINE_DATA]');
25 :signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);
26 :signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt, TRUE);
27 DBMS_SQLTUNE.IMPORT_SQL_PROFILE (
28 sql_text => sql_txt,
29 profile => h,
30 name => 'coe_6chcc0pvvhqqm_3617692013',
31 description => 'coe 6chcc0pvvhqqm 3617692013 '||:signature||' '||:signaturef||'',
32 category => 'DEFAULT',
33 validate => TRUE,
34 replace => TRUE,