如何检索以前的sql命令
想问一下如何检索该会话中我过去的所有数据库 sql 查询?谢谢
would like to ask how to retrieve all my past database sql queries within that session? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很确定 Oracle 不会保留每个会话的所有过去查询(关闭的游标)的数据。不过,我可以想出几种方法来获取此数据:
如果您使用 PL/SQL,则大多数过去的游标将保留在会话缓存中(直到
cursor_sharing
初始化)范围)。可以查询视图v$open_cursor
:将此视图加入到
v$sqltext
(或v$sqltext_with_newlines
)以获取完整的sql文本:您可以跟踪您的会话,在会话终止后打开生成的跟踪文件将显示所有 SQL(此外,您可以 tkprof 跟踪文件以获取摘要和统计信息)。
I'm pretty sure Oracle doesn't keep data on all past queries (closed cursors) for each session. I can think of a couple of ways to get this data however:
If you're using PL/SQL, most of your past cursors will remain in your session cache (up to the
cursor_sharing
initialization parameter). You can query the viewv$open_cursor
:Join this view to
v$sqltext
(orv$sqltext_with_newlines
) to get the full sql text:You could trace your session, opening the resulting trace file once the session terminates will reveal all SQL (furthermore, you can tkprof the trace file to get a summary and statistics).
正如 Vincent 指出的,唯一的方法是(据我所知)在客户端级别跟踪会话。
除了打开游标(Toad 就是这样做的)之外,另一种不太精确的方法是使用 ASH(活动会话历史记录)。
ASH 的问题在于
这是因为它只是为了“捕获”长时间运行的查询以提高性能。
然而,如果人们只对响应时间较长的查询感兴趣,那么它就很适合。
无论如何,这是一个简单的查询,返回会话的长查询历史记录。
As Vincent pointed out the only way would be (afaik) to trace the session at the client level.
In addition to the open cursors (which is how Toad does it), another, less precise, way would be to use ASH (Active Session History).
The problems with ASH are that
This is because it's only meant to "catch" long running queries for performance purpose.
It is well adapted however if one is only interested in the queries with long response time.
For what it's worth, here is a simple query returning a session's history of long queries.