Top 10-20 SQL

Hi all,
I am new in this forum and also new working as DBA. Oracle 9.2.0.6 under Unix.
How will I find out the top most 20 SQL which are being fired.
Thanks a lot in advance.
Cheers
Ben

If you dont have experience with STATSPACK and your concer is just to have top 10-20 queries, with the criteria of disk_reads (physical reads), buffer_gets (logical reads), parses and etc, you can always refer v$sql, v$sqlarea,v$sql_plan_statistics_all dynamic views.
Those dynamic performance views will hold the information from time database has started and statspack report gives you the report between the snapshot time.
Jaffar

Similar Messages

  • Equivalent for TOP 1 of SQL Server used in subqueries

    Hi all,
    I am trying to migrate a sql query from SQL Server to Oracle 9i, which uses the SQL Server TOP keyword in correlated subqueries.
    How should I write it in Oracle?
    The query is more complicated, but in principle looks like:
    SELECT TAB1.t1_id, TAB2_t2_id,
    ISNULL((select top 1 val_num
    from values where values.val_id = TAB1.val_id ) ,0),
    TAB1.date,
         (select top 1 TAB3.t3_id from TAB3 where TAB3.name = TAB1.name)
    FROM TAB1, TAB2
    WHERE TAB1.org_id = TAB2.org_id
         AND TAB1.date > TO_DATE('2006-01-01', 'YYYY-MM-DD')
         TAB2.required IS NOT NULL
    If I would remove in each subquery the "top 1" and add "and rownum = 1", it will not work.
    Any suggestions?
    Thanks,
    Paul

    http://www.ispirer.com/doc/sqlways38/Output/SQLWays-1-044.html

  • How to get top CPU consuming sql oracle 10g

    I can see the top sql by running ASH report. but there is too much infomation. is there a way I can just display TOP SQL section, and filter out other parts? this way I can use it in a shell script, and loop through the database.
    or is there a query can do the ASH job?
    thanks.
    Karl

    Hi,
    What you will do if the EM console bug present?
    As a best pratice, i will do like below
    1) execute the TOP command and you see process consuming high CPU
    2)
    SQL> oradebug setospid <&OSPid>
    SQL> oradebug tracefile_name --This will list the name of tracefile with location
    SQL> oradebug unlimit
    SQL> oradebug Event 10046 trace name context forever, level 12;
    Let it run for 20 mins around
    SQL> oradebug Event 10046 trace name context off;
    SQL> exit
    3) Tkprof with explain plan
    4) check any plan change for that sql
    Kind Regards,
    Rakesh jayappa

  • Increase top number of SQLs in AWR

    Hi,
    AWR report only reporting top 10 sqls. If I use the following SP to increase the top 50 sqls. The AWR is still reporting top 10 sqls. Is there a way to increase the top n sqls?
    execute dbms_workload_repository.modify_snapshot_settings(interval => 15,retention => 0,topnsql => 50);

    Hi,
    Go edit chart series.
    In that page there is attribute Maximum Rows
    Regards,
    Jari

  • Top sessions from sql

    hi
    How can i get the top 5 or 2 users who consuming large physical and logical i/o s,like we getting the top sessions in OEM.I dont want to use OEM.Is it v$filestat and v$session?
    with regards
    ramya

    You can use v$sesstat and v$session. Something like :
    select * from (select
    b.username,
    b.terminal,
    to_char(b.logon_time,'dd/mm/yyyy hh24:mi:ss'),
    b.program,
    a.value
    from v$sesstat a, v$session b
    where a.statistic# in (40, 41, 42) and
    b.sid = a.siD and
    b.username is not null and
    b.username not like 'SYS%'
    order by a.value desc)
    where rownum < 6;In v$statname you can see all statistics, and eventually change statistic#.

  • How to find top 10  SQL statments which are consuming more cpu time.

    hi all,
    Is there any command or script to monitor the top 10 sql statments which are consuming more cpu time.
    I know by using AWR REPORT we can find it, i want the command or script to find the top cpu utilization sql statments.
    Regards
    Subhash.

    Subhash,
    A quick and dirty Google search could have get you started with the following:
    Thread: how to get top CPU consuming sql oracle 10g
    Re: how to get top CPU consuming sql oracle 10g
    Oracle SQL top sessions
    http://www.dba-oracle.com/oracle10g_tuning/t_sql_top_sessions.htm
    "How to Find top 10 expensive sql's", version 9.2.0
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:73325450402303
    HTH,
    Thierry

  • How to generate Top 10 SQL's in the grid report.

    Hello,
    can anyone give a sample query to be used against to get the information of the top 10 SQL's from the database during the time frame we provide to the report during run time.
    Thanks for your time in advance,
    -Vj

    Subhash,
    A quick and dirty Google search could have get you started with the following:
    Thread: how to get top CPU consuming sql oracle 10g
    Re: how to get top CPU consuming sql oracle 10g
    Oracle SQL top sessions
    http://www.dba-oracle.com/oracle10g_tuning/t_sql_top_sessions.htm
    "How to Find top 10 expensive sql's", version 9.2.0
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:73325450402303
    HTH,
    Thierry

  • All sql

    [./solutions/atonx.sql]
    REM
    REM script ATONX.SQL
    REM =====================================
    SET AUTOTRACE ON EXPLAIN
    [./solutions/saved_settings.sql]
    set appinfo OFF
    set appinfo "SQL*Plus"
    set arraysize 15
    set autocommit OFF
    set autoprint OFF
    set autorecovery OFF
    set autotrace OFF
    set blockterminator "."
    set cmdsep OFF
    set colsep " "
    set compatibility NATIVE
    set concat "."
    set copycommit 0
    set copytypecheck ON
    set define "&"
    set describe DEPTH 1 LINENUM OFF INDENT ON
    set echo OFF
    set editfile "afiedt.buf"
    set embedded OFF
    set escape OFF
    set feedback ON
    set flagger OFF
    set flush ON
    set heading ON
    set headsep "|"
    set linesize 80
    set logsource ""
    set long 80
    set longchunksize 80
    set markup HTML OFF HEAD "<style type='text/css'> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>SQL*Plus Report</title>" BODY "" TABLE "border='1' width='90%' align='center' summary='Script output'" SPOOL OFF ENTMAP ON PRE ON
    set newpage 1
    set null ""
    set numformat ""
    set numwidth 10
    set pagesize 14
    set pause OFF
    set recsep WRAP
    set recsepchar " "
    set serveroutput OFF
    set shiftinout invisible
    set showmode OFF
    set sqlblanklines OFF
    set sqlcase MIXED
    set sqlcontinue "> "
    set sqlnumber ON
    set sqlpluscompatibility 8.1.7
    set sqlprefix "#"
    set sqlprompt "SQL> "
    set sqlterminator ";"
    set suffix "sql"
    set tab ON
    set termout OFF
    set time OFF
    set timing OFF
    set trimout ON
    set trimspool OFF
    set underline "-"
    set verify ON
    set wrap ON
    [./solutions/sol_06_04d.sql]
    -- this script requires the sql id from the previous script to be substituted
    SELECT PLAN_TABLE_OUTPUT      
    FROM TABLE (DBMS_XPLAN.DISPLAY_AWR(' your sql id here'));
    [./solutions/rpsqlarea.sql]
    set feedback off
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('your sql_id here'));
    set feedback on
    [./solutions/sqlid2.sql]
    SELECT SQL_ID, SQL_TEXT FROM V$SQL
    WHERE SQL_TEXT LIKE '%REPORT%' ;
    [./solutions/schemastats.sql]
    SELECT last_analyzed analyzed, sample_size, monitoring,
    table_name
    FROM user_tables;
    [./solutions/allrows.sql]
    REM
    REM script ALLROWS.SQL
    REM =====================================
    alter session set optimizer_mode = all_rows
    [./solutions/aton.sql]
    REM
    REM script ATON.SQL
    REM =====================================
    SET AUTOTRACE ON
    [./solutions/li.sql]
    REM script LI.SQL (list indexes)
    REM wildcards in table_name allowed,
    REM and a '%' is appended by default
    REM ======================================
    set termout off
    store set sqlplus_settings replace
    save buffer.sql replace
    set verify off autotrace off
    set feedback off termout on
    break on table_name skip 1 on index_type
    col table_name format a25
    col index_name format a30
    col index_type format a20
    accept table_name -
    prompt 'List indexes on table : '
    SELECT ui.table_name
    , decode(ui.index_type
    ,'NORMAL', ui.uniqueness
    ,ui.index_type) AS index_type
    , ui.index_name
    FROM user_indexes ui
    WHERE ui.table_name LIKE upper('&table_name.%')
    ORDER BY ui.table_name
    , ui.uniqueness desc;
    get buffer.sql nolist
    @sqlplus_settings
    set termout on
    [./solutions/utlxplp.sql]
    Rem
    Rem $Header: utlxplp.sql 23-jan-2002.08:55:23 bdagevil Exp $
    Rem
    Rem utlxplp.sql
    Rem
    Rem Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved.
    Rem
    Rem NAME
    Rem utlxplp.sql - UTiLity eXPLain Parallel plans
    Rem
    Rem DESCRIPTION
    Rem script utility to display the explain plan of the last explain plan
    Rem     command. Display also Parallel Query information if the plan happens to
    Rem run parallel
    Rem
    Rem NOTES
    Rem Assume that the table PLAN_TABLE has been created. The script
    Rem utlxplan.sql should be used to create that table
    Rem
    Rem With SQL*plus, it is recomended to set linesize and pagesize before
    Rem running this script. For example:
    Rem     set linesize 130
    Rem     set pagesize 0
    Rem
    Rem MODIFIED (MM/DD/YY)
    Rem bdagevil 01/23/02 - rewrite with new dbms_xplan package
    Rem bdagevil 04/05/01 - include CPU cost
    Rem bdagevil 02/27/01 - increase Name column
    Rem jihuang 06/14/00 - change order by to order siblings by.
    Rem jihuang 05/10/00 - include plan info for recursive SQL in LE row source
    Rem bdagevil 01/05/00 - make deterministic with order-by
    Rem bdagevil 05/07/98 - Explain plan script for parallel plans
    Rem bdagevil 05/07/98 - Created
    Rem
    set markup html preformat on
    Rem
    Rem Use the display table function from the dbms_xplan package to display the last
    Rem explain plan. Use default mode which will display only relevant information
    Rem
    select * from table(dbms_xplan.display());
    [./solutions/cbinp.sql]
    REM Oracle10g SQL Tuning Workshop
    REM script CBI.SQL (create bitmap index)
    REM prompts for input; index name generated
    REM =======================================
    accept TABLE_NAME prompt " on which table : "
    accept COLUMN_NAME prompt " on which column: "
    set termout off
    store set saved_settings replace
    set heading off feedback off verify off
    set autotrace off termout on
    column dummy new_value index_name
    SELECT 'creating index'
    , SUBSTR( SUBSTR('&table_name',1,4)||'_' ||
    TRANSLATE(REPLACE('&column_name', ' ', '')
    , 1, 25
    )||'_idx' dummy
    FROM dual;
    CREATE BITMAP INDEX &index_name ON &TABLE_NAME(&COLUMN_NAME)
    NOLOGGING COMPUTE STATISTICS
    @saved_settings
    set termout on
    undef INDEX_NAME
    undef TABLE_NAME
    undef COLUMN_NAME
    [./solutions/dump.sql]
    SElECT *
    FROM v$parameter
    WHERE name LIKE '%dump%';
    [./solutions/utlxplan.sql]
    rem
    rem $Header: utlxplan.sql 29-oct-2001.20:28:58 mzait Exp $ xplainpl.sql
    rem
    Rem Copyright (c) 1988, 2001, Oracle Corporation. All rights reserved.
    Rem NAME
    REM UTLXPLAN.SQL
    Rem FUNCTION
    Rem NOTES
    Rem MODIFIED
    Rem mzait 10/26/01 - add keys and filter predicates to the plan table
    Rem ddas 05/05/00 - increase length of options column
    Rem ddas 04/17/00 - add CPU, I/O cost, temp_space columns
    Rem mzait 02/19/98 - add distribution method column
    Rem ddas 05/17/96 - change search_columns to number
    Rem achaudhr 07/23/95 - PTI: Add columns partition_{start, stop, id}
    Rem glumpkin 08/25/94 - new optimizer fields
    Rem jcohen 11/05/93 - merge changes from branch 1.1.710.1 - 9/24
    Rem jcohen 09/24/93 - #163783 add optimizer column
    Rem glumpkin 10/25/92 - Renamed from XPLAINPL.SQL
    Rem jcohen 05/22/92 - #79645 - set node width to 128 (M_XDBI in gendef)
    Rem rlim 04/29/91 - change char to varchar2
    Rem Peeler 10/19/88 - Creation
    Rem
    Rem This is the format for the table that is used by the EXPLAIN PLAN
    Rem statement. The explain statement requires the presence of this
    Rem table in order to store the descriptions of the row sources.
    create table PLAN_TABLE (
         statement_id      varchar2(30),
         timestamp      date,
         remarks      varchar2(80),
         operation      varchar2(30),
         options      varchar2(255),
         object_node      varchar2(128),
         object_owner      varchar2(30),
         object_name      varchar2(30),
         object_instance numeric,
         object_type varchar2(30),
         optimizer varchar2(255),
         search_columns number,
         id          numeric,
         parent_id     numeric,
         position     numeric,
         cost          numeric,
         cardinality     numeric,
         bytes          numeric,
         other_tag varchar2(255),
         partition_start varchar2(255),
    partition_stop varchar2(255),
    partition_id numeric,
         other          long,
         distribution varchar2(30),
         cpu_cost     numeric,
         io_cost          numeric,
         temp_space     numeric,
    access_predicates varchar2(4000),
    filter_predicates varchar2(4000));
    [./solutions/indstats.sql]
    accept table_name -
    prompt 'on which table : '
    SELECT index_name name, num_rows n_r,
    last_analyzed l_a, distinct_keys d_k,
    leaf_blocks l_b, avg_leaf_blocks_per_key a_l,join_index j_I
    FROM user_indexes
    WHERE table_name = upper('&table_name');
    undef table_name
    [./solutions/test.sql]
    declare
    x number;
    begin
    for i in 1..10000 loop
    select count(*) into x from customers;
    end loop;
    end;
    [./solutions/rp.sql]
    set feedback off
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
    set feedback on
    [./solutions/sol_08_02b.sql]
    ALTER SESSION SET SQL_TRACE = TRUE;
    [./solutions/trace.sql]
    ALTER SESSION SET SQL_TRACE = TRUE;
    [./solutions/doit.sql]
    DROP INDEX SALES_CH_BIX;
    DROP INDEX SALES_CUST_BIX;
    DROP INDEX SALES_PROD_BIX;
    [./solutions/ci.sql]
    REM SQL Tuning Workshop
    REM script CI.SQL (create index)
    REM prompts for input; index name generated
    REM =======================================
    accept TABLE_NAME prompt " on which table : "
    accept COLUMN_NAME prompt " on which column(s): "
    set termout off
    store set saved_settings replace
    set heading off feedback off autotrace off
    set verify off termout on
    column dummy new_value index_name
    SELECT 'creating index'
    , SUBSTR( SUBSTR('&table_name',1,4)||'_' ||
    TRANSLATE(REPLACE('&column_name', ' ', '')
    , 1, 25
    )||'_idx' dummy
    FROM dual;
    CREATE INDEX &index_name
    ON &table_name(&column_name)
    NOLOGGING COMPUTE STATISTICS;
    @saved_settings
    set termout on
    undef INDEX_NAME
    undef TABLE_NAME
    undef COLUMN_NAME
    [./solutions/sol_06_04c.sql]
    exec dbms_workload_repository.create_snapshot('ALL');
    [./solutions/sol_06_04a.sql]
    column sql_text format a25
    SELECT SQL_ID, SQL_TEXT FROM V$SQL
    WHERE SQL_TEXT LIKE '%REPORT%' ;
    [./solutions/login.sql]
    REM ======================================
    REM COL[UMN] commands
    REM ======================================
    col dummy new_value index_name
    col name format a32
    col segment_name format a20
    col table_name format a20
    col column_name format a20
    col index_name format a30
    col index_type format a10
    col constraint_name format a20
    col num_distinct format 999999
    col update_comment format a20 word
    -- for the SHOW SGA/PARAMETER commands:
    col name_col_plus_show_sga format a24
    col name_col_plus_show_param format a40 -
    heading name
    col value_col_plus_show_param format a35 -
    heading value
    -- for the AUTOTRACE setting:
    col id_plus_exp format 90 head i
    col parent_id_plus_exp format 90 head p
    col plan_plus_exp format a80
    col other_plus_exp format a44
    col other_tag_plus_exp format a29
    col object_node_plus_exp format a8
    REM ======================================
    REM SET commands
    REM ======================================
    set describe depth 2
    set echo off
    set editfile D:\Tmp\buffer.sql
    set feedback 40
    set linesize 120
    set long 999
    set numwidth 8
    set pagesize 36
    set pause "[Enter]..." pause off
    set tab off
    set trimout on
    set trimspool on
    set verify off
    set wrap on
    REM ======================================
    REM DEFINE commands
    REM ======================================
    def 1=employees
    def table_name=employees
    def column_name=first_name
    def buckets=1
    def sc=';'
    REM ======================================
    REM miscellaneous
    REM ======================================
    [./solutions/sqlid.sql]
    SELECT SQL_ID, SQL_TEXT FROM V$SQL
    WHERE SQL_TEXT LIKE '%/* my%' ;
    [./solutions/hist1.sql]
    SELECT * FROM products WHERE prod_status LIKE 'available, on stock'
    [./solutions/sol_08_02.sql]
    ALTER SESSION SET TRACEFILE_IDENTIFIER = 'User12';
    [./solutions/utlxrw.sql]
    Rem
    Rem $Header: utlxrw.sql 29-apr-2005.08:22:09 mthiyaga Exp $
    Rem
    Rem utlxrw.sql
    Rem
    Rem Copyright (c) 2000, 2005, Oracle. All rights reserved.
    Rem
    Rem NAME
    Rem utlxrw.sql - Create the output table for EXPLAIN_REWRITE
    Rem
    Rem DESCRIPTION
    Rem Outputs of the EXPLAIN_REWRITE goes into the table created
    Rem by utlxrw.sql (called REWRITE_TABLE). So utlxrw must be
    Rem     invoked before any EXPLAIN_REWRITE tests.
    Rem
    Rem NOTES
    Rem If user specifies a different name in EXPLAIN_REWRITE, then
    Rem it should have been already created before calling EXPLAIN_REWRITE.
    Rem
    Rem MODIFIED (MM/DD/YY)
    Rem mthiyaga 04/29/05 - Remove unncessary comment
    Rem mthiyaga 06/08/04 - Add rewritten_txt field
    Rem mthiyaga 10/10/02 - Add extra columns
    Rem mthiyaga 09/27/00 - Create EXPLAIN_REWRITE output table
    Rem mthiyaga 09/27/00 - Created
    Rem
    Rem
    CREATE TABLE REWRITE_TABLE(
    statement_id VARCHAR2(30), -- id for the query
    mv_owner VARCHAR2(30), -- owner of the MV
    mv_name VARCHAR2(30), -- name of the MV
    sequence INTEGER, -- sequence no of the error msg
    query VARCHAR2(2000),-- user query
    query_block_no INTEGER, -- block no of the current subquery
    rewritten_txt VARCHAR2(2000),-- rewritten query
    message VARCHAR2(512), -- EXPLAIN_REWRITE error msg
    pass VARCHAR2(3), -- rewrite pass no
    mv_in_msg VARCHAR2(30), -- MV in current message
    measure_in_msg VARCHAR2(30), -- Measure in current message
    join_back_tbl VARCHAR2(30), -- Join back table in current msg
    join_back_col VARCHAR2(30), -- Join back column in current msg
    original_cost INTEGER, -- Cost of original query
    rewritten_cost INTEGER, -- Cost of rewritten query
    flags INTEGER, -- associated flags
    reserved1 INTEGER, -- currently not used
    reserved2 VARCHAR2(10)) -- currently not used
    [./solutions/nm.sql]
    ALTER INDEX &indexname NOMONITORING USAGE;
    [./solutions/attox.sql]
    REM
    REM script ATTOX.SQL
    REM =====================================
    set autotrace traceonly explain
    [./solutions/create_tab.sql]
    DROP TABLE test_sales;
    DROP TABLE test_promotions;
    DROP TABLE test_customers;
    DROP TABLE test_countries;
    CREATE table test_sales as select * from sales;
    CREATE TABLE test_promotions AS SELECT * FROM promotions;
    CREATE INDEX t_promo_id_idx ON TEST_PROMOTIONS(promo_id);
    ALTER TABLE test_promotions MODIFY promo_id PRIMARY KEY USING INDEX t_promo_id_idx;
    CREATE TABLE test_customers AS SELECT * FROM customers;
    CREATE INDEX t_cust_id_idx ON TEST_CUSTOMERS(cust_id);
    ALTER TABLE test_customers MODIFY cust_id PRIMARY KEY USING INDEX t_cust_id_idx;
    CREATE TABLE test_countries AS SELECT * FROM countries;
    CREATE INDEX t_country_id_idx ON TEST_COUNTRIES(country_id);
    ALTER TABLE test_countries MODIFY country_id PRIMARY KEY USING INDEX t_country_id_idx;
    UPDATE test_customers SET cust_credit_limit = 1000 WHERE ROWNUM <= 15000;
    [./solutions/cui.sql]
    REM SQL Tuning Workshop
    REM script CUI.SQL (create unique index)
    REM prompts for input; index name generated
    REM =======================================
    accept TABLE_NAME prompt " on which table : "
    accept COLUMN_NAME prompt " on which column(s): "\
    set termout off
    store set saved_settings replace
    set heading off feedback off verify off
    set autotrace off termout on
    SELECT 'creating unique index'
    , SUBSTR('ui_&TABLE_NAME._' ||
    TRANSLATE(REPLACE('&COLUMN_NAME', ' ', '')
    , 1, 30) dummy
    from dual
    CREATE UNIQUE INDEX &INDEX_NAME ON &TABLE_NAME(&COLUMN_NAME)
    @saved_settings
    set termout on
    undef INDEX_NAME
    undef TABLE_NAME
    undef COLUMN_NAME
    [./solutions/advisor_cache_setup.sql]
    set echo on
    alter system flush shared_pool;
    grant advisor to sh;
    connect sh/sh;
    SELECT c.cust_last_name, sum(s.amount_sold) AS dollars,
    sum(s.quantity_sold) as quantity
    FROM sales s , customers c, products p
    WHERE c.cust_id = s.cust_id
    AND s.prod_id = p.prod_id
    AND c.cust_state_province IN ('Dublin','Galway')
    GROUP BY c.cust_last_name;
    SELECT c.cust_id, SUM(amount_sold) AS dollar_sales
    FROM sales s, customers c WHERE s.cust_id= c.cust_id GROUP BY c.cust_id;
    select sum(unit_cost) from costs group by prod_id;
    [./solutions/utlxmv.sql]
    Rem
    Rem $Header: utlxmv.sql 16-feb-2001.13:03:32 nshodhan Exp $
    Rem
    Rem utlxmv.sql
    Rem
    Rem Copyright (c) Oracle Corporation 2000. All Rights Reserved.
    Rem
    Rem NAME
    Rem utlxmv.sql - UTiLity for eXplain MV
    Rem
    Rem DESCRIPTION
    Rem The utility script creates the MV_CAPABILITIES_TABLE that is
    Rem used by the DBMS_MVIEW.EXPLAIN_MVIEW() API.
    Rem
    Rem NOTES
    Rem
    Rem MODIFIED (MM/DD/YY)
    Rem nshodhan 02/16/01 - Bug#1647071: replace mv with mview
    Rem raavudai 11/28/00 - Fix comment.
    Rem twtong 12/01/00 - fix for sql*plus
    Rem twtong 09/13/00 - modify mv_capabilities_tabe
    Rem twtong 08/18/00 - change create table to upper case
    Rem jraitto 06/12/00 - add RELATED_NUM and MSGNO columns
    Rem jraitto 05/09/00 - Explain_MV table
    Rem jraitto 05/09/00 - Created
    Rem
    CREATE TABLE MV_CAPABILITIES_TABLE
    (STATEMENT_ID VARCHAR(30), -- Client-supplied unique statement identifier
    MVOWNER VARCHAR(30), -- NULL for SELECT based EXPLAIN_MVIEW
    MVNAME VARCHAR(30), -- NULL for SELECT based EXPLAIN_MVIEW
    CAPABILITY_NAME VARCHAR(30), -- A descriptive name of the particular
    -- capability:
    -- REWRITE
    -- Can do at least full text match
    -- rewrite
    -- REWRITE_PARTIAL_TEXT_MATCH
    -- Can do at leat full and partial
    -- text match rewrite
    -- REWRITE_GENERAL
    -- Can do all forms of rewrite
    -- REFRESH
    -- Can do at least complete refresh
    -- REFRESH_FROM_LOG_AFTER_INSERT
    -- Can do fast refresh from an mv log
    -- or change capture table at least
    -- when update operations are
    -- restricted to INSERT
    -- REFRESH_FROM_LOG_AFTER_ANY
    -- can do fast refresh from an mv log
    -- or change capture table after any
    -- combination of updates
    -- PCT
    -- Can do Enhanced Update Tracking on
    -- the table named in the RELATED_NAME
    -- column. EUT is needed for fast
    -- refresh after partitioned
    -- maintenance operations on the table
    -- named in the RELATED_NAME column
    -- and to do non-stale tolerated
    -- rewrite when the mv is partially
    -- stale with respect to the table
    -- named in the RELATED_NAME column.
    -- EUT can also sometimes enable fast
    -- refresh of updates to the table
    -- named in the RELATED_NAME column
    -- when fast refresh from an mv log
    -- or change capture table is not
    -- possilbe.
    POSSIBLE CHARACTER(1), -- T = capability is possible
    -- F = capability is not possible
    RELATED_TEXT VARCHAR(2000),-- Owner.table.column, alias name, etc.
    -- related to this message. The
    -- specific meaning of this column
    -- depends on the MSGNO column. See
    -- the documentation for
    -- DBMS_MVIEW.EXPLAIN_MVIEW() for details
    RELATED_NUM NUMBER, -- When there is a numeric value
    -- associated with a row, it goes here.
    -- The specific meaning of this column
    -- depends on the MSGNO column. See
    -- the documentation for
    -- DBMS_MVIEW.EXPLAIN_MVIEW() for details
    MSGNO INTEGER, -- When available, QSM message #
    -- explaining why not possible or more
    -- details when enabled.
    MSGTXT VARCHAR(2000),-- Text associated with MSGNO.
    SEQ NUMBER);
                        -- Useful in ORDER BY clause when
    -- selecting from this table.
    [./solutions/di.sql]
    DROP INDEX &index_name;
    [./solutions/hist2.sql]
    SELECT * FROM products WHERE prod_status = 'obsolete'
    [./solutions/sol_06_04b.sql]
    -- this script requires the sql_id that you got from the previous step
    SELECT SQL_ID, SQL_TEXT FROM dba_hist_sqltext where sql_id ='yourr sql id here';
    [./solutions/tabstats.sql]
    accept table_name -
    prompt 'on which table : '
    SELECT last_analyzed analyzed, sample_size, monitoring,
    table_name
    FROM user_tables
    WHERE table_name = upper('&table_name');
    undef TABLE_NAME
    [./solutions/rewrite.sql]
    ALTER SESSION SET QUERY_REWRITE_ENABLED = true
    [./solutions/atto.sql]
    REM
    REM script ATTO.SQL
    REM =====================================
    set autotrace traceonly
    [./solutions/flush.sql]
    --this script flushes the shared pool
    alter system flush shared_pool
    [./solutions/atoff.sql]
    REM
    REM script ATOFF.SQLREM =====================================
    SET AUTOTRACE OFF
    [./solutions/cbi.sql]
    REM Oracle10g SQL Tuning Workshop
    REM script CBI.SQL (create bitmap index)
    REM prompts for input; index name generated
    REM =======================================
    accept TABLE_NAME prompt " on which table : "
    accept COLUMN_NAME prompt " on which column: "
    set termout off
    store set saved_settings replace
    set heading off feedback off verify off
    set autotrace off termout on
    column dummy new_value index_name
    SELECT 'creating index'
    , SUBSTR( SUBSTR('&table_name',1,4)||'_' ||
    TRANSLATE(REPLACE('&column_name', ' ', '')
    , 1, 25
    )||'_idx' dummy
    FROM dual;
    CREATE bitmap index &INDEX_NAME on &TABLE_NAME(&COLUMN_NAME)
    LOCAL NOLOGGING COMPUTE STATISTICS
    @saved_settings
    set termout on
    undef INDEX_NAME
    undef TABLE_NAME
    undef COLUMN_NAME
    [./solutions/buffer.sql]
    SELECT c.cust_last_name, c.cust_year_of_birth
    , co.country_name
    FROM customers c
    JOIN countries co
    USING (country_id)
    [./solutions/sol_08_04.sql]
    ALTER SESSION SET SQL_TRACE = false;
    [./solutions/sqlplus_settings.sql]
    set appinfo OFF
    set appinfo "SQL*Plus"
    set arraysize 15
    set autocommit OFF
    set autoprint OFF
    set autorecovery OFF
    set autotrace TRACEONLY EXPLAIN STATISTICS
    set blockterminator "."
    set cmdsep OFF
    set colsep " "
    set compatibility NATIVE
    set concat "."
    set copycommit 0
    set copytypecheck ON
    set define "&"
    set describe DEPTH 1 LINENUM OFF INDENT ON
    set echo OFF
    set editfile "afiedt.buf"
    set embedded OFF
    set escape OFF
    set feedback 6
    set flagger OFF
    set flush ON
    set heading ON
    set headsep "|"
    set linesize 80
    set logsource ""
    set long 80
    set longchunksize 80
    set markup HTML OFF HEAD "<style type='text/css'> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>SQL*Plus Report</title>" BODY "" TABLE "border='1' width='90%' align='center' summary='Script output'" SPOOL OFF ENTMAP ON PRE OFF
    set newpage 1
    set null ""
    set numformat ""
    set numwidth 10
    set pagesize 14
    set pause OFF
    set recsep WRAP
    set recsepchar " "
    set serveroutput OFF
    set shiftinout invisible
    set showmode OFF
    set sqlblanklines OFF
    set sqlcase MIXED
    set sqlcontinue "> "
    set sqlnumber ON
    set sqlpluscompatibility 8.1.7
    set sqlprefix "#"
    set sqlprompt "SQL> "
    set sqlterminator ";"
    set suffix "sql"
    set tab ON
    set termout OFF
    set time OFF
    set timing OFF
    set trimout ON
    set trimspool OFF
    set underline "-"
    set verify ON
    set wrap ON
    [./solutions/sol_07_01.sql]
    SELECT owner, job_name,enabled
    FROM DBA_SCHEDULER_JOBS
    WHERE JOB_NAME = 'GATHER_STATS_JOB';
    [./solutions/colhist.sql]
    SELECT column_name, num_distinct, num_buckets, histogram
    FROM USER_TAB_COL_STATISTICS
    WHERE histogram <> 'NONE';
    [./solutions/rpawr.sql]
    set feedback off
    SELECT PLAN_TABLE_OUTPUT      
    FROM TABLE (DBMS_XPLAN.DISPLAY_AWR('&sqlid'));
    set feedback on
    [./solutions/im.sql]
    ALTER INDEX &indexname MONITORING USAGE;
    [./solutions/utlxpls.sql]
    Rem
    Rem $Header: utlxpls.sql 26-feb-2002.19:49:37 bdagevil Exp $
    Rem
    Rem utlxpls.sql
    Rem
    Rem Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved.
    Rem
    Rem NAME
    Rem utlxpls.sql - UTiLity eXPLain Serial plans
    Rem
    Rem DESCRIPTION
    Rem script utility to display the explain plan of the last explain plan
    Rem     command. Do not display information related to Parallel Query
    Rem
    Rem NOTES
    Rem Assume that the PLAN_TABLE table has been created. The script
    Rem     utlxplan.sql should be used to create that table
    Rem
    Rem With SQL*plus, it is recomended to set linesize and pagesize before
    Rem running this script. For example:
    Rem     set linesize 100
    Rem     set pagesize 0
    Rem
    Rem MODIFIED (MM/DD/YY)
    Rem bdagevil 02/26/02 - cast arguments
    Rem bdagevil 01/23/02 - rewrite with new dbms_xplan package
    Rem bdagevil 04/05/01 - include CPU cost
    Rem bdagevil 02/27/01 - increase Name column
    Rem jihuang 06/14/00 - change order by to order siblings by.
    Rem jihuang 05/10/00 - include plan info for recursive SQL in LE row source
    Rem bdagevil 01/05/00 - add order-by to make it deterministic
    Rem kquinn 06/28/99 - 901272: Add missing semicolon
    Rem bdagevil 05/07/98 - Explain plan script for serial plans
    Rem bdagevil 05/07/98 - Created
    Rem
    set markup html preformat on
    Rem
    Rem Use the display table function from the dbms_xplan package to display the last
    Rem explain plan. Force serial option for backward compatibility
    Rem
    select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));
    [./solutions/dai.sql]
    REM script DAI.SQL (drop all indexes)
    REM prompts for a table name; % is appended
    REM does not touch indexes associated with constraints
    REM ==================================================
    accept table_name -
    prompt 'on which table : '
    set termout off
    store set sqlplus_settings replace
    save buffer.sql replace
    set heading off verify off autotrace off feedback off
    spool doit.sql
    SELECT 'drop index '||i.index_name||';'
    FROM user_indexes i
    WHERE i.table_name LIKE UPPER('&table_name.%')
    AND NOT EXISTS
    (SELECT 'x'
    FROM user_constraints c
    WHERE c.index_name = i.index_name
    AND c.table_name = i.table_name
    AND c.status = 'ENABLED');
    spool off
    @doit
    get buffer.sql nolist
    @sqlplus_settings
    set termout on
    [./solutions/setupenv.sql]
    connect system/oracle
    GRANT DBA TO sh;
    GRANT CREATE ANY OUTLINE TO sh;
    GRANT ADVISOR TO sh;
    GRANT CREATE ANY VIEW TO sh;
    EXECUTE DBMS_

    What an insane topic. Where's your question?
    I recommend you to start over with a smart question and only the relevant code lines.
    Check this link: [How To Ask Questions The Smart Way|http://www.catb.org/~esr/faqs/smart-questions.html].

  • Bi for a realtime scenario with SQL Server

    Hi ,
    i need to create a dashboard to extract data in realtime mode that means an automatic refresh of data each 1 or 2 minutes.
    The dashboard must show data that are the result of the execution of SQL store Procedure in MS SQL Server 2008.
    We have BI 4.1 platform SP2.
    Thanks in advance for your suggestions.
    Best Regards.
    Andrea

    Hi Andrea,
    Create universe on top of your SQL server DB and create reports on tops of it.
    Later you can use Live office / QAAWS/BIWS to fetch the Data to xcelsius dashboard.
    there are few settings in Dashbaord designer which will refresh the dashboard on the refresh every option.
    PF the below screenshot.

  • Top N analysis..

    .Don't plz send the links ... plz provide with sme solution ...
    ....Suppose ..i want to find TOP 3 earners of the Company so tht i can do .by using ..Inline vies.......
    ...My query is ..how to find ...the THIRD highest Earner of the Company .......
    The Table is Employees ..Which is located in HR schema.....

    I don't understand what you are trying to say, sorry.
    My point is:
    If you know how to get the top 3 earners:
    SQL> get t1
      1  select v.*, rownum rn
      2  from   ( select *
      3           from   emp
      4           order by sal desc
      5         ) v
      6* where rownum <= 3
    SQL> /
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO         RN
          7839 KING       PRESIDENT            17-NOV-81       5000                    10          1
          7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20          2
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20          3
    SQL> then it is easy to select only the 3rd row from this result set:
    SQL> get t2
      1  select *
      2  from   (
      3           select v.*, rownum rn
      4           from   ( select *
      5                    from   emp
      6                    order by sal desc
      7                  ) v
      8           where rownum <= 3
      9         ) v2
    10* where v2.rn >= 3
    SQL> /
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO         RN
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20          3
    SQL> So I can not get your point.
    Message was edited by:
    Leo Mannhart

  • SQL monitoring scripts

    Hi Gurus,
    I need a whole bunch of SQL monitoring SQLs in other words some data dictionary SQL scripts to monitor SQLs like following
    --Top 5 worst sqls
    select c.*
    from (select disk_reads, buffer_gets, rows_processed, executions,
    -- address,
    -- hash_value,
    first_load_time, sql_text
    from v$sqlarea
    where parsing_user_id !=0
    order by buffer_gets/decode(executions,null,1,0,1,executions) desc ) c
    where rownum <= 5
    order by disk_reads desc;
    Thanks
    Amitava.

    Just look at the AWR data / run an AWR report.
    See DBA_HIST_SQLSTAT.

  • Where to find the SQL log by crystal reports

    i want to watch the sql log by crystal report loading,but i don't know how to find it , somebody knows it? thanks advanced!

    Hi Wang,
    If you mean to look at the SQL query CR generates, then open the report in the CR Designer > Go to the Database option on the top > Click Show SQL.
    -Abhilash

  • Using Ranking on MS SQL Server 2005

    Hello,
    We are on BOXI3.1 base version and have a universe on top of MS SQL Server 2005.
    My question is regarding use of rank functions. BO guides state that
    You can perform a database ranking only if your database supports
    it. If this is not the case, the Add a database ranking button is disabled on
    the Query Panel toolbar. Databases that support ranking are Oracle, DB2,
    Terradata and Redbrick.
    So SQL Server is not in the list. However the add database ranking button is enabled on
    my report panel. If i add a ranking the query runs for a long time and times-out.
    Is there any universe parameter i need to enable to use ranking? Has any-one mangaged to
    use ranking functionality with SQL Server 2005.
    Thanks in advance.

    Hi Bashir Awan,
    When we create this Object (using your example) at Universe level is the ranking hardcoded ?
    My questions is, say i have Product object (with values A, B, C, D, E), and sales aggregated (10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
    Say the table is as follows
    Product;        sales
        A;               10
        A;                70*
        B;                 50
        B;                 20*
        C;                 30
        C;                 60*
        D;                 40
        D;                 90
        E;                 80
        E;                100
    Note: * represents Oversees sales outside US
    Case 1: Now when we rank whole data to select top 3 we should get (E, D, C in Desc order)
    Case 2: Now if I apply prompt on Country of sales as US will I get (E, B, D) or is it still (E, D, C as earlier).
    Case 3: Similarly if I apply prompt on Product (no prompt on Country) in the filter pane and select (A, D, E) will my results show (E, D, A) or (E, D) as the value of A may be restricted due to ranking formula based on sales at Universe level.
    I am sorry I may be asking a very basic question. Thanks
    Sudhir.

  • Expensive SQL Statements of the day?

    Hi...
    How can i find out Expensive SQL Statements of the day please.?
    Our SAP Version is ECC 6.0 on Oracle 10.2.0.4.0
    Rgds

    Hi Srinivas,
    On ECC 6.0, go to ST04 t-code --> performance --> SQL Cache --> You see SQL Statements where you need to sort by SQL Statements by Total Execution Time(ms).
    I have tried on one of my R/3 4.7EE system, ST04n --> Resource COnsumption --> Top SQL Statements --> you will see 50 Top most expensive SQL Statements interms of wait time.
    also Read: [Re: Diagnosis of the expensive ABAP programs having database time > 90%;
                      [Please Read before Posting in the Performance and Tuning Forum;
    Regards,
    Kanthi Kiran

  • How to call a java class placed in java top?

    Hi,
    Can anyone please let me know how we can call the java class placed in the java top using PL/SQL?
    Thanks,
    Bharat

    Bharat ,
    Please refer this link , you can call java static method using sql function
    http://www.stanford.edu/dept/itss/docs/oracle/10g/java.101/b12021/invokeapp.htm
    Keerthi

Maybe you are looking for