Compare time taken by sqls
Hi experts,
Can any one refer me any tool or utility by which i can get time taken by different sql's without using explain plan..
Regards,
SKP
If you are running it from SQL*Plus, just set timing on
SQL> set timing on
SQL> select empno,ename from emp where deptno=10;
EMPNO ENAME
7782 CLARK
7839 KING
7934 MILLER
Elapsed: 00:00:01.97
SQL> select empno,ename from emp where deptno=20;
EMPNO ENAME
7369 SMITH
7566 JONES
7788 SCOTT
7876 ADAMS
7902 FORD
Elapsed: 00:00:01.91
SQL>
Similar Messages
-
How to find the time taken for creating execution plan alone
Hi,
Is there any way to find out the division between the time taken for query parsing, creating execution plan and actual data retrieval seperately? If I enable 'set timing on' I see the elapsed time which is the total time taken for all these 3.
Some of my queries are taking long time when I run it first time and so want to know what is it taking long, is it the parsing the query or creating the execution plan? (Since my queries run faster second time, I am assuming the major part was for parsing or creating the plan but not the data retrieval).
Also, where does Oracle keep the execution plan? Is it in the BUFFER_CACHE? if so, I tried flushing the buffer_cache and restarting the DB as well, but still the query execution seems faster compared to the first time. How long does Oracle keep the execution plan in the cache and is there anyway to increase this cache size?
Thanks in advance!user13169027 wrote:
Hi,
Is there any way to find out the division between the time taken for query parsing, creating execution plan and actual data retrieval seperately? If I enable 'set timing on' I see the elapsed time which is the total time taken for all these 3.
Some of my queries are taking long time when I run it first time and so want to know what is it taking long, is it the parsing the query or creating the execution plan? (Since my queries run faster second time, I am assuming the major part was for parsing or creating the plan but not the data retrieval).
The ideal way for finding the answer to your questions above, would be to perform a (sql) trace of your query executions. To see the difference in the trace-files, you might want to trace the first execution in one session, and the second execution in another session: so you get two different trace files, which you can then seperately tkprof, and investigate.
Also, where does Oracle keep the execution plan? Is it in the BUFFER_CACHE? if so, I tried flushing the buffer_cache and restarting the DB as well, but still the query execution seems faster compared to the first time. How long does Oracle keep the execution plan in the cache and is there anyway to increase this cache size?
Execution plans are held in the shared-pool, not the buffer-cache. As far as I know they will be kept in memory in an LRU way (least recently used), just like db-blocks are in the buffer-pool (I know this is not entirely correct, but for all practical purposes, think of it this way). -
Query regarding the ActiveSync and parameter time-taken from ActiveSync IIS logs.
Here what I see for from the logs.
[email protected] 45.101.90.185 Apple-iPad2C3/1202.410 200 0 0 1501129
443 [email protected] 45.101.90.185 Apple-iPad2C3/1202.410 200
0 0 22105
443 [email protected] 45.101.90.185 Apple-iPad2C3/1202.410 200
0 0 452
443 [email protected] 45.101.90.185 Apple-iPad2C3/1202.410 200
0 0 936
443 [email protected] 45.101.90.185 Apple-iPad2C3/1202.410 200
0 0 656238
In the above log, highlighted are the time-taken and I just want to check what is the ideal time-taken value, some value above should be causing some problem, like the one of the top 1501129 ?
?AND I see its for POST event and CMD=Ping&log query.......
We have Mobile Iron in the environment and we are seeing few timeout errors on MobileIron server and for users intermittently. They usually see below error... However we don't see any end users issues, but just want to get rid of below error. MobileIron guys
are pointing it to time-taken value which is high intermittently.
IOException connection to server [email protected] -- java.io.IOException:
awaitUninterruptibly was stopped by timeout
@BALAHi,
To understand more about the issue, I’d like to confirm the following information:
1. What’s your Exchange 2010 version?
http://support.microsoft.com/kb/2536517/en-us
2. Do you install other software, like SQL, on the same Exchange Server?
3. Change another admin account to access EMS.
Thanks,
Angela Shi
TechNet Community Support -
Query Execution time - Elapsed time v Actual time taken
Hi All,
I have this scenario where I am querying a single table with the following results. It is a very heavy query in that there are multiple aggregate functions and multiple unions on it. Even if the query is written poorly (i doubt it is) why would the actual
time taken to execute the query be much more than the statistics provided through the following commands?
SET STATISTICS IO ON;
SET STATISTICS TIME ON;
Attached are the stats provided for the relevant query in question.
Table '123456789_TEMP_DATA'. Scan count 178, logical reads 582048, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 936 ms, elapsed time = 967 ms.
2014-01-06 17:36:41.383
Now, although the CPU Time/Elapsed time shows that it takes less than a second, it actually takes more than 15 seconds to fetch the results. (This is the actual time that you get on the bottom bar of the Query pane as well.)
What is the reason? Why is it that there is such a big discrepancy between the numbers? How can I improve this situation?
Thanks!Yes. I am returning a huge number of rows to the client.
The query is simply against a single table.
Select
'First Record',AVG(COLUMN1),STDEV(COLUMN1
),COUNT(COLUMN1)
FROM [TABLE1] WHERE (SOME CONDITION)
UNION ALL
Select 'Second Record',AVG(COLUMN2),STDEV(COLUMN2),COUNT(COLUMN2) FROM [TABLE1]
WHERE (SOME OTHER CONDITION)
Imagine there are 178 records fetched in this manner with 178 UNIONs. The WHERE clause will always change for each SELECT statement.
Now, the question is not so much about the query itself, but why the execution time is actually 15 seconds whilst the SQL STATISTICS show it to be 936ms (<1 second)
Thanks! -
Time taken in each section of Mapping
Hi All,
One of my mappings is taking a very long to execute in production db. Is there anyway/ any table which lets me view the times taken for each step in the mapping?
I tried to use Debug mode by opening the mapping in OWB but the debug mode is a lot slower than the mapping itself when deployed - hence i am not able to know accurately where the actual problem might be.
thanks.Hi
The OWB browser has runtime reports that will let you see the steps and timings.
There are a bunch of reports in the blog here on the runtime audit tables that you can use in SQLDeveloper, or just rip off the SQL;
http://blogs.oracle.com/warehousebuilder/2010/10/owb_sql_reports_in_code_samples.html
Download the zip, either use SQLDev with the reports or take the file OWBReports.xml and look at the SQL in it and use wherever.
Cheers
David -
How we can store start time & end time taken by execution of scenerio?
Hi
i want to store starting time and ending time taken by executing of any scenerio and date also on which scenerio will be executed.
plz assist me regards the same
thankswhen you say store , you want to capture in some file ,email or table.
If table , you can have a small sql linking SNP_SESSION and SNP_SCEN and fetching the required detail accordingly. -
Got a mac book pro a month back, the bootup time taken now is much more as compared to earlier. Requesting some possible solutions.
Thanks,
SidLinc,
As per your instructions, these were the messages that were logged in the first few minutes after start up.
Jul 17 21:17:18 localhost com.apple.launchd[1]: *** launchd[1] has started up. ***
Jul 17 21:17:37 localhost com.apple.usbmuxd[22]: usbmuxd-211 built on Feb 8 2011 at 13:49:43 on Feb 8 2011 at 13:49:43, running 64 bit
Jul 17 21:17:39 localhost bootlog[41]: BOOT_TIME: 1310917638 0
Jul 17 21:17:39 localhost mDNSResponder[29]: mDNSResponder mDNSResponder-258.21 (May 26 2011 14:40:13) starting
Jul 17 21:17:39 localhost configd[13]: bootp_session_transmit: bpf_write(en1) failed: Network is down (50)
Jul 17 21:17:39 localhost configd[13]: DHCP en1: INIT-REBOOT transmit failed
Jul 17 21:17:39 Siddharth-Jaswas-MacBook-Pro configd[13]: setting hostname to "Siddharth-Jaswas-MacBook-Pro.local"
Jul 17 21:17:39 Siddharth-Jaswas-MacBook-Pro configd[13]: network configuration changed.
Jul 17 21:17:42 Siddharth-Jaswas-MacBook-Pro blued[16]: Apple Bluetooth daemon started
Jul 17 21:17:43 Siddharth-Jaswas-MacBook-Pro /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow[30]: Login Window Application Started
Jul 17 21:17:43 Siddharth-Jaswas-MacBook-Pro com.apple.kextd[10]: Can't load /System/Library/Extensions/IOSerialFamily.kext/Contents/PlugIns/InternalModemSu pport.kext - no code for running kernel's architecture.
Jul 17 21:17:43 Siddharth-Jaswas-MacBook-Pro com.apple.kextd[10]: Failed to load /System/Library/Extensions/IOSerialFamily.kext/Contents/PlugIns/InternalModemSu pport.kext - (libkern/kext) requested architecture/executable not found.
Jul 17 21:17:43 Siddharth-Jaswas-MacBook-Pro com.apple.kextd[10]: Load com.apple.driver.InternalModemSupport failed; removing personalities.
Jul 17 21:17:44 Siddharth-Jaswas-MacBook-Pro loginwindow[30]: Login Window Started Security Agent
Jul 17 21:17:45 Siddharth-Jaswas-MacBook-Pro loginwindow[30]: Login Window - Returned from Security Agent
Jul 17 21:17:45 Siddharth-Jaswas-MacBook-Pro loginwindow[30]: USER_PROCESS: 30 console
Jul 17 21:17:45 Siddharth-Jaswas-MacBook-Pro com.apple.launchd.peruser.501[86] (com.apple.ReportCrash): Falling back to default Mach exception handler. Could not find: com.apple.ReportCrash.Self
Jul 17 21:17:45 Siddharth-Jaswas-MacBook-Pro configd[13]: network configuration changed.
Jul 17 21:17:50 Siddharth-Jaswas-MacBook-Pro com.apple.launchd.peruser.501[86] (com.apple.Kerberos.renew.plist[110]): Exited with exit code: 1
Jul 17 21:17:50 Siddharth-Jaswas-MacBook-Pro com.apple.usbmuxd[22]: HandleUSBMuxDictionary client 0x101800ab0-iTunesHelper/com.apple.iTunesHelper using library usbmuxd-211 built on Jan 13 2011 at 04:19:31, running usbmuxd-211 built on Feb 8 2011 at 13:49:43
Jul 17 21:18:10 Siddharth-Jaswas-MacBook-Pro [0x0-0xf00f].com.google.Chrome[140]: [0717/211810:INFO:breakpad_mac.mm(89)] Breakpad disabled
Jul 17 21:18:16 Siddharth-Jaswas-MacBook-Pro [0x0-0xf00f].com.google.Chrome[140]: [140:519:54119099370:ERROR:CONSOLE(6465)] "Uncaught TypeError: Cannot read property 'can_uninstall' of undefined", source: chrome://newtab/ (6465)
Thanks,
Sid -
How to calculate total time taken by a report
I am a beginner in oracle reports,
I want to display in my report these three fields
Report Start Time:
Report End Time:
Time Taken
Although we can find this by Porgrame->Tracing optinon but i want it should display along with my report. Can somebody help me on that.I played around with Raffy's idea for a while, but either because I have an older version of Reports (3.0.5), or I interpreted it wrong, my value in CF_END_TIME was always identical to CP_START_TIME. Even when I put the CF_END_TIME column lower and to the right of any other object in the Data Model.
But I did get it to work, and this is how:
I created a Placeholder column named CP_START_TIME that I loaded with SYSDATE in a function on the Before Report Trigger.
I created a Placeholder column named CP_END_TIME that holds a Date. Then I created a Function Column named CF_ADVANCE_END_TIME that I placed inside the lowest Group Field on my Data Model. This function does nothing more than copy SYSDATE into :CP_END_TIME.
Then I created a Function Column called CF_TIME_TAKEN that compares CP_START_TIME to CP_END_TIME and returns a VARCHAR2 string with the elapsed time.
I put the three non-group Columns on my Trailer page and it looks like:
START TIME Oct 12, 2005 14:47
END TIME Oct 12, 2005 16:00
ELAPSED TIME 0 01:12:47
It bears repeating that the Format Mask of the Placeholder Column needs to specify the smallest increment of time you want measured. That Format Mask is used for Validation, and may truncate your date/time if you don't specify all the fields. I used 'Mon DD, YYYY HH24:MI:SS' for my Placeholder columns, and 'Mon DD, YYYY HH24:MI' for the fields that display them. -
How to identify time taken to execute a package
Hi all,
Is the method without TKPROFF to find the time taken to execute a package that calls a procedure.
for examples
Lets says I execute a packaage at SQLplus window
SQL> Execute my_pack.bal_proc;
(It took some time may be 4 hrs to excecute according to my watch).
At this stage if I want to find the time by some sql command that after executing the package what was the time.
can someone help me in finding a query that tell what was the time taken to execute a package.
thanks n rgds
saazYou can check start and end time
Then end time -start time
SQL> select systimestamp start_time from dual;
START_TIME
11-AUG-09 11.30.47.758282 AM -04:00
SQL> Execute my_pack.bal_proc;
SQL> select systimestamp end_time from dual;
END_TIME
11-AUG-09 11.31.11.207530 AM -04:00Edited by: user5495111 on Aug 11, 2009 8:32 AM -
Time taken for a method to run. ?
I have a query regarding ascertaining the time taken
for a method to execute
I have a SQL statement that I reads 10,000 rows.
String a_SQL = "Select.....from TableA";
try {
IQuery query = m_UC.createQuery();
SimpleTableModel stm = query.executeSelect(a_SQL);
}catch(SQLException se){
// Query Over.
private void displayJTable(){
// display rows read from the query above.
} As the query is executing,I want to display a progress bar
showing the status of the query.
Now I cant use this :
start = System.currentTimeMillis();
try {
IQuery query = m_UC.createQuery();
SimpleTableModel stm = query.executeSelect(a_SQL);
}catch(SQLException se){
end = System.currentTimeMillis();
System.out.println(" Time taken to display " + (end - start)/1000);
The above will give me the time elapsed in seconds for the SQL query to execute,but
this is not what I want.
What i want is to use this :
// Progress BAR executing,so I need to get to know the time
// taken for the query to run
try {
the SQL execution
}cach(){
// Query over.
// Stop Progres Bar.
// Display JTable. How can I know when to stop the Progress Bar as I have no handle
on the time taken to execute the query?
Any help will be appreciatedYou can have a separate thread (or maybe it's just part of the regular GUI update thread? I don't know details about GUIs) that puts up an hourglass or spinning clock hands or dancing hamster or whatever to indicate that something is going on, but like the man says, you can't know ahead of time how long it will take to run a query, so you can't show percent done. You also don't in general know ahead of time how many rows will be returned so that doesn't help you.
You might be able to do something for the processing of the returned data, once the query completes, because then you can often get a count of the number of rows, so you process each row in a loop, and update the % done counter each time through the loop. -
Capturing query time taken inside a proc
Hi ,
select * from v$version
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Solaris: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
=================
I have a few insert and delete statements inside my stored procedure .
I need to cature the time taken by these queries after their run .
Is there any way we can get this . ( Not putting timestamps before and after the query and taking difference )
Thanks ,
MaheshMahesh wrote:
I am looking is there anything like sql%rowcount which gives the count affected or we have set time on in sql*plus which gives the time .Elapsed time in Pl/SQL can be calculated by using DBMS_UTILLITY.GET_TIME
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_util.htm#i1002765
Regards
Peter -
Hello everyone,
i'm given the task to create a vi that do the download firmware in ideal time of 30 secs. Somehow, it's able to perform the work but at the time of 1min3secs.
How can i reduce the time taken for this vi. ?
Thank you.
regards
Attachments:
time_vi.JPG 63 KBMikeS81 wrote:
Hello microes,
do you know how much time every case need? One way could be to enlarge the wait time in the while loop to give the processor more time.
Mike
That probably won't help speed up the process any on the Labview side of the code. The key thing is that there is a wait statement in the while loop to give the processor an opportunity to do other things.. But on the other hand, the loop is only designed to be a visual monitor of progress. So there is no need to poll for the status every millisecond. You could get by with a 500 msec wait statement in that while loop.
I still think most of the time to run is in the CIN blocks. A good idea would be to put a Get time function in each of those case statements and send the data to an indicator. That way after the code runs, you can compare timestamps and see how much time each part of the code is taking. (For the while loop, you could do some averaging functions to track the average loop iteration time.) -
How to show the processing time taken for a BPEL process in BAM report.
Hi All,
I have the data as below in the Data object. I would like to show the time taken for each order to complete in the report.
instance Id order Id product Name product Code price status instance Time updaterName
1360010 ord004 Guitar prod003 2000 requested 9/22/2008 12:12:11 PM Invoke_InsertSalesOrder
1360010 ord004 Guitar prod003 2000 Approved 9/22/2008 12:15:11 PM Invoke_OrderStatusUpdate
This data comes from simple BPEL process where sensors are configured at the start and end of BPEL process. Also have a human task activity in between to create the time difference.
In Enterprise link design studio, I tried to calculate the time difference using expression calculator and store it as calculated field. But that doesn't seems to work because when I execute the plan, second sensor data reaches only after human approval whereas first sensor data would be waiting for calculation and ultimately nothing comes into data object.
How and where the calculation be done to show the processing time in the report. Please someone throw some light on this.
Regards
Jude.
Edited by: user600726 on Sep 30, 2008 1:30 AMI would suggest modifying your data object so that the data can all be in a single row and use the sensor at the end of the process to upsert (update) the row created by the sensor at the start of the process. The time difference between two fields in the same row is then an easy calculation on a BAM report -- No EL plan should be needed.
-
Report to display Average time taken for processing payments".
Hi,
I have been asked to develop a report for "Report to display Average time taken for processing payments".
Could any one guide me technically what are the different tables i need to take to generate the report. Treat this is very urgent. Pls provide sample code too....
Thanks in advance....Given below is the set up for credit card payment processing:
Set Up Credit Control Areas:
Define Credit Control Area
Transaction: OB45
Tables: T014
Action: Define a credit control area and its associated currency. The Update Group should be 00012. This entry is required so the sales order will calculate the value to authorize
Assign Company Code to Credit Control Area
Transaction: OB38
Tables: T001
Action: Assign a default credit control area for each company code
Define Permitted Credit Control Area for a Company
Code
Transaction:
Tables: T001CM
Action: For each company code enter every credit control area that can be used
Identify Credit Price
Transaction: V/08
Tables: T683S
Action: Towards the end of the pricing procedure, after all pricing and tax determination, create a subtotal line to store the value of the price plus any sales tax. Make the following entries:
Sub to: A
Reqt: 2
AltCTy: 4
Automatic Credit Checking
Transaction: OVA8
Tables: T691F
Action: Select each combination of credit control areas, risk categories and document types for which credit checking should be bypassed. You need to mark the field no Credit Check with the valid number for sales documents.
Set Up Payment Guarantees
Define Forms of Payment Guarantee
Transaction: OVFD
Tables: T691K
Action: R/3 is delivered with form 02 defined for payment cards. Other than the descriptor, the only other entry should be 3 in the column labeled PymtGuaCat
Define Payment Guarantee Procedure
Transaction:
Tables: T691M/T691O
Action: Define a procedure and a description.
Forms of Payment Guarantee and make the following entries Sequential Number 1
Payment Guarantee Form 02
Routine Number 0 Routine Number can be used to validate payment card presence.
Define Customer Payment Guarantee Flag
Transaction:
Tables: T691P
Action: Define a flag to be stored in table.
Create Customer Payment Guarantee = Payment Card Payment Cards (All Customers can use Payment Cards).
Define Sales Document Payment Guarantee Flag
Transaction:
Tables: T691R
Action: Define the flag that will be associated with sales document types that are relevant for payment cards
Assign Sales Document Payment Guarantee Flag
Transaction:
Tables: TVAK
Action: Assign the document flag type the sales documents types that are relevant for payment cards.
Determine Payment Guarantee Procedure
Transaction: OVFJ
Tables: T691U
Action: Combine the Customer flag and the sales document flag to derive the payment guarantee procedure
Payment Card Configuration
Define Card Types
Transaction:
Tables: TVCIN
Action: Create the different card types plus the routine that validates the card for length and prefix (etc )
Visa , Mastercard, American Express, and Discover
Create the following entries for each payment card
AMEX American Express ZCCARD_CHECK_AMEX Month
DC Discover Card ZCCARD_CHECK_DC Month*****
MC Mastercard ZCCARD_CHECK_MC Month
VISA Visa ZCCARD_CHECK_VISA Month
The Routines can be created based on the original routines delivered by SAP.
*****SAP does not deliver a card check for Discover Card. We created our own routine.
Define Card Categories
Transaction:
Tables: TVCTY
Action: Define the card category to determine if a
payment card is a credit card or a procurement card.
Create the following two entries
Cat Description One Card Additional Data
CC Credit Cards No-check No-check
PC Procurement Cards No-check Check
Determine Card Categories
Transaction:
Tables: TVCTD
Action: For each card category map the account number range to a card category. Multiple ranges are possible for each card category or a masking technique can be used. Get the card number ranges from user community. Below is just a sample of what I am aware are the different types of cards.
Visa Credit Expires in 7 days.
400000 405500
405505 405549
405555 415927
415929 424603
424606 427532
427534 428799
428900 471699
471700 499999
Visa Procurement Expires in 7 days.
405501 405504
405550 405554
415928 415928
424604 424605
427533 427533
428800 428899
Mastercard Credit Expires in 30 days
500000 540499
540600 554999
557000 599999
Mastercard Procurement Expires in 30 days
540500 540599
555000 556999
American Express Credit Expires in 30 days
340000 349999
370000 379999
Discover Card Credit Expires in 30 days
601100 601199
Set Sales Documents to accept Payment Card Information Transaction:
Tables: TVAK
Action: Review the listing of Sales Document types and enter 03 in the column labeled PT for each type which can accept a payment card
Configuration for Authorization Request
Maintain Authorization Requirements
Transaction: OV9A
Tables: TFRM
Action: Define and activate the abap requirement that determines when an authorization is sent. Note that the following tables are available to be used in the abap requirement (VBAK, VBAP, VBKD, VBUK, and VBUP).
Define Checking Group
Transaction:
Tables: CCPGA
Action: Define a checking group and enter the
description. Then follow the below guidelines for the remaining fields to be filled.
AuthReq Routine 901 is set here.
PreAu If checked R/3 will request an authorization for a .01 and the authorization will be flagged as such. (Insight does not use pre-authorization check).
A horizon This is the days in the future SAP will use to determine the value to authorize
(Insight does not use auth horizon period).
Valid You will get warning message if the payment card is expiring within 30 days of order entry date.
Assign Checking Group to Sales Document
Transaction:
Tables: TVAK
Action: Assign the checking group to the sales order types relevant for payment cards
Define Authorization Validity Periods
Transaction:
Tables: TVCIN
Action: For each card type enter the authorization validity period in days.
AMEX American Express 30
DC Discover card 30
MC Master card 30
VISA Visa 7
Configuration for clearing houses
Create new General Ledger Accounts
Transaction: FS01
Tables:
Action: Two General Ledger accounts need to be created for each payment card type. One for A/R reconciliation purposes and one for credit card clearing.
Maintain Condition Types
Transaction: OV85
Tables: T685
Action: Define a condition type for account determination and assign it to access sequence A001
Define account determination procedure
Transaction: OV86
Tables: T683 / T683S
Action: Define procedure name and select the procedure for control. Enter the condition type defined in the previous step.
Assign account determination procedure
Transaction:
Tables:
Action: Determine which billing type we are using for payment card process.
Authorization and Settlement Control
Transaction:
Tables: TCCAA
Action: Define the general ledger accounts for reconciliation and clearing and assign the function modules for authorization and settlement along with the proper RFC destinations for each.
Enter Merchant IDs
Transaction:
Tables: TCCM
Action: Create the merchant ids that the company uses to process payment cards
Assign merchant ids
Transaction:
Tables: TCCAA
Action: Enter the merchant ids with each clearinghouse account -
How to find out the execution time of a sql inside a function
Hi All,
I am writing one function. There is only one IN parameter. In that parameter, i will pass one SQL select statement. And I want the function to return the exact execution time of that SQL statement.
CREATE OR REPLACE FUNCTION function_name (p_sql IN VARCHAR2)
RETURN NUMBER
IS
exec_time NUMBER;
BEGIN
--Calculate the execution time for the incoming sql statement.
RETURN exec_time;
END function_name;
/Please note that wrapping query in a "SELECT COUNT(*) FROM (<query>)" doesn't necessarily reflect the execution time of the stand-alone query because the optimizer is smart and might choose a completely different execution plan for that query.
A simple test case shows the potential difference of work performed by the database:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
Session altered.
SQL>
SQL> drop table count_test purge;
Table dropped.
Elapsed: 00:00:00.17
SQL>
SQL> create table count_test as select * from all_objects;
Table created.
Elapsed: 00:00:02.56
SQL>
SQL> alter table count_test add constraint pk_count_test primary key (object_id)
Table altered.
Elapsed: 00:00:00.04
SQL>
SQL> exec dbms_stats.gather_table_stats(ownname=>null, tabname=>'COUNT_TEST')
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.29
SQL>
SQL> set autotrace traceonly
SQL>
SQL> select * from count_test;
5326 rows selected.
Elapsed: 00:00:00.10
Execution Plan
Plan hash value: 3690877688
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5326 | 431K| 23 (5)| 00:00:01 |
| 1 | TABLE ACCESS FULL| COUNT_TEST | 5326 | 431K| 23 (5)| 00:00:01 |
Statistics
1 recursive calls
0 db block gets
419 consistent gets
0 physical reads
0 redo size
242637 bytes sent via SQL*Net to client
4285 bytes received via SQL*Net from client
357 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5326 rows processed
SQL>
SQL> select count(*) from (select * from count_test);
Elapsed: 00:00:00.00
Execution Plan
Plan hash value: 572193338
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 5 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| PK_COUNT_TEST | 5326 | 5 (0)| 00:00:01 |
Statistics
1 recursive calls
0 db block gets
16 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>As you can see the number of blocks processed (consistent gets) is quite different. You need to actually fetch all records, e.g. using a PL/SQL block on the server to find out how long it takes to process the query, but that's not that easy if you want to have an arbitrary query string as input.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle:
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/
Maybe you are looking for
-
How do I import video from a DVD-RAM disc?
Hello-- I'm not sure this is the right place to ask this question, but... I have a Panasonic DVD recorder and I recorded something on a DVD-RAM disc. I was hoping I could import the video to iMovie, or even play the video on my Mac, but I am unable t
-
Select of date with yyyymmdd format
HI I have a report that I want to select the current date -1. but our dates are in this format YYYYMMDD so I cant just use 'current date?
-
Creating sales order, va01 and
Hi, While creating a sales order, sold-to-party and ship-to-party fields are available and they are entered while creating order. How can I know to whom an order has been shipped to? In which table can I get this data? I need to know to whom shipment
-
How to sync 'selected' tv shows
Hi all, Well am considerably new to this so please bear with me, I understand that you can select certain things to sync with ipod, ie. in each section you've got 'sync all' or 'sync selected' and then you select what you want to select in my 'tv sho
-
Problème avec icloud sue iphone 3gs
J'ai un problème avec icloud sur mon iphone 3gs, quand je veux activer icloud il me dit que le nombre maximum de compte gratuit est atteint alors que je n'ai activer aucun compte. Pouvez-vous m'aider ?