"select * from (
 with fsq as (
  select /*+ materialize */
   i.dbid
    , i.instance_name
    , i.instance_number
--    , trunc(s.snap_time, 'DD')     DAY
--    , to_number(to_char(s.snap_time, 'HH24'))  HOUR
--   -- , to_char(s.snap_time, 'MI')    MINUTE
--    , 0           MINUTE
    , trunc( 
      lag(s.snap_time, 1)
      over(
       partition by
      v.dbid
       , i.instance_name
       , v.instance_number
       , v.event
     order by 
      s.snap_time
      )
      , 'HH24'
     )           SNAP_TIME
    , v.event_type        EVENT_TYPE
    , v.event          EVENT_NAME
    , nvl(
    decode(
     greatest(
      time_waited_micro,
      nvl(
       lag(time_waited_micro,1,0)
       over(
        partition by 
         v.dbid
          , i.instance_name
          , v.instance_number
          , v.event
        order by v.snap_id
       )
       , time_waited_micro
      )
     ),
     time_waited_micro,
     time_waited_micro - lag(time_waited_micro,1,0)
     over (
      partition by
       v.dbid
        , i.instance_name
        , v.instance_number
        , v.event
      order by v.snap_id
     ),
     time_waited_micro
    )
       , time_waited_micro
     ) / 1000000         SECONDS_SPENT
    , total_waits         WAIT_COUNT
  from
   (select distinct dbid, instance_name, instance_number from stats$database_instance) i
    , stats$snapshot s
    , ( select 
     snap_id, dbid, instance_number, 'WAIT' event_type, event, time_waited_micro, total_waits 
    from 
     stats$system_event
    where
     event not in (select event from stats$idle_event)
    union all
    select 
     snap_id, dbid, instance_number, 
     case 
      when name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage') then 'CPU'
      when name like 'OS % time' then 'OS'
      else 'STAT'
     end, 
     name , value, 1
    from
     stats$sysstat
--    where      name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage')
--    or  name like('OS % time')
--    or 1 = 2 -- this will be a bind variable controlling whether all stats need to be returned
   ) v
  where
   i.dbid = s.dbid 
  and i.dbid = v.dbid
  and s.dbid = v.dbid 
  and s.snap_id = v.snap_id
  and s.snap_time between trunc(%FROM_DATE%) and %TO_DATE%
  and i.instance_name = '%INSTANCE%'
 )
 select * from (
  select 
   instance_name
    , instance_number
    , snap_time
    , trunc(snap_time, 'DD')  DAY
    , to_char(snap_time, 'HH24') HOUR
    , to_char(snap_time, 'MI') MINUTE       
    , event_type   
    , event_name   
    , seconds_spent
    , wait_count   
    , ratio_to_report(seconds_spent) over (
--      partition by (to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09'))
      partition by (snap_time)
      ) ratio
  from fsq
  where 
   snap_time is not null -- lag(s.snap_time, 1) function above will leave time NULL for first snapshot
  -- to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09') 
  -- > ( select min(to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')) from fsq)
 ) 
 where ratio > 0
 and %FILTER%
 order by
    instance_name
  , instance_number
  , day
  , hour
  , minute
  , event_type
  , seconds_spent desc
  , wait_count desc
)"

"SELECT
   snap_id
 , dbid
 , instance_number
 , sample_id
 , to_char(sample_time, 'YYYYMMDD') sample_day
 , to_char(sample_time, 'HH24')     sample_hour
 , to_char(sample_time, 'MI')       sample_minute
 , session_id
 , session_serial#
 , user_id
 , sql_id
 , sql_child_number
 , sql_plan_hash_value
 , service_hash
 , session_type
 , sql_opcode
 , qc_session_id
 , qc_instance_id
 , current_obj#
 , current_file#
 , current_block#
 , seq#
 , event_id
 , p1
 , p2
 , p3
 , wait_time
 , time_waited
 , program
 , module
 , action
 , client_id
FROM
   dba_hist_active_sess_history h
WHERE
   h.sample_time BETWEEN sysdate - 1 AND sysdate
"

"select
   sample_id
 , to_char(sample_time, 'YYYYMMDD HH24:MI') sample_time
 , session_id
 , session_serial#
 , user_id
 , sql_id
 , sql_child_number
 , sql_plan_hash_value
 , sql_opcode
 , service_hash
 , session_type
 , session_state
 , qc_session_id
 , qc_instance_id
 , event
 , event_id
 , event#
 , seq#
 , p1
 , p2
 , p3
 , wait_time
 , time_waited
 , current_obj#
 , current_file#
 , current_block#
 , program
 , module
 , action
 , client_id
from 
 v$active_session_history 
where 
 sample_time between sysdate - 1/24 and sysdate 
order by 
 sample_time
"

"SELECT
 TRUNC(h.sample_time, 'DD')  day,
 TO_CHAR(h.sample_time, 'HH24') hour,
 TO_CHAR(h.sample_time, 'MI') minute,
-- MAX(h.instance_number)   instance_number,
-- MAX(h.session_id)    session_id,
-- MAX(u.user_id)     user_id,
-- MAX(h.sql_id)     sql_id,
-- MAX(s.name service_name)  service_name,
-- MAX(e.name event_name)   event_name,
-- SUM(h.wait_time)    wait_time,
-- SUM(h.time_waited)    time_waited,
-- SUM(h.wait_time + h.time_waited) total_wait,
-- MAX(h.program)     program,
-- MAX(h.module)     module,
-- MAX(h.action)     action,
-- MAX(h.client_id)    client_id
    (h.instance_number)    instance_number,
    (h.session_id)     session_id,
    (h.qc_session_id)    qc_session_id,
    (u.username)     username,
    (h.sql_id)      sql_id,
    (s.name)      service_name,
    (e.name)      event_name,
    (h.program)      program,
    (h.module)      module,
    (h.action)      action,
    (h.client_id)     client_id,
    COUNT(qc_session_id)/6   px_sess_count, -- divided by 6 as theres one sample per 10 seconds in dba_hist_active_sess_history
    SUM(h.wait_time)    wait_time,
    SUM(h.time_waited)    time_waited,
    SUM(h.wait_time + h.time_waited)/1000000 total_sec
--
FROM 
 dba_hist_active_sess_history h,
 dba_users u,
 dba_services s,
 v$event_name e
--
WHERE
-- join pred
 u.user_id = h.user_id
AND h.service_hash = s.name_hash
AND h.event_id = e.event_id
-- filter pred
AND sample_time between %FROM_DATE% and %TO_DATE%
--
GROUP BY
 h.sample_time,
 h.instance_number,
 h.session_id,  
 h.qc_session_id,
 u.username,     
 h.sql_id,      
 s.name,
 e.name,  
 h.program,     
 h.module,      
 h.action,      
 h.client_id    
--
ORDER BY
 sample_time
"

"SELECT
 TRUNC(h.sample_time, 'DD')  day,
 TO_CHAR(h.sample_time, 'HH24') hour,
 ':'||SUBSTR(TO_CHAR(h.sample_time, 'MI'),1,1)||'0' minute,
   MAX(h.instance_number)   instance_number,
--   MAX(h.session_id)    session_id,
   MAX(qc_session_id)    qc_session_id,
   MAX(u.user_id)     user_id,
   MAX(h.sql_id)     sql_id,
   MAX(s.name)  service_name,
   MAX(e.name)  event_name,
   SUM(h.wait_time)    wait_time,
   SUM(h.time_waited)    time_waited,
   SUM(h.wait_time + h.time_waited) total_wait,
   MAX(h.program)     program,
   MAX(h.module)     module,
   MAX(h.action)     action,
   COUNT(qc_session_id)/60   px_sess_count,
   MAX(h.client_id)    client_id
--- (h.instance_number)    instance_number,
--- (h.session_id)     session_id,
--- (h.qc_session_id)    qc_session_id,
--- (u.username)     username,
--- (h.sql_id)      sql_id,
--- (s.name)      service_name,
--- (e.name)      event_name,
--- (h.program)      program,
--- (h.module)      module,
--- (h.action)      action,
--- (h.client_id)     client_id,
--- COUNT(qc_session_id)/60   px_sess_count, -- divided by 60 as theres one sample per 10 seconds in dba_hist_active_sess_history
--- SUM(h.wait_time)    wait_time,           -- and we want 10 minute samples
--- SUM(h.time_waited)    time_waited,
--- SUM(h.wait_time + h.time_waited)/1000000 total_sec
--
FROM 
 dba_hist_active_sess_history h,
 dba_users u,
 dba_services s,
 v$event_name e
--
WHERE
-- join pred
 u.user_id = h.user_id
AND h.service_hash = s.name_hash
AND h.event_id = e.event_id
AND h.qc_session_id IS NOT NULL
AND h.qc_session_id != 0
-- filter pred
AND sample_time between %FROM_DATE% and %TO_DATE%
AND s.name != 'SYS$BACKGROUND'
--AND h.dbid = (select dbid from dba_hist_snapshot where rownum = 1)
--AND h.snap_id IN 
--  (select snap_id from dba_hist_snapshot 
--   where begin_interval_time >= %FROM_DATE%
--   and   end_interval_time <= %TO_DATE%)
--
GROUP BY
 h.sample_time,
 TRUNC(h.sample_time, 'DD'),
 TO_CHAR(h.sample_time, 'HH24'),
 ':'||SUBSTR(TO_CHAR(h.sample_time, 'MI'),1,1)||'0',
 h.instance_number,
-- h.session_id,  
 h.qc_session_id,
 u.username,     
 h.sql_id,      
 s.name,
-- e.name,  
-- h.program,     
 h.module,      
 h.action,      
 h.client_id    
--
--HAVING
--   COUNT(qc_session_id)/60 >= 0.2
--
ORDER BY
 sample_time

"

"select * from dba_hist_sysmetric_summary
where begin_time between %FROM_DATE% and %TO_DATE%"

"SELECT
 TRUNC(h.sample_time, 'DD')  day,
 TO_CHAR(h.sample_time, 'HH24') hour,
 ':'||SUBSTR(TO_CHAR(h.sample_time, 'MI'),1,1)||'0' minute,
   MAX(h.instance_number)   instance_number,
--   MAX(h.session_id)    session_id,
   MAX(qc_session_id)    qc_session_id,
   MAX(u.user_id)     user_id,
   MAX(h.sql_id)     sql_id,
   MAX(s.name)  service_name,
   MAX(e.name)  event_name,
   SUM(h.wait_time)    wait_time,
   SUM(h.time_waited)    time_waited,
   SUM(h.wait_time + h.time_waited) total_wait,
   MAX(h.program)     program,
   MAX(h.module)     module,
   MAX(h.action)     action,
   COUNT(qc_session_id)/60   px_sess_count,
   MAX(h.client_id)    client_id
--- (h.instance_number)    instance_number,
--- (h.session_id)     session_id,
--- (h.qc_session_id)    qc_session_id,
--- (u.username)     username,
--- (h.sql_id)      sql_id,
--- (s.name)      service_name,
--- (e.name)      event_name,
--- (h.program)      program,
--- (h.module)      module,
--- (h.action)      action,
--- (h.client_id)     client_id,
--- COUNT(qc_session_id)/60   px_sess_count, -- divided by 60 as theres one sample per 10 seconds in dba_hist_active_sess_history
--- SUM(h.wait_time)    wait_time,           -- and we want 10 minute samples
--- SUM(h.time_waited)    time_waited,
--- SUM(h.wait_time + h.time_waited)/1000000 total_sec
--
FROM 
 dba_hist_snapshot sn,
 dba_hist_active_sess_history h,
 dba_users u,
 dba_services s,
 v$event_name e
--
WHERE
-- join pred
 u.user_id = h.user_id
AND h.service_hash = s.name_hash
AND h.event_id = e.event_id
AND h.qc_session_id IS NOT NULL
AND h.qc_session_id != 0
-- filter pred
AND h.sample_time between %FROM_DATE% and %TO_DATE%
AND sn.begin_interval_time >= %FROM_DATE%
AND sn.end_interval_time <= %TO_DATE%
AND sn.snap_id = h.snap_id
AND s.name != 'SYS$BACKGROUND'
--AND h.dbid = (select dbid from dba_hist_snapshot where rownum = 1)
--AND h.snap_id IN 
--  (select snap_id from dba_hist_snapshot 
--   where begin_interval_time >= %FROM_DATE%
--   and   end_interval_time <= %TO_DATE%)
--
GROUP BY
 h.sample_time,
 TRUNC(h.sample_time, 'DD'),
 TO_CHAR(h.sample_time, 'HH24'),
 ':'||SUBSTR(TO_CHAR(h.sample_time, 'MI'),1,1)||'0',
 h.instance_number,
-- h.session_id,  
 h.qc_session_id,
 u.username,     
 h.sql_id,      
 s.name,
-- e.name,  
-- h.program,     
 h.module,      
 h.action,      
 h.client_id    
--
--HAVING
--   COUNT(qc_session_id)/60 >= 0.2
--
ORDER BY
 sample_time

"

"select 
 to_char(sample_time, 'MM-DD') day, 
 to_char(sample_time, 'HH24') hour, 
 to_char(sample_time, 'MI') minute, 
 substr(event,1,40) event, 
-- count(distinct sample_time) samples, 
 sum(cnt)/60*3 cnt 
from 
 sawr$session_wait_hist 
where 
 sample_time between %FROM_DATE% and %TO_DATE% 
group by 
 to_char(sample_time, 'MM-DD'), 
 to_char(sample_time, 'HH24'), 
 to_char(sample_time, 'MI'), 
 event 
order by 
 minute asc, cnt desc
"

"select
 to_char(timestamp, 'YYYY-MM-DD')  day,
 count(*)        sessions,
 sum((logoff_time - timestamp)*86400)/2 sum_time, -- division by 2 because there's
 avg((logoff_time - timestamp)*86400)/2 avg_time, -- 2 sessions involved in replication push
 sum(session_cpu)/100     sum_cpu,
 avg(session_cpu)/100     avg_cpu
from 
 t1
-- dba_audit_session
where 
 os_username = 'oracle'
and username = 'REPADMIN' 
and timestamp between %FROM_DATE% and %TO_DATE%
and %FILTER%
group by 
 to_char(timestamp, 'YYYY-MM-DD')
order by 1
"

"select
 '""'||to_char(timestamp, 'YYYY-MM-DD HH24')||':00""' hour,
 count(*)        sessions,
 sum((logoff_time - timestamp)*86400)/2 sum_time, -- division by 2 because there's          
 avg((logoff_time - timestamp)*86400)/2 avg_time, -- 2 sessions involved in replication push
 sum(session_cpu)/100     sum_cpu,
 avg(session_cpu)/100     avg_cpu
from 
 t1
-- dba_audit_session
where 
 os_username = 'oracle'
and username = 'REPADMIN' 
and timestamp between %FROM_DATE% and %TO_DATE%
and %FILTER%
group by 
 '""'||to_char(timestamp, 'YYYY-MM-DD HH24')||':00""'
order by 1
"

"select
 to_char(timestamp, 'YYYY-MM-DD')  day,
 count(*)        sessions,
 sum((logoff_time - timestamp)*86400)/2 sum_time, -- division by 2 because there's
 avg((logoff_time - timestamp)*86400)/2 avg_time, -- 2 sessions involved in replication push
 sum(session_cpu)/100     sum_cpu,
 avg(session_cpu)/100     avg_cpu
from 
 t2
-- dba_audit_session
where 
 os_username = 'oracle'
and username = 'REPADMIN' 
and timestamp between %FROM_DATE% and %TO_DATE%
and %FILTER%
group by 
 to_char(timestamp, 'YYYY-MM-DD')
order by 1
"

select * from delta$filestatxs order by snap_id

"SELECT
 sn.snap_time,
 sql.*
FROM
 stats$snapshot sn,
 delta$sql_summary sql
WHERE
 sn.snap_id = sql.snap_id
AND sn.snap_time between %FROM_DATE% and %TO_DATE%
AND sql.cpu_time >= 10000000
ORDER BY
 sn.snap_time ASC, sql.cpu_time desc"

"select  
-- yyyymmddhh24,
 day,
 hr,
 type,
 name,
 secs
-- pct_total*100 pct_total,
-- sum(pct_total*100) over (partition by yyyymmddhh24
--     order by hourly_ranking
--     rows unbounded preceding) cum_pct_total
from (
select
  to_char(ss.snap_time, 'YYYYMMDDHH24') yyyymmddhh24,
  to_char(ss.snap_time, 'YYYY-MM-DD') day,
  to_char(ss.snap_time, 'HH24')||':'||to_char(ss.snap_time, 'MI') hr,
  s.type,
  s.name,
  sum(s.secs) secs,
  ratio_to_report(sum(s.secs))
   over (partition by to_char(ss.snap_time, 'YYYYMMDDHH24')) pct_total,
  rank () over (partition by to_char(ss.snap_time, 'YYYYMMDDHH24')
    order by sum(s.secs) desc) hourly_ranking
  from   (select dbid,
   instance_number,
   snap_id,
   'Wait' type,
   event name,
   nvl(decode(greatest(time_waited_micro,
         nvl(lag(time_waited_micro,1,0)
      over (partition by dbid,
           instance_number,
           event
       order by snap_id),time_waited_micro)),
       time_waited_micro,
       time_waited_micro - lag(time_waited_micro,1,0)
      over (partition by dbid,
           instance_number,
           event
      order by snap_id),
     time_waited_micro), time_waited_micro)/1000000 secs
   from stats$system_event
   where time_waited_micro > 0
   and event not in (select event from stats$idle_event)
   union all
    select t.dbid,
   t.instance_number,
   t.snap_id,
   'CPU' type,
                 'SQL execution' name,
   nvl(decode(greatest(t.value,
         nvl(lag(t.value,1,0)
      over (partition by t.dbid,
           t.instance_number
       order by t.snap_id),t.value)),
       t.value,
       (t.value - (p.value + r.value)) - lag((t.value - (p.value + r.value)),1,0)
      over (partition by t.dbid,
           t.instance_number
      order by t.snap_id),
     (t.value - (p.value + r.value))),
       (t.value - (p.value + r.value)))/100 secs
          from   stats$sysstat t,
                 stats$sysstat p,
                 stats$sysstat r
          where t.dbid = p.dbid
          and r.dbid = t.dbid
          and t.instance_number = p.instance_number
          and r.instance_number = t.instance_number
          and t.snap_id = p.snap_id
          and r.snap_id = t.snap_id
   and t.name = 'CPU used by this session'
          and p.name = 'recursive cpu usage'
          and r.name = 'parse time cpu'
   union all
   select dbid,
   instance_number,
   snap_id,
   'CPU' type,
   'Recursive SQL execution' name,
   nvl(decode(greatest(value,
         nvl(lag(value,1,0)
      over (partition by dbid,
           instance_number
       order by snap_id),value)),
       value,
       value - lag(value,1,0)
      over (partition by dbid,
           instance_number
      order by snap_id),
     value), value)/100 secs
   from   stats$sysstat
   where  name = 'recursive cpu usage'
   and    value > 0
   union all
   select dbid,
   instance_number,
   snap_id,
    'CPU' type,
   'Parsing SQL' name,
   nvl(decode(greatest(value,
         nvl(lag(value,1,0)
      over (partition by dbid,
           instance_number
       order by snap_id),value)),
       value,
       value - lag(value,1,0)
      over (partition by dbid,
           instance_number
      order by snap_id),
     value), value)/100 secs
   from   stats$sysstat
   where  name = 'parse time cpu'
   and    value > 0)   s,
  stats$snapshot    ss,
  (select distinct dbid,
     instance_number,
     instance_name
   from stats$database_instance)        i
  where i.instance_name = '%INSTANCE%'
  and s.dbid = i.dbid
  and s.instance_number = i.instance_number
  and ss.snap_id = s.snap_id
  and    ss.dbid = s.dbid
  and    ss.instance_number = s.instance_number
  and    ss.snap_time between trunc(%FROM_DATE%) and %TO_DATE%
  group by 
   to_char(ss.snap_time, 'YYYYMMDDHH24'),
    to_char(ss.snap_time, 'YYYY-MM-DD'),
    to_char(ss.snap_time, 'HH24')||':'||to_char(ss.snap_time, 'MI'),    s.type,
    s.name
  having sum(s.secs) > 0
  order by yyyymmddhh24, secs
)
where
 yyyymmddhh24 not in (select to_char(min(snap_time), 'YYYYMMDDHH24') 
       from stats$snapshot 
       where dbid = (
       select distinct dbid 
       from stats$database_instance 
       where instance_name = '%INSTANCE%'
       )
      )
and hourly_ranking <= 6
and %FILTER%
order by
  yyyymmddhh24,
  hourly_ranking
"

"select * from (
 with fsq as (
  select /*+ materialize */
   i.dbid
    , i.instance_name
    , i.instance_number
--    , trunc(s.snap_time, 'DD')     DAY
--    , to_number(to_char(s.snap_time, 'HH24'))  HOUR
--   -- , to_char(s.snap_time, 'MI')    MINUTE
--    , 0           MINUTE
    , trunc( 
      lag(s.snap_time, 1)
      over(
       partition by
      v.dbid
       , i.instance_name
       , v.instance_number
       , v.event
     order by 
      s.snap_time
      )
      , 'HH24'
     )           SNAP_TIME
    , v.event_type        EVENT_TYPE
    , v.event          EVENT_NAME
    , nvl(
    decode(
     greatest(
      time_waited_micro,
      nvl(
       lag(time_waited_micro,1,0)
       over(
        partition by 
         v.dbid
          , i.instance_name
          , v.instance_number
          , v.event
        order by v.snap_id
       )
       , time_waited_micro
      )
     ),
     time_waited_micro,
     time_waited_micro - lag(time_waited_micro,1,0)
     over (
      partition by
       v.dbid
        , i.instance_name
        , v.instance_number
        , v.event
      order by v.snap_id
     ),
     time_waited_micro
    )
       , time_waited_micro
     ) / 1000000         SECONDS_SPENT
    , total_waits         WAIT_COUNT
  from
   (select distinct dbid, instance_name, instance_number from stats$database_instance) i
    , stats$snapshot s
    , ( select 
     snap_id, dbid, instance_number, 'WAIT' event_type, event, time_waited_micro, total_waits 
    from 
     stats$system_event
    where
     event not in (select event from stats$idle_event)
    union all
    select 
     snap_id, dbid, instance_number, 
     case 
      when name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage') then 'CPU'
      when name like 'OS % time' then 'OS'
      else 'STAT'
     end, 
     name , value, 1
    from
     stats$sysstat
--    where      name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage')
--    or  name like('OS % time')
--    or 1 = 2 -- this will be a bind variable controlling whether all stats need to be returned
   ) v
  where
   i.dbid = s.dbid 
  and i.dbid = v.dbid
  and s.dbid = v.dbid 
  and s.snap_id = v.snap_id
  and s.snap_time between trunc(%FROM_DATE%) and %TO_DATE%
  and i.instance_name = '%INSTANCE%'
 )
 select * from (
  select 
   instance_name
    , instance_number
    , snap_time
    , trunc(snap_time, 'DD')  DAY
    , to_char(snap_time, 'HH24') HOUR
    , to_char(snap_time, 'MI') MINUTE       
    , event_type   
    , event_name   
    , seconds_spent
    , wait_count   
    , ratio_to_report(seconds_spent) over (
--      partition by (to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09'))
      partition by (snap_time)
      ) ratio
  from fsq
  where 
   snap_time is not null -- lag(s.snap_time, 1) function above will leave time NULL for first snapshot
  -- to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09') 
  -- > ( select min(to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')) from fsq)
 ) 
 where ratio > 0
 order by
    instance_name
  , instance_number
  , day
  , hour
  , minute
  , event_type
  , seconds_spent desc
  , wait_count desc
)"

select rownum/10 rn, sin(rownum/10) wave from dual connect by level <= 200 order by rownum

"select
   sample_id
 , to_char(sample_time, 'YYYYMMDD HH24:MI') sample_time
 , session_id
 , session_serial#
 , user_id
 , sql_id
 , sql_child_number
 , sql_plan_hash_value
 , sql_opcode
 , service_hash
 , session_type
 , session_state
 , qc_session_id
 , qc_instance_id
 , event
 , event_id
 , event#
 , seq#
 , p1
 , p2
 , p3
 , wait_time
 , time_waited
 , current_obj#
 , current_file#
 , current_block#
 , program
 , module
 , action
 , client_id
from 
 v$active_session_history 
where 
 sample_time between sysdate - 1/24/4 and sysdate 
order by 
 sample_time
"

"select * from (select
    to_char(sn.begin_interval_time, 'YYYY-MM-DD HH24:MI') begin_time,
    st.*
from
    dba_hist_snapshot sn
  , dba_hist_sqlstat st
where
    sn.snap_id = st.snap_id
and sn.dbid = st.dbid
and sn.instance_number = st.instance_number
and sn.begin_interval_time > %FROM_DATE%)"

