Oracle获取最近执行的SQL语句

注意:不是每次执行的语句都会记录(如果执行的语句是能在该表找到的则ORACLE不会再次记录,就是说本次执行的语句和上次或者说以前的语句一模一样则下面语句就查不出来的):

select  last_load_time, sql_text from v$sql 
where module not in ('jsenv.exe','w3wp.exe','SQL Developer') 
--and sql_text like '%"Extent1"."ENCOUNTERID"%' 
order by last_load_time desc;

select sql_text,last_load_time from v$sql order by last_load_time desc;

SELECT   sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and (sql_text like 'select%' or sql_text like 'SELECT%') ORDER BY last_load_time DESC;

SELECT   sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and sql_text like 'update%' ORDER BY last_load_time DESC;

SELECT   sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and last_load_time like' 2017-6-9%' ORDER BY last_load_time DESC;

select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
  from v$session a, v$sqlarea b 
where a.sql_address = b.address; 
---执行过的
select b.SQL_TEXT,b.FIRST_LOAD_TIME,b.SQL_FULLTEXT,b.FIRST_LOAD_TIME
from v$sqlarea b
where b.FIRST_LOAD_TIME between to_date('2017-06-09 13:24:47','yyyy-mm-dd hh24:mi:ss') and to_date('2017-06-10 13:24:47','yyyy-mm-dd hh24:mi:ss')
order by b.FIRST_LOAD_TIME;
--(此方法好处可以查看某一时间段执行过的sql,并且 SQL_FULLTEXT 包含了完整的 sql 语句)

 

    原文作者:Chr☆s
    原文地址: https://www.cnblogs.com/chriskwok/p/6978042.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞