Monday, June 28, 2010

sample code for load top AWR sql into sql plan baseline

--in this example we load top 30 sql inside AWR snapshot 710 to 714 , into sql tuning set , followed by loaded and create as sql plan baseline.

EXEC DBMS_SQLTUNE.DROP_SQLSET('tset1');
EXEC DBMS_SQLTUNE.CREATE_SQLSET('tset1');

DECLARE
 baseline_cursor DBMS_SQLTUNE.SQLSET_CURSOR;
 my_plans PLS_INTEGER;
BEGIN
 OPEN baseline_cursor FOR
    SELECT VALUE(p)
    FROM TABLE (DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY(
                  710,714,
                   NULL, NULL,
                   'elapsed_time',
                   NULL, NULL, NULL,
                   30)) p;

    DBMS_SQLTUNE.LOAD_SQLSET(
             sqlset_name     => 'tset1',
             populate_cursor => baseline_cursor);
    my_plans := DBMS_SPM.LOAD_PLANS_FROM_SQLSET( sqlset_name => 'tset1');
END;
/