Search notes:

DBA_HIST_ACTIVE_SESS_HISTORY: Query duration of SQL statement executions

with ash as (
   select
      ash.sample_time, -- ash.sample_time_utc,
      ash.sql_exec_start,
      ash.user_id,
      -- 
      row_number() over (partition by ash.session_id, ash.session_serial#, ash.sql_id, ash.sql_exec_id, dbid order by ash.sample_time     ) first_rec_for_sql_exec,
      row_number() over (partition by ash.session_id, ash.session_serial#, ash.sql_id, ash.sql_exec_id, dbid order by ash.sample_time desc)  last_rec_for_sql_exec,
      --
      ash.sql_id, ash.sql_child_number, ash.sql_exec_id,
      ash.dbid, ash.con_dbid
   from
      sys.dba_hist_active_sess_history     ash                           
)
select
   ash.sql_id, ash.sql_child_number, ash.sql_exec_id,
   ash.sql_exec_start,
   usr.username,
   min (case when ash.first_rec_for_sql_exec =1 then ash.sample_time end) first_sample_time,
   max (case when ash. last_rec_for_sql_exec =1 then ash.sample_time end)  last_sample_time,
   cast(substr(txt.sql_text, 1, 1000) as varchar2(1000)),
   count(*)                                                           cnt_samples
from
   ash                                                                         left join
   sys.dba_hist_sqltext                 txt on ash.sql_id   = txt.sql_id  and
                                               ash.dbid     = txt.dbid    and
                                               ash.con_dbid = txt.con_dbid     left join
   sys.dba_users                        usr on ash.user_id  = usr.user_id
group by
   ash.sql_id, ash.sql_child_number, ash.sql_exec_id,
   ash.sql_exec_start,
   usr.username,
   cast(substr(txt.sql_text, 1, 1000) as varchar2(1000))
-- where
--    lower(substr(ash.sql_text, 1, 1000)) like '%insert %tq84_table%'
order by
   min (case when ash.first_rec_for_sql_exec =1 then ash.sample_time end) desc
;

See also

dba_hist_active_sess_history

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759612596, '216.73.216.149', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/installed/data-dictionary/hist/active_sess_history/sql-statement-duration(72): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78