如何为 oracle select 查询计时
找出 oracle select 语句花费多少时间的最佳方法是什么?我有以下查询,我想找出时间,但是,由于此查询带来了 4000 条记录,并且需要时间在屏幕上显示这 4000 条记录,因此规定的经过时间可能不正确。
有没有办法可以将其包装到游标中,然后从 sql plus 运行它,以便获得执行此操作所需的正确时间?
SELECT a.code, NVL(a.org, ' '), NVL(a.office_number, ' '), SUBSTR(a.code, 0, 2)
FROM PARTICIPANT a WHERE a.type_code = 'PRIME';
what is the best way to find out how much time an oracle select statement takes. I have the following query for which I want to find out the time, however, since this query brings four thousand records and it takes time to display those 4 thousand records on the screen, the elapsed time stated might not be correct.
Is there a way I can wrap this into a cursor and then run it from sql plus so that I get the correct time it takes to execute this?
SELECT a.code, NVL(a.org, ' '), NVL(a.office_number, ' '), SUBSTR(a.code, 0, 2)
FROM PARTICIPANT a WHERE a.type_code = 'PRIME';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 SQL*Plus 中,您还可以使用简单的 TIMING 选项:
这将单独报告每个语句的计时信息。
另一种选择是设置单独的计时器:
您甚至可以嵌套这些单独的计时器 -
TIMING STOP
将最近的计时器从堆栈中弹出。In SQL*Plus you can also use the simple TIMING option:
This will report timing information for each statement individually.
Another option is to set up individual timers:
You can even nest these individual timers - the
TIMING STOP
pops the most recent timer off a stack.我能想到的有几种方法。
我通常通过使用
CREATE TABLE AS SELECT....
将其运行到表中来完成此类操作,这意味着我经常在架构中散布许多名为MIKE_TEMP_1
的表。SQL*Plus 中的另一个选项是使用 SET AUTOTRACE TRACEONLY ,它应该运行所有查询,但禁止打印结果。
There are a couple of ways I can think of.
I normally do this sort of thing by running it into a table with
CREATE TABLE AS SELECT....
, which means I often litter my schema with many tables namedMIKE_TEMP_1
.Other option is in SQL*Plus to use
SET AUTOTRACE TRACEONLY
which should run all the query but suppress the printing of the results.我想到的选项:
a)使用外部选择,如果优化器破坏它,这可能不完全准确,但可以提供一个好主意:
b)将其放入脚本中,从命令行运行它并将输出重定向到一个文件。
c) 打开线轴并关闭 termout(不确定这一点)。
d)
设置 autotrace traceonly
(@MikeyByCrikey 击败了我)。Options that spring to mind:
a) use an outer select, which may not be entirely accurate if the optimizer mangles it but can give a good idea:
b) put it in a script, run it from the command line and redirect the output to a file.
c) turn spool on and termout off (not sure about that one).
d)
set autotrace traceonly
(which @MikeyByCrikey beat me to).您可以转到 V$SQL,其中有以下列:
但它们是该 SQL 的所有执行的聚合。如果没有其他人运行 SQL,您可以创建之前/之后的快照并计算出差异。
You can go to V$SQL where you have the following columns :
but they are an aggregate for all executions of that SQL. You can do a before/after snapshot and work out the difference if no-one else is running the SQL.
只是不显示查询结果
Just do not display query results