原创转载请注明出处
SQL TUNING ADVISOR是10G中顾问构架中的一个重要组建,除了使用EM来进行使用还可以使用语句来使用,主要目的在于看看ORACLE给出的SQL优化建议,但是好像不是每次都有效。如果能100%有用也不需要人为优化,不管如何我感觉可以一试。一下是完成这个任务的过程
1、创建调整任务
---define
DECLARE
my_task_name VARCHAR2 (30);
my_sqltext CLOB;
BEGIN
my_sqltext := 'select * from pp,pp2 order by 1,2,3,4';
my_task_name := dbms_sqltune.create_tuning_task (sql_text=> my_sqltext,
bind_list => null,
user_name => 'sys',
scope => 'COMPREHENSIVE',
time_limit => 60,
task_name => 'TEST_tuning_task',
description => 'Tuning Task'
);
END;
2、执行调整任务
---execute
exec dbms_sqltune.execute_tuning_task('TEST_tuning_task');
3、查看执行情况
---checek
SELECT status FROM USER_ADVISOR_TASKS WHERE lower(task_name) ='test_tuning_task';
select * from user_advisor_tasks;
---report
SET LONG 999999
set serveroutput on size 999999
SET LINESIZE 1000
SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST_tuning_task') FROM DUAL;
4、删除调整任务
---drop
exec dbms_sqltune.drop_tuning_task('TEST_tuning_task');