如何为 oracle select 查询计时

发布于 2024-10-02 23:39:01 字数 328 浏览 4 评论 0原文

找出 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吻泪 2024-10-09 23:39:01

在 SQL*Plus 中,您还可以使用简单的 TIMING 选项:

SQL> SET TIMING ON
SQL> SELECT bla FROM bla...
...
Elapsed: 00:00:00:01
SQL> SELECT bar FROM foo...
...
Elapsed: 00:00:23:41
SQL> SET TIMING OFF

这将单独报告每个语句的计时信息。

另一种选择是设置单独的计时器:

SQL> TIMING START mytimer
SQL> ... run all my scripts ...
SQL> TIMING STOP
timinig for: mytimer
Elapsed: 00:00:08.32

您甚至可以嵌套这些单独的计时器 - TIMING STOP 将最近的计时器从堆栈中弹出。

In SQL*Plus you can also use the simple TIMING option:

SQL> SET TIMING ON
SQL> SELECT bla FROM bla...
...
Elapsed: 00:00:00:01
SQL> SELECT bar FROM foo...
...
Elapsed: 00:00:23:41
SQL> SET TIMING OFF

This will report timing information for each statement individually.

Another option is to set up individual timers:

SQL> TIMING START mytimer
SQL> ... run all my scripts ...
SQL> TIMING STOP
timinig for: mytimer
Elapsed: 00:00:08.32

You can even nest these individual timers - the TIMING STOP pops the most recent timer off a stack.

梦在深巷 2024-10-09 23:39:01

我能想到的有几种方法。

我通常通过使用 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 named MIKE_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.

天赋异禀 2024-10-09 23:39:01

我想到的选项:

a)使用外部选择,如果优化器破坏它,这可能不完全准确,但可以提供一个好主意:

SELECT COUNT(*) from (
    SELECT a.code, NVL(a.org, ' '), NVL(a.office_number, ' '), SUBSTR(a.code, 0, 2) 
    FROM PARTICIPANT a WHERE a.type_code = 'PRIME'
);

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:

SELECT COUNT(*) from (
    SELECT a.code, NVL(a.org, ' '), NVL(a.office_number, ' '), SUBSTR(a.code, 0, 2) 
    FROM PARTICIPANT a WHERE a.type_code = 'PRIME'
);

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).

御守 2024-10-09 23:39:01

您可以转到 V$SQL,其中有以下列:

APPLICATION_WAIT_TIME
CONCURRENCY_WAIT_TIME
CLUSTER_WAIT_TIME
USER_IO_WAIT_TIME
PLSQL_EXEC_TIME
CPU_TIME
ELAPSED_TIME

但它们是该 SQL 的所有执行的聚合。如果没有其他人运行 SQL,您可以创建之前/之后的快照并计算出差异。

You can go to V$SQL where you have the following columns :

APPLICATION_WAIT_TIME
CONCURRENCY_WAIT_TIME
CLUSTER_WAIT_TIME
USER_IO_WAIT_TIME
PLSQL_EXEC_TIME
CPU_TIME
ELAPSED_TIME

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.

回眸一遍 2024-10-09 23:39:01

只是不显示查询结果

SET TERMOUT OFF

Just do not display query results

SET TERMOUT OFF
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文