您好,登錄后才能下訂單哦!
grant advisor to user;
grant select_catalog_role to user; --通過OEM管理必不可少
grant execute on dbms_sqltune to user;
此時分兩種情況,一種是在v$sql中存在的SQL,一種是在v$sql中不存在的SQL
跟據SQL_ID取v$sql中bind_data的值
select position, value_string
from table(dbms_sqltune.extract_binds('beda0a200500521ffd700'));
select dbms_sqltune.extract_bind(bind_data,1).value_string || '-' ||
dbms_sqltune.extract_bind(bind_data, 2).value_string || '-' ||
dbms_sqltune.extract_bind(bind_data, 3).value_string || '-' ||
dbms_sqltune.extract_bind(bind_data, 4).value_string || '-' ||
dbms_sqltune.extract_bind(bind_data, 5).value_string || '-' ||
dbms_sqltune.extract_bind(bind_data, 6).value_string
from sys.wrh$_sqlstat
where sql_id = '1nnrufx6sw8sd'
DECLARE
my_task_name VARCHAR2(30);
my_sqltext CLOB;
BEGIN
my_sqltext := 'select * from emp where ename=:name and DEPTNO= :deptno';
my_task_name :=DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_text => my_sqltext,
bind_list => sql_binds(anydata.convertvarchar2(10),anydata.convertnumber(2)),
user_name => 'TEST',
scope => 'COMPREHENSIVE',
time_limit => 60,
task_name =>'test_sql_tuning',
description => 'Task to tune a query on emp');
END;
/
declare
my_task_name VARCHAR2(30);
my_sqltext CLOB;
BEGIN
my_sqltext := 'select * fromorabpel.cube_scope';
my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_text => my_sqltext,
user_name => 'orabpel',
scope => 'COMPREHENSIVE',
time_limit => 60, --優化限時60s
task_name => 'wxw_sql_tuning_task',
description => 'tune thebad sql');
dbms_sqltune.Execute_tuning_task(task_name =>'TEST_sql_tuning_task');
END;
這種情況通常常用于v$sql中的異常SQL優化
DECLARE
my_task_name VARCHAR2(40);
BEGIN
my_task_name := DBMS_SQLTUNE.create_tuning_task(
sql_id => '1hudpukz651tt',
plan_hash_value => NULL,
scope => dbms_sqltune.SCOPE_COMPREHENSIVE,
time_limit => dbms_sqltune.TIME_LIMIT_DEFAULT,
task_name => 'test_sql_tuning_1hudpukz651tt',
description => '1hudpukz651tt');
DBMS_SQLTUNE.EXECUTE_TUNING_TASK(task_name => 'test_sql_tuning_1hudpukz651tt');
dbms_output.put_line(my_task_name);
END;
declare
my_task_name varchar2(30);
begin
my_task_name := dbms_sqltune.create_tuning_task(
begin_snap => 24365,
end_snap => 24366,
sql_id =>'d40kghyfbg8sj',
plan_hash_value => null,
scope =>'comprehensive',
time_limit => 60,
task_name =>'wxw_sql_tuning_task',
description => 'tune thebad sql'
);
dbms_sqltune.execute_tuning_task (task_name =>'wxw_sql_tuning_task');
end;
---execute
execdbms_sqltune.execute_tuning_task('TEST_tuning_task');
---checek
SELECT status FROM USER_ADVISOR_TASKS WHERElower(task_name) ='test_tuning_task';
select * from user_advisor_tasks;
---report
SET LONG 999999
set serveroutput on size 999999
SET LINESIZE 1000
SELECTDBMS_SQLTUNE.REPORT_TUNING_TASK('TEST_tuning_task') FROM DUAL;
---drop
execdbms_sqltune.drop_tuning_task('TEST_tuning_task');
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。