Find out the history of SQL queries Find out the history of SQL queries oracle oracle

Find out the history of SQL queries


    select v.SQL_TEXT,           v.PARSING_SCHEMA_NAME,           v.FIRST_LOAD_TIME,           v.DISK_READS,           v.ROWS_PROCESSED,           v.ELAPSED_TIME,           v.service      from v$sql vwhere to_date(v.FIRST_LOAD_TIME,'YYYY-MM-DD hh24:mi:ss')>ADD_MONTHS(trunc(sysdate,'MM'),-2)

where clause is optional. You can sort the results according to FIRST_LOAD_TIME and find the records up to 2 months ago.


For recent SQL:

select * from v$sql

For history:

select * from dba_hist_sqltext


You can use this sql statement to get the history for any date:

SELECT * FROM V$SQL V where  to_date(v.FIRST_LOAD_TIME,'YYYY-MM-DD hh24:mi:ss') > sysdate - 60