Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to time an oracle select query

Tags:

oracle

plsql

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';
like image 365
learn_plsql Avatar asked Nov 17 '10 16:11

learn_plsql


People also ask

How do I time a SQL query?

Using Client StatisticsGo to Menu >> Query >> Select Include client Statistics. Execute your query. In the results panel, you can see a new tab Client Statistics. Go to the Client Statistics tab to see the execution time.

How do you know the time taken to execute a query in Oracle?

Answer: For seeing the elapsed time for an individual query, you can see individual query response time in SQL*Plus with the "set timing on" command. For DBA's, Oracle has several tools for measuring system-wide response time using v$sysmetric, v$active_session_history, v$sqlarea and v$sysmetric_summary.


2 Answers

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.

like image 177
Jeffrey Kemp Avatar answered Sep 28 '22 01:09

Jeffrey Kemp


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.

like image 21
Mike Meyers Avatar answered Sep 28 '22 00:09

Mike Meyers