column a_date       new_value newdate
select to_char(sysdate,'yyyymmdd_hh24miss') as a_date from dual;
col a_dbid           new_value newdbid
select dbid a_dbid from v$database;

column a_snap_id new_value v_snap_id
set echo on;
select min(snap_id) a_snap_id from sys.WRM$_SNAPSHOT where begin_interval_time>=(sysdate-30);
select '&&newdate' var_date, &&newdbid var_dbid, &&v_snap_id var_snap_id from dual;

select start_interval_time, end_interval_time from sys.WRM$_SNAPSHOT where snap_id=&&v_snap_id;

ALTER SESSION SET TRACEFILE_IDENTIFIER = "ADBA_AWR_PURGE_&newdate";

EXEC DBMS_MONITOR.session_trace_enable;

EXEC DBMS_MONITOR.session_trace_enable(waits=>TRUE, binds=>TRUE);

select value ||'/'||(select instance_name from v$instance) ||'_ora_'||
        (select spid||case when traceid is not null then '_'||traceid else null end
              from v$process where addr = (select paddr from v$session
                                          where sid = (select sid from v$mystat
                                                     where rownum = 1
                                                )
                                     )
        ) || '.trc' tracefile
 from v$parameter where name = 'user_dump_dest';

EXEC dbms_workload_repository.drop_snapshot_range(1,&&v_snap_id,&&newdbid); 

EXEC DBMS_MONITOR.session_trace_disable;