sqlplus autotrace

Posted on 2012-09-03
Last Modified: 2012-09-06
I need to insert into Oracle table the execution plan as well as statistics of the statements with autotrace for sqlplus session.

for example:
SQL> set autotrace on;
SQL> select count(*)
  2  from dual;


Exrcution Plan
Plan hash value: 1388734953                                                    
| Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |              
|   0 | SELECT STATEMENT |      |     1 |     2   (0)| 00:00:01 |              
|   1 |  FAST DUAL       |      |     1 |     2   (0)| 00:00:01 |              

          1  recursive calls                                                    
          0  db block gets                                                      
          0  consistent gets                                                    
          0  physical reads                                                    
          0  redo size                                                          
        425  bytes sent via SQL*Net to client                                  
        416  bytes received via SQL*Net from client                            
          2  SQL*Net roundtrips to/from client                                  
          0  sorts (memory)                                                    
          0  sorts (disk)                                                      
          1  rows processed                                                    

Can I insert this output into Oracle table?
I need to trace many statements for the current session and save them in a table.

Thanks in advance!
Question by:ralph_rea
    LVL 23

    Expert Comment

    Simplest:  SPOOL the output and store on your file system.  It is heavily documented how to date-stamp files, add instance names, etc; and they are appendable.

    Otherwise, you're looking at clob storage if you require the store-as-table thing.

    Have you evaluated the usefulness of the .trc output in your trace logs?

    Author Comment

    I need to find the following values ¿¿for the sqlplus session set autotrace on;

    Cost (%CPU)

    I'd like to create a table with these columns and insert these values or or I'd like to find some system table that gives me the data.
    LVL 76

    Accepted Solution

    Don't do this with autotrace.  Do this with explain plan.  You can set statement id's and trace as many select's as you wish.  The plans are stored and you can extract whatever you want.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now