您好,登录后才能下订单哦!
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。