如何查看针对 Oracle 执行的查询?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3237916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I see queries that are executed against Oracle?
提问by vld_apos
I need to see the queries that are being sent to Oracle to execute them. Can someone give me specific detailed instructions on how to do this ?
我需要查看发送到 Oracle 以执行它们的查询。有人可以给我关于如何做到这一点的具体详细说明吗?
回答by bhangm
If you want to see the queries from a specific user, you can use this (assuming you have privileges to query v$session
and v$sqlarea
(usually through SELECT_CATALOG_ROLE
)
如果您想查看来自特定用户的查询,您可以使用它(假设您有权限查询v$session
和v$sqlarea
(通常通过SELECT_CATALOG_ROLE
)
SELECT sess.sid,
sess.username,
sqla.optimizer_mode,
sqla.hash_value,
sqla.address,
sqla.cpu_time,
sqla.elapsed_time,
sqla.sql_text
FROM v$sqlarea sqla, v$session sess
WHERE sess.sql_hash_value = sqla.hash_value
AND sess.sql_address = sqla.address
AND sess.username = 'SCOTT'
Replace SCOTT with the appropriate username in your system
用系统中适当的用户名替换 SCOTT
Output:
输出:
544 SCOTT ALL_ROWS 2004330732 07000001064088E8 89391 131836 SELECT sess.sid, sess.username,
sqla.optimizer_mode, sqla.h
ash_value, sqla.address, s
qla.cpu_time, sqla.elapsed_time,
sqla.sql_text FROM v$sqlarea sq
la, v$session sess WHERE sess.sql_hash_
value = sqla.hash_value AND sess.sql_
address = sqla.address AND sess.usern
ame = 'SCOTT'
回答by Tony Andrews
This query will show queries that are currently running:
此查询将显示当前正在运行的查询:
select sql_text from v$sqlarea where users_executing > 0;