添加 '数据库/oracle/oracle查询最近执行的sql.md'
This commit is contained in:
parent
3ef735afc8
commit
695d180b92
1 changed files with 42 additions and 0 deletions
42
数据库/oracle/oracle查询最近执行的sql.md
Normal file
42
数据库/oracle/oracle查询最近执行的sql.md
Normal file
|
@ -0,0 +1,42 @@
|
|||
#### 查看 Oracle 正在执行的 sql 语句以及发起的用户
|
||||
```sql
|
||||
SELECT b.sid oracleID,
|
||||
b.username 用户名,
|
||||
b.serial#,
|
||||
paddr,
|
||||
sql_text 正在执行的SQL,
|
||||
b.machine 计算机名称
|
||||
FROM v$process a, v$session b, v$sqlarea c
|
||||
WHERE a.addr = b.paddr
|
||||
AND b.sql_hash_value = c.hash_value
|
||||
```
|
||||
|
||||
#### 查询当前用户正在执行的SQL
|
||||
```sql
|
||||
select a.sid,
|
||||
a.serial#,
|
||||
a.paddr,
|
||||
a.machine,
|
||||
nvl(a.sql_id, a.prev_sql_id) sql_id,
|
||||
b.sql_text,
|
||||
b.sql_fulltext,
|
||||
b.executions,
|
||||
b.first_load_time,
|
||||
b.last_load_time,
|
||||
b.last_active_time,
|
||||
b.disk_reads,
|
||||
b.direct_writes,
|
||||
b.buffer_gets
|
||||
from v$session a, v$sql b
|
||||
where a.username = sys_context('USERENV', 'CURRENT_USER')
|
||||
and a.status = 'ACTIVE'
|
||||
and nvl(a.sql_id, a.prev_sql_id) = b.sql_id;
|
||||
|
||||
```
|
||||
|
||||
#### 查看1小时内执行的sql语句,并按照执行时间倒序排序
|
||||
```sql
|
||||
select s.LAST_ACTIVE_TIME,s.SQL_TEXT,s.SQL_FULLTEXT,s.FIRST_LOAD_TIME,s.LAST_LOAD_TIME,s.EXECUTIONS from v$sql s
|
||||
where s.SQL_TEXT like '%DUAL%' and s.LAST_ACTIVE_TIME>sysdate-1/24
|
||||
order by s.LAST_ACTIVE_TIME desc
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue