oracle查询正在执行的sql以及时间,查询Oracle正在执行和执行过的SQL语句

查询Oracle正在执行和执行过的SQL语句

---正在执行的

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

from v$sqlarea b

where b.FIRST_LOAD_TIME between '2014-12-01/09:00:00' and

'2014-12-30/09:00:00' order by b.FIRST_LOAD_TIME

(此方法好处可以查看某一时间段执行过的sql,并且 SQL_FULLTEXT 包含了完整的 sql 语句)

其他

select OSUSER,PROGRAM,USERNAME,SCHEMANAME,B.Cpu_Time,STATUS,B.SQL_TEXT

from V$SESSION A LEFT JOIN V$SQL B ON A.SQL_ADDRESS=B.ADDRESS AND A.SQL_HASH_VALUE=B.HASH_VALUE order by b.cpu_time desc

select address, sql_text, piece

from v$session, v$sqltext

where address = sql_address

-- and machine = < you machine name >

order by address, piece

查找前十条性能差的sql.

你可能感兴趣的:(oracle查询正在执行的sql以及时间,查询Oracle正在执行和执行过的SQL语句)