找出 SQL 查询的历史记录

在服务器上执行了更新SQL查询,导致后来出现很多问题.

An update SQL query was executed on the server, which caused many problems later.

如何获取最近 2 个月执行的更新查询列表,以便我可以准确跟踪有问题的 SQL 查询?

How can I get the list of update queries executed in last 2 months, so that I can trace the exact problematic SQL query?

推荐答案

    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 v
where to_date(v.FIRST_LOAD_TIME,'YYYY-MM-DD hh24:mi:ss')>ADD_MONTHS(trunc(sysdate,'MM'),-2)

where 子句是可选的.可以根据FIRST_LOAD_TIME对结果进行排序,查找最多2个月前的记录.

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

相关文章