手动使用10g Tuning Adviser

A、没有绑定变量的情况:
                
                   1、
SQL> DECLARE
                             l_sql               VARCHAR2(500);
                               l_sql_tune_task_id  VARCHAR2(100);
                            BEGIN
                               l_sql := 'select /*We will trace this sql*/ name,addr,insertdata from
                          (select name,addr,insertdata,rank() over(partition by name,addr order by
                          insertdatadesc) rn from t ) where rn = 1';
                              l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
                                                       sql_text    => l_sql,
                                                       user_name   => 'TEST',
                                                      scope       => DBMS_SQLTUNE.scope_comprehensive,
                                                    time_limit  => 60,
                                                      task_name   => 'test_tuning_task',
                                                      description => 'Tuning task for an a simple query.');
                             DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
                            END;
                            /
                       
                        PL/SQL 过程已成功完成。
                        
                     2、 SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'test_tuning_task');
                       
                        PL/SQL 过程已成功完成。
                        
                     3、SQL> SELECT DBMS_SQLTUNE.report_tuning_task('test_tuning_task') AS recommendations FROM dual;
       

 B、有绑定变量的情况:                        
                        SQL> variable var_1 number;
                        SQL> variable var_2 number;
                        SQL> variable var_3 number;
                        SQL> exec :var_1 := 5;
                        SQL> exec :var_2 := 4;                        
                        SQL> exec :var_3 := 3;                        
                        SQL> select id,name,addr from t where id<>:var_1 and id<:var_2 and id<:var_3;
                       
                                ID NAME                 ADDR
                        ---------- -------------------- --------------------
                                 1 张                   北京
                                 2 张                   北京
                       
                        SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'TEST';
                       
                        TASK_NAME                      STATUS
                        ------------------------------ -----------
                        ADDM:1184202927_1_201          COMPLETED
                        ADDM:1184202927_1_202          COMPLETED
                        test_tuning_task                           COMPLETED
                       
                        SQL> BEGIN
                               DBMS_SQLTUNE.drop_tuning_task (task_name => 'test_tuning_task');
                          END;
                           /                        
                        SQL>
                        SQL>
                        SQL> DECLARE
                             l_sql               VARCHAR2(500);
                            l_sql_tune_task_id  VARCHAR2(100);
                           BEGIN
                             l_sql := 'select id,name,addr from t where id<>:var_1 and id<:var_2 and i
                        d<:var_3';
                                                      l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
                                                   sql_text    => l_sql,
                                                       bind_list   => sql_binds(anydata.ConvertNumber(5),
                  anydata.ConvertNumber(4),anydata.ConvertNumber(3)),
                                                      user_name   => 'TEST',
                                                      scope       => DBMS_SQLTUNE.scope_comprehensive,
                                                      time_limit  => 60,
                                                      task_name   => 'test_tuning_task',
                                                      description => 'Tuning task for an a simple query
                        .');
                              DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
                             END;
                            /
                        
                        SQL> SELECT * FROM DBA_SQLTUNE_BINDS;

                           TASK_ID  OBJECT_ID   POSITION VALUE()
                        ---------- ---------- ---------- --------------------
                               393          1          1 ANYDATA()
                               393          1          2 ANYDATA()
                               393          1          3 ANYDATA()
      
                        SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'test_tuning_task');
                       
                        PL/SQL 过程已成功完成。
                       
                        SQL> SELECT DBMS_SQLTUNE.report_tuning_task('test_tuning_task') AS recommendatio
                        ns FROM dual;

转自:http://www.itpub.net/thread-1019685-1-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值