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/

Similar Messages

  • How to find out the last time login for a locked login account?

    In ASE 15.4,there are many login account show as locked and unlocked. How to find out the last login time for those locked login account?

    Thank you.  The version of my ASE is 12.5.4.
    This is what I got from select * from syslogins: 
    suid status accdate totcpu totio spacelimit timelimit resultlimit dbname name password language pwdate audflags fullname srvname logincount procid
    1
    30 2 10/25/2012 11:41:10.430 AM 0 0 0 0 0 . . ... us_english 02/24/2.0.08 12:55:38.640 PM 0 [NULL] [NULL] [NULL] [NULL]
    this is what I got from exec sp_displaylogin 'mylogin':
    1 Suid: 46                               
    2 Loginame: mylogin   
    3 Fullname: FN LN
    4 Default Database: mydb
    5 Default Language: us_english   
    6 Auto Login Script:    
    7 Configured Authorization:   
    8 Locked: YES                              
    9 Date of Last Password Change: Apr 17 2010  2:36PM    
    10 Password expiration interval: 0            
    11 Password expired: NO                               
    12 Minimum password length: 6            
    13 Maximum failed logins: 0            
    14 Current failed login attempts:    
    15 Authenticate with: AUTH_DEFAULT                     
    which one is for last login time?

  • OSB: how to figure out the execution time of OSB proxy

    Trying to figure out how to determine the execution time taken for any given OSB proxy. Seems like the OSB built-in alerting facilities can display the average response time of all calls to a proxy but not individually. Is there a way to dig this out from the monitoring data being collected?

    Service monitoring which comes OOTB is supposed to be aggregated because in usual scenarios you dont need to see the processing time of a specific request. From a performance monitoring perspective the useful data usually is average processing time and minimum or maximum processing time for any request within the aggregation interval which is provided by OSB OOTB.
    Now, in some cases the business might want to track each request individually. So, for example they can track how long did it take to process a specific order. OSB does not provide this feature OOTB. There are multiple ways to get this implemented. Two of the most common ways are:
    1. Add a start and end time capturing in Proxy Services. You can use logging/reporting/publish to a DB etc to achieve this. But this is indeed intrusive and you will need to do this for every Proxy which needs to be monitored at every instance level. This is also a slight overhead in processing in itself.
    2. Use monitoring products which can monitor the WS invocations externally. This will mean more investment but definitely a much better solution. You can consider using different products from Oracle and other vendors based on your requirements, features of products and costs. A few examples are OWSM, Oracle EM, CA Wily etc.

  • How to find out the first time RMAN be utilized in DB

    I need to find out the history of RMAN process in my database, like when it was used first time, and status ect...
    I have checked all v$RMAN_xxx view and v$backup_XXXX views, didn't fine anything.
    Is there other views that may be helpful?
    Also any way I can find out when was archivelog turned on?
    Thanks

    Here is the version
    SQL> select banner from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Prod
    PL/SQL Release 10.1.0.4.0 - Production
    CORE 10.1.0.4.0 Production
    TNS for 32-bit Windows: Version 10.1.0.4.0 - Production
    NLSRTL Version 10.1.0.4.0 - Production
    Here is what I got if I just issue RMAN from command line:
    E:\>rman
    Recovery Manager: Release 10.2.0.2.0 - Production on Tue Feb 27 11:21:18 2007
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    RMAN>
    here is what I got if I got into $oracle_home/bin
    E:\>cd oracle\product\10.1.0\db_1\bin
    E:\oracle\product\10.1.0\Db_1\BIN>rman
    Recovery Manager: Release 10.1.0.4.0 - Production
    Copyright (c) 1995, 2004, Oracle. All rights reserved.
    RMAN>
    Thanks for the help.

  • How to find out the exact time in UK with daylight savings.

    Hi,
    how can i get the exact time in UK even if the daylight savings time is implemented in UK..,
    now my code is implemented for IST ,how can i get the BST timings?
    Thankx.

    the setTimeZone method of SimpleDateFormat (actually inherited from DateFormat). Use it to set it to your timezone when parsing or formatting a date string for your timezone and set it to the UK timezone when parsing or formatting a date string for their timezone.
    Edit: IOW SimpleDateFormat was the answer, not a question.

  • How to find out the remaining time of guarantee of an iPad Air?

    I have received a second hand iPad air today and I would like to know how long of guarantee it still  has. Is there any way that, by serial number, activation or other thing, I can access it?If I need to use the guarantee  do I must show any receipt or the activation is  already  enough?

    Enter your Serial Number here:
    Check Your Service and Support Coverage
    You can find your serial number here:
    Settings > General > About > Serial Number

  • How to find out the rows inserted between a time period.

    Hi,
    Please help me to solve this.
    Table - emp.
    Colmns - empno(Primary Key),ename, mgr
    How to find out the rows inserted between a time period.
    For eg:- Between 02-Oct-2006 1 PM and 03-Oct-2006 2 PM.
    regards,
    Mathew.

    Hi,
    Maybe work:
    For each row, ORA_ROWSCN returns the conservative upper bound system change number (SCN) of the most recent change to the row. This pseudocolumn is useful for determining approximately when a row was last updated. It is not absolutely precise, because Oracle tracks SCNs by transaction committed for the block in which the row resides
    e.g.:
    SGMS@ORACLE10> create table test(cod number);
    Table created.
    SGMS@ORACLE10> insert into test values (1);
    1 row created.
    SGMS@ORACLE10> insert into test values (2);
    1 row created.
    SGMS@ORACLE10> commit;
    Commit complete.
    SGMS@ORACLE10> insert into test values (3);
    1 row created.
    SGMS@ORACLE10> commit;
    Commit complete.
    SGMS@ORACLE10> select SCN_TO_TIMESTAMP(ora_rowscn),ora_rowscn,cod from test;
    SCN_TO_TIMESTAMP(ORA_ROWSCN)       ORA_ROWSCN        COD
    06/11/06 08:56:56,000000000         727707205          1
    06/11/06 08:56:56,000000000         727707205          2
    06/11/06 08:57:05,000000000         727707210          3Cheers

  • How can i find out the last time a back up to icloud was done

    How can i find out the last time a back up was done to icloud?

    Go to Settings>iCloud>Storage & Backup.  It will be shown just below the Back Up Now button at the bottom.

  • How to find out the time when the ASE started?

    Normally, ASE not reboot for production. Only for maintenance or performance tuning, maybe need to reboot ASE.
    Question is how to find out the time when ASE was started?
    one way maybe is check errorlog. Any more simple way no need to login to server OS?

    Hi Kent,
    In ASE 12.5 and up, you can do 'select @@boottime'  For older releases, a general method is 'select crdate from sysdatabases where dbid=2'
    1> select @@boottime, crdate from sysdatabases where dbid=2
    2> go
                                     crdate
                 Jul 15 2014  9:19AM             Jul 15 2014  9:19AM
    (1 row affected)
    Cheers
    Dan

  • How to find out the last date & time on which a program has been run

    Hi Experts,
    Can anybody tell how to find out the last date on which a purticular program has been run.
    Valuable answers will be rewarded.
    Thanks & Regards,
    Satish.

    Hi!
    Try STAD transaction. Unfortunately it contains a huge amount of data, so it is available only for a few days backwards... Maybe some weeks, but you can't make yearly reports from its data... So it's not useful to see, which program is in use or not...
    I planned once to download it weekly, but it was not so important...
    Regards
    Tamá

  • How to find out the Target Component name and Target view name

    Hi All Expert,
                      I want to know ,how to find out the target component and target view in WEB UI,when i click on a field which shows as a hyper link in WEB UI .At GUI level ,i know the how it will work.Any way to find out the component name and view name which is show the details of that field at GUI level .IF you go to transaction CRMD_ORDER then open the service contract id .then goto the item level value .there is 1 service data tab is available at item level.there is two button is available.first one is available time and second one is response time .if i click on any button then one popup is open which is shows the details of that button.I dont know how to find out the component name and view name from GUI level.
    Thanks in Advance....
    Vishwas Sahu

    Hi Vishwa,
                 The control would be something like this for navigation in Get_p_xxx method u mention as link and u mention a event name which gets triggered on the click of this hyperlink. So your GET_P_XXX method would have the following code:
    CASE iv_property.
        WHEN if_bsp_wd_model_setter_getter=>fp_fieldtype.
          rv_value = cl_bsp_dlc_view_descriptor=>field_type_event_link.
        WHEN if_bsp_wd_model_setter_getter=>fp_onclick.
          rv_value = 'EXAMPLE'.
    Now you have to create a method as EH_ONEXAMPLE at your IMPL class and within which you would give an outbound plug method. Within the outbound plug the target data would be filled in the collection and window outbound plug would be triggered.
    This is a huge topic and  i have just mentioned you basic things.
    Regards,
    Bharathy.

  • How to find out the RasterItem(embedded) links name?

    How to find out the RasterItem(embedded) links name which appeared in Links menu(Window->Links) via scripting for illustrator cs3. Please advise me the possibilities.
    Thanks for looking into this.

    Thanks for your support. From your code i got the filename(embedded) with pathname(if the embedded image in that location). If the embedded image not in that location at that time it throws error message. Is it possible to find out the name of the embedded image, if the corresponding image not in that location. Kindly advise me the possiblitities.
    Thanks for looking into this.

  • How to find out the save as setting information in illustrator cs3?

    How to find out the save as setting information in illustrator cs3 through programmatically. I saved the file using the setting like Overprint, EmbedAllFonts, IncludeDocumentThumbnails throgh scripting. But i don't know how to find out the save as setting information(Overprint, EmbedAllFonts, IncludeDocumentThumbnails) whether the checkbox true or not through scripting. Kindly advice me.

    Thanks for your response. Some time the operator will set the wrong "save as setting" in the eps file . So i need to check wheather the operator set the correct save as setting or not. If the operator set the wrong save as setting,  i need to inform while running the script. So please advice me how to find out the save as setting information of the active document file, and then inform to the operator if any improper "save as setting" occured.

  • How to find out the max mem can be allocatedTT for 32 bit Win ?

    How to find out the maximum Permanent Data Size and Temporary Data Size that can be allocated for the Oracle Times Ten for 32 bit Windows OS.

    Hi Chris,
    Am I write in saying that this also depends on shared memory setting as well?
    If that is the case, on a platform like window 2003 32-bit, one cannot have more than 4GB of shared memory. Windows Server 2003 includes support for a startup switch (entered in the boot.ini file) that allows the allocation of memory and memory address space. Regardless of the amount of physical memory that is installed on the system, the operating system uses a virtual address space of 4 GB. Out of that amount, by default, 2 GB is allocated to user-mode processes (for example, Oracle or TimesTen) and 2 GB is allocated to kernel-mode processes (for example the operating system and others). In a nutshell on systems that have more than 1 GB of RAM, this startup switch can be used to allocate more memory to applications (3 GB) and less memory to the operating system (1 GB). However, adding adding the /3GB switch to the boot.ini file will not increase the amount of physical RAM memory, the 3GB switch just tells the computer to allocate the existing memory space differently.
    For a 32-bit TimesTen the limit on memory cannot be more than 2GB (PermSize+TempSize). For example on Linux 32-bit I have 1024MB and 512MB for these two parameters.
    Thanks,
    Mich

  • How to make use of SE37- Function Module & how to find out the table?

    Hi ,
    1.Could anyone help me what's this SE37-Function module is all about,How to make use of this?
    For Eg,If i want to delete a BOM permanently from the system then I have to use the Function module CM_DB_DEL_FROM_ROOT_BOM.
    But after giving the particular name what should i do?
    Please help me.
    2.How to find out the respective table for a particular field sya for T code-COGI, T code MFBF,where its values are getting populated.,Please help in this issue.
    Thanks in adavnce for spending some time
    Raj.S

    Hi Raj
    Function Modules
    Function modules are procedures that are defined in special ABAP programs only, so-called function groups, but can be called from all ABAP programs. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder.
    Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating  and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.
    Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.
    The Function Builder  also has a release process for function modules. This ensures that incompatible changes cannot be made to any function modules that have already been released. This applies particularly to the interface. Programs that use a released function module will not cease to work if the function module is changed.
    Check this link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm
    You can execute function module in SE37ie you can perform the activiites defined in the function module by executing it.
    By deleting BOM you mention the FM name in se37 and execute. In some function module it will ask input parameters as developed in the program , you have to give the input parameters and execute.

Maybe you are looking for

  • Bug in new hotplug (2004_09_23-2)?

    Has anyone else had/has problems with the hotplug update? My comp freezes (50/50 chance) at boot, when the hotplug-deamon is started.. it just stops at "busy" and nothing more happens.. I have to make a cold reboot and hope that it works.. Also I get

  • PDF attachments are showing up as WORD doc attachments

    For some reason, my Gmail program shows PDF attachments (that were created using Adobe) as a WORD attachment? When I double click on the attachment, it tries to open in WORD and just shows gobbledygook.  Yet, if I don't try to open it and save it to

  • Renaming files question

    I am new to Lightroom and have a file naming question. I previously used Capture NX2 to import and rename my files. My convention is "YYYY-MM-DD-HH-MM-SS-JAH". Capture NX2 had an option where it would add a "-n" after the seconds field (SS in above)

  • Off topic question  - Apple ID profile

    I don't know where else to post this. I just spent an hour looking around Apple.com trying to find a place to log in so I could update my email address. I never did find a place to do it until I went to the forums. There, I logged in so I could creat

  • Downloadable PDF Form Templates

    Are there any templates available for download for Acrobat Pro, other than the ones I see when I go to create a form and I'm asked to choose a template? Specifically, I'm interested in timesheets with different looks. There's one available installed,