RATIO_TO_REPORT

Hi to all,
I am new to OBI and I was using discoverer for a long time.
I made a new report in OBI, and I would like to create a calculation that would give me the same results as if I would use the RATIO_TO_REPORT function in discoverer.
If I select the "display as percentage" option, it automatically calculates the percentage based on the total, and I need it by subtotal. Other options don't seem to work for me (also selecting the a layer).
Could you help me?
Thanks
Nayeli

user11953039 wrote:
Is using RATIO_TO_REPORT to calculate percentage advisable?Here is a link to the documentation: http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions142.htm#SQLRF00691
It doesn't calculate percentages, but ratios. Hence the name. Where percentage = 100 * ratio.
Does it have performance issues.This question is too vague to answer, but -as with any function- it costs time to execute.
Regards,
Rob.

Similar Messages

  • How can i use the Ratio_to_report function in obiee

    Hi,
    I have to use ratio_to_report function to create the report.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions124.htm.
    this is the link which explains the usage of this function.This function computes the ratio of a value to the sum of a set of values.How can i achieve this in BI
    Please help me
    Thanks,
    saichand

    Hi Sai,
    One more approach is:
    Use pivot and duplicate the measure in Measures block.
    For Duplicated Measure, go to More Options > Show Data As > Index of > Column
    Even it serves the same purpose...
    Hope you got my point... :)

  • GROUP BY ROLLUP skews RATIO_TO_REPORT

    Hi Everyone,
    The RATIO_TO_REPORT works fine until I use GROUP BY ROLLUP, then my RATIO_TO_REPORT is incorrrect.
    I've tried every combination I can think of.
    Any suggestions?
    Thank You in Advance for Your Help,
    Lou
    SELECT
    a.language,
    a.count,
    LPAD(TO_CHAR(ROUND(RATIO_TO_REPORT(SUM(a.count)) OVER () * 100 ,2), '09.99') || '%',20,' ') AS "PERCENTAGE"
    FROM
    (SELECT 'English' AS "LANGUAGE", 1 AS "COUNT" FROM DUAL
    UNION ALL
    SELECT 'French', 3 FROM DUAL
    UNION ALL
    SELECT 'Klingon', 1 FROM DUAL
    ) a
    -- GROUP BY a.language, a.count -- COUNT & PERCENT ARE CORRECT BUT NO COUNT TOTAL
    GROUP BY ROLLUP(a.language), a.count -- COUNT AND COUNT TOTAL ARE CORRECT, BUT PERCENT IS SKEWED
    ORDER BY a.language, a.count

    SQL> SELECT
      2  a.language,
      3  a.count,
      4  LPAD(TO_CHAR(ROUND(RATIO_TO_REPORT(SUM(a.count)) OVER
      5    (partition by grouping_id(a.language, a.count)) * 100 ,2), '999.99') || '%',20,' ')
      6      AS "PERCENTAGE"
      7  FROM
      8  (SELECT 'English' AS "LANGUAGE", 1 AS "COUNT" FROM DUAL
      9  UNION ALL
    10  SELECT 'French', 3 FROM DUAL
    11  UNION ALL
    12  SELECT 'Klingon', 1 FROM DUAL
    13  ) a
    14  GROUP BY ROLLUP(a.language, a.count)
    15  ORDER BY a.language, a.count
    16  /
    LANGUAG      COUNT PERCENTAGE
    English          1               20.00%
    English                          20.00%
    French           3               60.00%
    French                           60.00%
    Klingon          1               20.00%
    Klingon                          20.00%
                                    100.00%
    7 linhas selecionadas.
    SQL>

  • Ratio_to_report into pl/sql procedure

    how can i use 'ratio_to_report' inside a stored procedure?

    from the SQL prompt (sqlplus) Use either "execute" or its abbreviation "exec" .
    SQL> create procedure x(y number)
      2  as
      3  begin
      4  dbms_output.put_line(y);
      5  end;
      6  /
    Procedure created.
    SQL> set serveroutput on size 1000000
    SQL> execute x(100);
    100
    PL/SQL procedure successfully completed.
    SQL> exec x(100);
    100
    PL/SQL procedure successfully completed.
    SQL>

  • How to achieve the querys in one statement

    <p>
    Hi,everyone:
    I have a table:
    create table my_cube
    (model char(10), theyear char(10), color char(10), units_sold smallint);
    </p>
    <p>
    To list the unit-sold percentage of the 'chevy' model in 1990, i write:
    </p>
    <p>
    select 1990, 'Chevy', round(( (select sum(units_sold) from my_cube where model='Chevy' and theyear=1990)/(select sum(units_sold) from my_cube where theyear=1990) )*100, 2) from dual;
    </p>
    <p>
    But i'm wondering is that possible to list all the unit-sold percentage of all models in every year in one statement? Could anyone help me. Thanks.
    </p>
    <p>
    Here are some values for test:
    insert into my_cube values('Chevy', 1990, 'Red', 5);
    insert into my_cube values('Chevy', 1990, 'White', 87);
    insert into my_cube values('Chevy', 1990, 'Blue', 12);
    insert into my_cube values('Chevy', 1991, 'Red', 54);
    insert into my_cube values('Chevy', 1991, 'White', 95);
    insert into my_cube values('Chevy', 1991, 'Blue', 19);
    insert into my_cube values('Chevy', 1992, 'Red', 31);
    insert into my_cube values('Chevy', 1992, 'White', 54);
    insert into my_cube values('Chevy', 1992, 'Blue', 11);
    insert into my_cube values('Ford', 1990, 'Red', 64);
    insert into my_cube values('Ford', 1990, 'White', 62);
    insert into my_cube values('Ford', 1990, 'Blue', 13);
    </p>

    First of all, don't use CHAR. Use VARCHAR2. Save yourself some headaches.
    Make the year column a number, and be careful about the column name MODEL. It's a reserved word.
    Aside from the above solution, you could also use the handy ratio_to_report function:
    SQL> select m_year, m_model
      2        ,sum(m_units_sold)
      3        ,ratio_to_report(sum(m_units_sold)) over (partition by m_year) r
      4  from   my_cube
      5  group  by m_year, m_model
      6  ;
                  M_YEAR M_MODEL       SUM(M_UNITS_SOLD)                    R
                    1990 Chevy                       104 .4279835390946502058
                    1990 Ford                        139 .5720164609053497942
                    1991 Chevy                       168                    1
                    1992 Chevy                        96                    1

  • Getting counts and divide by sum in a single Pivot query

    Hi,
    I have a pivot query which gives the counts of all codes. I also have to divide the count with the total in the same query.
    e.g
      col1          col2                   col3
    error_1       05-Jun-2012       parts
    error_1      05_june_2012     parts
    error_1      04_june_2012     consumables
    error_2      04_june_2012     consumables
    error_3      03_june_2012     parts
    .Now the output should have the counts/divided by sum multiplied by 100. Basically, the percentage.
    output will be something like
    error                     June-2012                                 May-2012                              Feb-2012 ....      headers
    error_1                    60%                                          0 %                                         0%
    error_2                    20%                                          0                                             0%
    error_3                    20%                                           0%                                         0%Any suggestions please?
    Thanks,
    Sun

    with
    t1 as
    (select 'error_1' col1,trunc(sysdate) - 1 col2 from dual union all
    select 'error_1',trunc(sysdate) - 1 from dual union all
    select 'error_1',trunc(sysdate) + 30 from dual union all
    select 'error_2',trunc(sysdate) + 31 from dual union all
    select 'error_3',trunc(sysdate) - 2 from dual union all
    select 'error_3',trunc(sysdate) + 30 from dual union all
    select 'error_1',trunc(sysdate) - 3 from dual union all
    select 'error_2',trunc(sysdate) - 2 from dual union all
    select 'error_3',trunc(sysdate) + 30 from dual union all
    select 'error_4',trunc(sysdate) - 6 from dual
    select col1,
           count(case to_char(col2,'mon') when 'jul' then 1 end) one,
           100 * ratio_to_report(count(case to_char(col2,'mon') when 'jul' then 1 end)) over () x,
           count(case to_char(col2,'mon') when 'jun' then 1 end) two,    
           100 * ratio_to_report(count(case to_char(col2,'mon') when 'jun' then 1 end)) over () y
      from t1
    group by col1
    order by col1Regards
    Etbin
    Edited by: Etbin on 8.6.2012 14:15
    used next month to keep english and slovenian 'mon' the same ;)

  • Flash Chart : Percentage values in the pie chart and  values in the legend

    Hi All,
    Query is :
    SELECT null link
    ,GN.region Region
    ,ROUND(100*ratio_to_report(COUNT(DISTINCT GN.submittedbyemail)) over (),2) value
    FROM goodnews_stories GN
    GROUP BY GN.region
    I use the above query to display the flash pie chart percentage values.
    The values are displayed in percentage in legend as well as on the chart.
    I need to display the values in the legend and percentage values in the chart.
    How this can be achieved ?
    Regards,
    Archana

    Hello,
    Can we do this using apex? I have observed in legend as well as on chart it displays the same values which are generated by the sql query.
    Regards,
    Archana

  • Error ORA-01017 happened when dbms_scheduler run a job.

    Hi All,
    I got a problem when I use dbms_scheduler to run a job. I got Error code 1017 when the job is run by scheduler. Please find my steps below:
    Oracle version is : Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    1. Created a job successfully by using the code below:
    begin
    dbms_scheduler.create_job(
    job_name => 'monthly_refresh_elec_splits',
    job_type => 'PLSQL_BLOCK',
    job_action => 'BEGIN TRADINGANALYSIS.PKG_IM_REPORTING_ERM.REFRESH_ELEC_SPLITS_TEST; commit; END;',
    start_date => SYSTIMESTAMP,
    repeat_interval => 'freq=monthly;bymonthday=25;byhour=10;byminute=35;bysecond=0;',
    end_date => NULL,
    enabled => TRUE,
    comments => 'monthly_refresh_elec_splits.',
    auto_drop => FALSE
    end;
    2. Got the job run details from talbe user_scheduler_job_run_details after the job is finished:
    select * from user_scheduler_job_run_details where job_name = 'MONTHLY_REFRESH_ELEC_SPLITS' order by log_id desc;
    LOG_ID     LOG_DATE     OWNER     JOB_NAME     JOB_SUBNAME     STATUS     ERROR#     REQ_START_DATE     ACTUAL_START_DATE     RUN_DURATION     INSTANCE_ID     SESSION_ID     SLAVE_PID     CPU_USED     DESTINATION     ADDITIONAL_INFO
    2054804     25/06/2012 10:35:01.086000 AM +10:00     TRADINGANALYSIS     MONTHLY_REFRESH_ELEC_SPLITS          FAILED     1017     25/06/2012 10:35:00.300000 AM +10:00     25/06/2012 10:35:00.400000 AM +10:00     +00 00:00:01.000000     1     1025,37017     129396     +00 00:00:00.030000          ORA-01017: invalid username/password; logon denied
    ORA-02063: preceding line from NETS
    ORA-06512: at "TRADINGANALYSIS.PKG_IM_REPORTING_ERM", line 574
    ORA-06512: at line 1
    3. If I run the job directly the job will be finished successfully.
    begin
    dbms_scheduler.run_job('monthly_refresh_elec_splits',TRUE);
    end;
    LOG_ID     LOG_DATE     OWNER     JOB_NAME     JOB_SUBNAME     STATUS     ERROR#     REQ_START_DATE     ACTUAL_START_DATE     RUN_DURATION     INSTANCE_ID     SESSION_ID     SLAVE_PID     CPU_USED     DESTINATION     ADDITIONAL_INFO
    2054835     25/06/2012 11:05:38.515000 AM +10:00     TRADINGANALYSIS     MONTHLY_REFRESH_ELEC_SPLITS          SUCCEEDED     0     25/06/2012 11:04:35.787000 AM +10:00     25/06/2012 11:04:35.787000 AM +10:00     +00 00:01:03.000000     1     1047,700          +00 00:00:00.030000
    Additional Info:
    PL/SQL Code in procedure
    PROCEDURE Refresh_Elec_Splits_Test IS
    BEGIN
    --Refresh im_fact_nets_genvol from v_im_facts_nets_genvol in NETS
    DELETE FROM IM_FACT_NETS_GENVOL;
    --the local NETS_GENVOL table has an additional column providing volume splits by generator and month.
    --INSERT INTO IM_FACT_NETS_GENVOL values ('test',sysdate,'test',1,2,3,4,5,6,7);
    INSERT INTO IM_FACT_NETS_GENVOL
    select ngv.*,
    ratio_to_report (net_mwh) OVER (PARTITION BY settlementmonth, state)
    gen_percent
    from [email protected] ngv;
    commit;
    END;
    Does anyone can advice where should I check and how can I solve the problem?
    Thanks in advance
    Edited by: user13244529 on 24/06/2012 18:33
    Edited by: user13244529 on 24/06/2012 18:43

    I apologize if you already solved this.. but see Metalink ID 790221.1
    +*<Moderator Edit - deleted contents of MOS Doc - pl do NOT post such content - it is a violation of your Support agreement>*+                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help need in sql

    i have a scenario like
    bank_division sum(amount) total_percentage(calculated by : / total sum of adjacent amounts i.e(10000+2000+3000+4000) *100
    aaaa 10000
    bbb 2000
    ccc 3000
    dddd 40000
    for above thing i have written sql like
    select bank_division,sum(amount)  from bank group by bank;
    but i am unable to calculate percentage for each bank_division..........
    .its like for aaaa correspoding percentage will be
    10000/ total sum of adjacent amounts i.e(10000+2000+3000+4000) *100
    and for bbb it will be
    2000/ total sum of adjacent amounts i.e(10000+2000+3000+4000) *100
    so on...
    can any one help me how to write in single sql

    user632733 wrote:
    in your sql you are using lag to display from existing total_sal....which cant be possible in above scenario..??? Where did you see existing total_sal? EMP table:
    SQL> select deptno,ename,sal from emp
      2  /
        DEPTNO ENAME             SAL
            20 SMITH             800
            30 ALLEN            1600
            30 WARD             1250
            20 JONES            2975
            30 MARTIN           1250
            30 BLAKE            2850
            10 CLARK            2450
            20 SCOTT            3000
            10 KING             5000
            30 TURNER           1500
            20 ADAMS            1100
        DEPTNO ENAME             SAL
            30 JAMES             950
            20 FORD             3000
            10 MILLER           1300
    14 rows selected.
    SQL> As you can see, there are multiple employees in each department. Now look at mu solution. Inner select:
             select  deptno,
                     sum(sal) total_sal
               from  emp
               group by deptnosummarizes sal for each department. If you run it separately:
    SQL>          select  deptno,
      2                   sum(sal) total_sal
      3             from  emp
      4             group by deptno
      5  /
        DEPTNO  TOTAL_SAL
            30       9400
            20      10875
            10       8750
    SQL> Outer select calculates previous department total salary and its ratio to report.
    SY.
    P.S. And if you want to display individual employees along with department level summarization:
    select  deptno,
            ename,
            total_sal,
            prev_deptno,
            last_value(total_sal) over(order by deptno range between unbounded preceding and 1 preceding) prev_dept_total_sal,
            ratio_to_report(total_sal) over () * 100
      from  (
             select  deptno,
                     ename,
                     sum(sal) over(partition by deptno) total_sal,
                     max(deptno) over(order by deptno range between unbounded preceding and 1 preceding) prev_deptno
               from  emp
      order by deptno
        DEPTNO ENAME       TOTAL_SAL PREV_DEPTNO PREV_DEPT_TOTAL_SAL RATIO_TO_REPORT(TOTAL_SAL)OVER()*100
            10 MILLER           8750                                                           6.38569604
            10 KING             8750                                                           6.38569604
            10 CLARK            8750                                                           6.38569604
            20 ADAMS           10875          10                8750                           7.93650794
            20 FORD            10875          10                8750                           7.93650794
            20 JONES           10875          10                8750                           7.93650794
            20 SMITH           10875          10                8750                           7.93650794
            20 SCOTT           10875          10                8750                           7.93650794
            30 WARD             9400          20               10875                           6.86006203
            30 TURNER           9400          20               10875                           6.86006203
            30 ALLEN            9400          20               10875                           6.86006203
        DEPTNO ENAME       TOTAL_SAL PREV_DEPTNO PREV_DEPT_TOTAL_SAL RATIO_TO_REPORT(TOTAL_SAL)OVER()*100
            30 JAMES            9400          20               10875                           6.86006203
            30 BLAKE            9400          20               10875                           6.86006203
            30 MARTIN           9400          20               10875                           6.86006203
    14 rows selected.
    SQL>

  • How to distinguish built-in SQL functions of PL/SQL?

    I m having a hard time to figure out which functions are used ONLY in SQL statements and which are used in regular expr(ie, variable assignment,). Can anyone show me a list of each or perhaps a URL to look for?
    I have searched through either the developer's guide and reference but couldn't find any appropriate indication in one place that make it clear.
    For instance, I thought I can use CAST function in a variable assginment like the following:
    declare
    cursor myCur is SELECT Value_varchar2(1) FROM table WHERE id = 1;
    myRec myCur%ROWTYPE;
    var_a NUMBER(1);
    begin
    OPEN myCur;
    FETCH myCur INTO myRec;
    CLOSE myCur;
    var_a := CAST(myCur.Value_varchar2(1) AS NUMBER(1));
    DBMS_OUTPUT.PUT_LINE('var_a = ' || TO_CHAR(var_a));
    end;
    . It seems like CAST function can ONLY be used in SQL statement, but no doc so far states that?!
    Edited by: HappyJay on 2010/05/12 12:05

    Sorry to bother you, Bob!
    I think I might already found the list. Is it the following list?
    ---------------------- QUOTED FROM Oracle® Database PL/SQL Language Reference 11g Release 2 (11.2)Part Number E10472-06
    SQL Functions in PL/SQL Expressions
    In PL/SQL expressions, you can use all SQL functions except:
    Aggregate functions (such as AVG and COUNT)
    Analytic functions (such as LAG and RATIO_TO_REPORT)
    Data mining functions (such as CLUSTER_ID and FEATURE_VALUE)
    Encoding and decoding functions (such as DECODE and DUMP)
    Model functions (such as ITERATION_NUMBER and PREVIOUS)
    Object reference functions (such as REF and VALUE)
    XML functions (such as APPENDCHILDXML and EXISTSNODE)
    These conversion functions:
    BIN_TO_NUM
    These miscellaneous functions:
    CUBE_TABLE
    DATAOBJ_TO_PARTITION
    LNNVL
    NVL2
    SYS_CONNECT_BY_PATH
    SYS_TYPEID
    WIDTH_BUCKET
    PL/SQL supports an overload of BITAND for which the arguments and result are BINARY_INTEGER.
    When used in a PL/SQL expression, the RAWTOHEX function accepts an argument of data type RAW and returns a VARCHAR2 value with the hexadecimal representation of bytes that comprise the value of the argument. Arguments of types other than RAW can be specified only if they can be implicitly converted to RAW. This conversion is possible for CHAR, VARCHAR2, and LONG values that are valid arguments of the HEXTORAW function, and for LONG RAW and BLOB values of up to 16380 bytes.
    ----------------------

  • Decimal places in charts

    Hi
    I have this SQL code for a pie chart and it rounds items down to 0% instead of showing decimal places. Is is possible to change it to show 0.5% for example?
    select null link, PRODUCT label, 100*ratio_to_report(COUNT(ID)) over () value
    from CHART_BY_PRODUCT
    WHERE REGION = NVL(REPLACE(:P17_REGION, '%null'||'%', NULL), REGION)
    AND LOB = NVL(REPLACE(:P17_LOB, '%null'||'%', NULL), LOB)
    AND TRUNC(TO_DATE(DATECALLED)) BETWEEN TRUNC(TO_DATE(:P17_FROM_DATE))
    AND TRUNC(TO_DATE(:P17_TO_DATE))
    group by PRODUCT
    order by count(id) descRegards
    Adam

    Basically this function - 100*ratio_to_report(COUNT(ID)) over () - is showing values in percentage. i.e. 40%, 20%, 5%, 1%, 0%.
    I want it to show the percentage with decimal places i.e 40.52%, 20.3%, 5.2%, 1.25%, 0.25%
    Can I change the function somehow to show two decimal places?
    Thanks
    Adam

  • Function returning SQL query for mutiple series in a chart

    Hi,
    I would like to know if there is a way to specify a single PL/SQL function returning the queries for multiple series in a 2D Line Flash Chart. I have multiple series in my chart that has different values in the where clause. I can write a PL/SQL function that can return all these queries in one shot. Is there anyway that I can specify this function as returning the queries for all the series in the chart?
    As an example, assume that I am using the following three queries for the series in my chart:
    select deptno, count(*) from emp where deptno = 10 group by deptno
    select deptno, count(*) from emp where deptno = 20 group by deptno
    select deptno, count(*) from emp where deptno = 30 group by deptno
    I can't write a PL/SQL function that returns a query in the multiple series syntax (SELECT link, label, series_1_value [, series_2_value [, ...]]FROM ...) as I am using an aggregate function and my where clause is different for each series.
    Thanks,
    Rupesh

    Hi Roel,
    Thanks for your reply. I am already using an analytical function (RATIO_TO_REPORT(COUNT(*)) OVER () ) in my actual report. My problem is that the query for one series differs from the other only in one where clause. I will be able to dynamically able to generate all the queries for all the series in one pl/sql function. But the chart definition screen does not allow us to define a single function that returns queries for the all the series - possibly seperated by some seperator like S1: select.... S2:select and so on.
    Regards,
    Rupesh

  • Case Decode - invalid column name error

    select Workweek, max( decode( Type, T34, prct, null ) ) Bad,
                        max( decode( Type, T35, prct, null ) ) Repair,
                        max( decode( Type, T36, prct, null ) ) Good
    FROM
    (select Workweek, Type, round(ratio_to_report(sum(Testtime_in_Minutes)) over(partition by Workweek)*100,3) prct
    FROM
    (select ts.lot as Lot, ts.wafer_id as Wafer, dt.SORT_X as X, dt.SORT_Y as Y, ts.devrevstep as PRODUCT, ts.operation as OPERATION, dt.INTERFACE_BIN as INTERFACE_BIN, (dt.TEST_TIME)/60.0 as Testtime_in_Minutes,
    ts.TEST_END_DATE_TIME as Test_End_Time, ts.Program_Name, ts.test_end_work_week as Workweek,
    (CASE
    WHEN (dt.INTERFACE_BIN > 9 AND dt.INTERFACE_BIN < 15) THEN 'T34'
    WHEN (dt.INTERFACE_BIN =30 OR dt.INTERFACE_BIN =31 OR dt.INTERFACE_BIN = 32 OR dt.INTERFACE_BIN = 33) THEN 'T35'
         ELSE 'T36'
         END ) Type
    from a_testing_session ts, a_device_testing dt
    where ts.test_end_work_week >= 200715
    and (ts.devrevstep like '9600%')
    and dt.lao_start_ww = ts.test_end_work_week
    and dt.ts_id = ts.ts_id)
    GROUP BY Workweek, Type)
    This sql query above does not run properly, gives invalid column name error. However, the entire select statement surrounded by the () works. There must be an error in the first 4 lines someplace, but I do not see it.

    Assuming type is a string, I assume you meant
    MAX( DECODE( type, 'T34', prct, NULL )) Badwhere T34 is a string literal. Otherwise, you'd need to have columns named T34, T35, and T36 in your inner select.
    One note, though, it's probably a bad idea to have a column named Type. While it's legal to do so, TYPE is a keyword in SQL, so that name will at a minimum be confusing.
    Justin

  • How can I get an execution plan for a Function in oracle 10g

    Hi
    I have:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    I would like to know if is possible to get an EXECUTION PLAN for a FUNCTION if so, how can I get it ?
    Regards

    You can query the AWR data if your interesting SQL consumes enough resources.
    Here is a SQL*Plus script I call MostCPUIntensiveSQLDuringInterval.sql (nice name eh?)
    You'll need to know the AWR snap_id numbers for the time period of interest, then run it like this to show the top 20 SQLs during the interval:
    @MostCPUIntensiveSQLDuringInterval 20The script outputs a statement to run when you are interested in looking at the plan for an interesting looking statement.
    -- MostCPUintesticeSQLDuringInterval: Report on the top n SQL statements during an AWR snapshot interval.
    -- The top statements are ranked by CPU usage
    col inst_no             format      999 heading 'RAC|Node'
    col sql_id              format a16      heading 'SQL_ID'
    col plan_hash_value     format 999999999999 heading 'Plan|hash_value'
    col parsing_schema_name format a12      heading 'Parsing|Schema'
    col module              format a10      heading 'Module'
    col pct_of_total   format        999.99 heading '% Total'
    col cpu_time       format   999,999,999 heading 'CPU     |Time (ms)'
    col elapsed_time   format   999,999,999 heading 'Elapsed |Time (ms)'
    col lios           format 9,999,999,999 heading 'Logical|Reads'
    col pios           format   999,999,999 heading 'Physical|Reads'
    col execs          format    99,999,999 heading 'Executions'
    col fetches        format    99,999,999 heading 'Fetches'
    col sorts          format       999,999 heading 'Sorts'
    col parse_calls    format       999,999 heading 'Parse|Calls'
    col rows_processed format   999,999,999 heading 'Rows|Processed'
    col iowaits        format   999,999,999,999 heading 'iowaits'
    set lines 195
    set pages 75
    PROMPT Top &&1 SQL statements during interval
    SELECT diff.*
    FROM (SELECT e.instance_number inst_no
                ,e.sql_id
                ,e.plan_hash_value
                ,e.parsing_schema_name
                ,substr(trim(e.module),1,10) module
                ,ratio_to_report(e.cpu_time_total - b.cpu_time_total) over (partition by 1) * 100 pct_of_total
                ,(e.cpu_time_total - b.cpu_time_total)/1000 cpu_time
                ,(e.elapsed_time_total - b.elapsed_time_total)/1000 elapsed_time
                ,e.buffer_gets_total - b.buffer_gets_total lios
                ,e.disk_reads_total - b.disk_reads_total pios
                ,e.executions_total - b.executions_total execs
                ,e.fetches_total - b.fetches_total fetches
                ,e.sorts_total - b.sorts_total sorts
                ,e.parse_calls_total - b.parse_calls_total parse_calls
                ,e.rows_processed_total - b.rows_processed_total rows_processed
    --            ,e.iowait_total - b.iowait_total iowaits
    --            ,e.plsexec_time_total - b.plsexec_time_total plsql_time
          FROM dba_hist_sqlstat b  -- begining snap
              ,dba_hist_sqlstat e  -- ending snap
          WHERE b.sql_id = e.sql_id
          AND   b.dbid   = e.dbid
          AND   b.instance_number = e.instance_number
          and   b.plan_hash_value = e.plan_hash_value
          AND   b.snap_id = &LowSnapID
          AND   e.snap_id = &HighSnapID
          ORDER BY e.cpu_time_total - b.cpu_time_total DESC
         ) diff
    WHERE ROWNUM <=&&1
    set define off
    prompt  to get the text of the SQL run the following:
    prompt  @id2sql &SQL_id
    prompt .
    prompt  to obtain the execution plan for a session run the following:
    prompt  select * from table(DBMS_XPLAN.DISPLAY_AWR('&SQL_ID'));
    prompt  or
    prompt  select * from table(DBMS_XPLAN.DISPLAY_AWR('&SQL_ID',NULL,NULL,'ALL'));
    prompt .
    set define on
    undefine LowSnapID
    undefine HighSnapIDI guess you'll need the companion script id2sql.sql, so here it is:
    set lines 190
    set verify off
    declare
       maxDisplayLine  NUMBER := 150;  --max linesize to display the SQL
       WorkingLine     VARCHAR2(32000);
       CurrentLine     VARCHAR2(64);
       LineBreak       NUMBER;
       cursor ddl_cur is
          select sql_id
            ,sql_text
          from v$sqltext_with_newlines
          where sql_id='&1'
          order by piece
       ddlRec ddl_cur%ROWTYPE;
    begin
       WorkingLine :='.';
       OPEN ddl_cur;
       LOOP
          FETCH ddl_cur INTO ddlRec;
          EXIT WHEN ddl_cur%NOTFOUND;
          IF ddl_cur%ROWCOUNT = 1 THEN
             dbms_output.put_line('.');
             dbms_output.put_line('   sql_id: '||ddlRec.sql_id);
             dbms_output.put_line('.');
             dbms_output.put_line('.');
             dbms_output.put_line('SQL Text');
             dbms_output.put_line('----------------------------------------------------------------');
          END IF;
          CurrentLine := ddlRec.sql_text;
          WHILE LENGTH(CurrentLine) > 1 LOOP
             IF INSTR(CurrentLine,CHR(10)) > 0 THEN -- if the current line has an embeded newline
                WorkingLine := WorkingLine||SUBSTR(CurrentLine,1,INSTR(CurrentLine,CHR(10))-1);  -- append up to new line
                CurrentLine := SUBSTR(CurrentLine,INSTR(CurrentLine,CHR(10))+1);  -- strip off up through new line character
                dbms_output.put_line(WorkingLine);  -- print the WorkingLine
                WorkingLine :='';                   -- reset the working line
             ELSE
                WorkingLine := WorkingLine||CurrentLine;  -- append the current line
                CurrentLine :='';  -- the rest of the line has been processed
                IF LENGTH(WorkingLine) > maxDisplayLine THEN   -- the line is morethan the display limit
                   LineBreak := instr(substr(WorkingLine,1,maxDisplayLine),' ',-1); --find the last space before the display limit
                   IF LineBreak = 0 THEN -- there is no space, so look for a comma instead
                      LineBreak := substr(WorkingLine,instr(substr(WorkingLine,1,maxDisplayLine),',',-1));
                   END IF;
                   IF LineBreak = 0 THEN -- no space or comma, so force the line break at maxDisplayLine
                     LineBreak := maxDisplayLine;
                   END IF;
                   dbms_output.put_line(substr(WorkingLine,1,LineBreak));
                   WorkingLine:=substr(WorkingLine,LineBreak);
                END IF;
             END IF;
          END LOOP;
          --dbms_output.put(ddlRec.sql_text);
       END LOOP;
       dbms_output.put_line(WorkingLine);
       dbms_output.put_line('----------------------------------------------------------------');
       CLOSE ddl_cur;
    END;
    /

  • CPU,Temp utilization for a particular schema

    Hi,
    There is a requirement to get the CPU utilization at a schema level for a particular database.
    Is this something we can get from AWR reports?
    Is there any other way of getting these reports.
    Regards,
    Narayan

    AWR, yes
    Try:
    select a.username, count(*) "ON CPU", ratio_to_report(count(*)) over() ratio
    from dba_users a, dba_hist_active_sess_history b
    where a.user_id = b.user_id
    and b.session_state = 'ON CPU'
    and b.session_type = 'FOREGROUND' --comment out if needed
    group by a.username
    order by 2 desc;HTH

Maybe you are looking for

  • Help with password encryption

    Hello I am trying to create a one way hash password encryption...here is what I have developed so far..... Login class (contains GUI) import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.awt.image.*; import

  • Touch displays PLAY icon while in safari then crashes....

    Not sure if you are having this problem too! However - when Im surfing the touch I notice that I get a little PLAY icon beside my battery, which is indicating that I am listening to music while surfing which you CANNOT do. The only way to fix this pr

  • Photo shop on a mac?

    Hi can you get photoshop on a mac pro cause every time i try to download it it comes up with an error????

  • To convert SAP screens to Adobe flex..

    Hi All, We have a requirment to convert SAP screen to Adobe flex, which support tasks such as decision making with dynamic charts and visualizations. Any pointers for the same will be helpful. Regards Nitin.

  • Use Homepage SSL certificate as exchange server certificate?

    the certicate needs to match the fully qualified domain name that you connect against. so if the web site uses www.domain.de and the echange server's OWA/Activesync is owa.domain.de it wont match and you'll get errors. However if the SSL cert is wild