Can analytical function support this requirement?

As a result of some Qry, I get the following result set.
Column1 Column2
A       100   
A       200
A       200
A       100
B       200
B       200
B       200
C       100
C       200
D       200
D       200
E       200
With this as input i had to take some decision like, For a particular Column1 value, if all the avaiable value of column2 is 200 (B, D & E in this case), i need to do one set of operations, if atleast one of the value for Column2 is non 200 (A & C in this case), i need to do another set of operation. How to frame the If clause or any other approach?
By using Analytical count(*) function, is it possible to generate something like
Column1 Column2   Column3(200_count)
A       100       2
A       200       2
A       200       2
A       100       2
B       200       3
B       200       3
B       200       3
C       100       1
C       200       1
D       200       3
D       200       3
E       200       3

hi,
Something lilke this?
with data as (
select 'A' column1,       100     column2 from dual union all
select 'A' column1,       200 from dual union all
select 'A' column1,       200 from dual union all
select 'A' column1,       100 from dual union all
select 'B' column1,       200 from dual union all
select 'B' column1,       200 from dual union all
select 'B' column1,       200  from dual union all
select 'C' column1,       100 from dual union all
select 'C' column1,       200 from dual union all
select 'D' column1,       200 from dual union all
select 'D' column1,       200 from dual union all
select 'E' column1,       200 from dual
select
column1,column2,count(0) over (partition by column1,column2) cnt
from data
order by column1The above query will count the occuerence of column2 for every column1.
If you want to count only 200 something like may help you.
with data as (
select 'A' column1,       100     column2 from dual union all
select 'A' column1,       200 from dual union all
select 'A' column1,       200 from dual union all
select 'A' column1,       100 from dual union all
select 'B' column1,       200 from dual union all
select 'B' column1,       200 from dual union all
select 'B' column1,       200  from dual union all
select 'C' column1,       100 from dual union all
select 'C' column1,       200 from dual union all
select 'D' column1,       200 from dual union all
select 'D' column1,       200 from dual union all
select 'E' column1,       200 from dual
select
column1,column2,sum(
case when column2=200 then
1
else
0
end
) over (partition by column1) cnt
from data
order by column1Regards,
Bhushan
Edited by: Buga added second query

Similar Messages

  • Photos/Fotos: One of the most important selection features the is "Star" rating. How on earth can you stop supporting this feature ???

    One of the most important selection features the is "Star" rating.
    How on earth can Apple stop supporting this feature ???
    My iPhoto lib contains >100´000 photos. All of them are rated with stars. Dependent on the rating I distribute the photos on >20 apple devices in our family.
    Many friends of mine do the same.
    It´s time for a severe request to Apple to take over that feature from iPhoto to Photos. They should start to learn, that people that liked their previously released software have spent hundreds of hours to adapt their data with that software to their needs. I´m using Mac´s since 1984. Might be that I start thinking about using different systems if they continue to through away my efforts from the past...
    If you dislike Apples latest moves and like this feature too you need to provide feedback to them on the following web page: www.apple.com/feedback
    Horst

    Remember that star ratings are not part of standard metadata.

  • Can analytic functions be used  in a cursor ?

    The following pl/sql code gives out the error as given below the code. However when the select staement in the cursor if run alone gives the results. Can someone tell me why. Can't analytic functions be used in cursors
    declare
    cursor cur1 is
    SELECT
    col1,
    col2,
    REGR_SLOPE(col1, LOG(10,col2))
    OVER(PARTITION BY col1 ORDER BY col2
    ROWS BETWEEN 2 PRECEDING AND UNBOUNDED FOLLOWING)
    from datatab;
    OVER(PARTITION BY col1 ORDER BY col2
    ERROR at line 7:
    ORA-06550: line 7, column 5:
    PLS-00103: Encountered the symbol "(" when expecting one of the following:
    , from

    Since it is a cursor, you can put the select statement in quotes which will execute the statement as dynamic SQL and allow the analytical function reference:
    open c for
      'SELECT col1, col2, REGR_SLOPE(col1, LOG(10,col2))
                          OVER(PARTITION BY col1 ORDER BY col2
                          ROWS BETWEEN 2 PRECEDING AND UNBOUNDED FOLLOWING)
         from datatab';
    loop
      fetch c into v_col1, v_col2, v_col3;
      exit when c%notfound;
      -- do something with values
    end loop;
    close c;

  • Can I use analytical function in this problem?

    Hi,
    I want to use query only for the following . I don't want to wright any function or procedure for this.
    create temp table test_3 (user_id number, auth_id number);
    insert into test_3 values (133,609);
    insert into test_3 values (133,610);
    insert into test_3 values (133,611);
    insert into test_3 values (133,612);
    insert into test_3 values (133,613);
    insert into test_3 values (133,614);
    insert into test_3 values (144,1);
    insert into test_3 values (134,610);
    insert into test_3 values (135,610);
    insert into test_3 values (135,610);
    insert into test_3 values (135,610);
    insert into test_3 values (136,610);
    insert into test_3 values (136,610);
    insert into test_3 values (137,610);
    insert into test_3 values (137,610);
    insert into test_3 values (137,609);
    insert into test_3 values (137,11);
    I want to count:
    1. for each auth_id, how many users are there who is assigned to this aut_id only
    example
    user_id 134 and 135 is assigned to auth_id 610 only and the count is 3 and 2 respectively .
    user_id 144 is assigned to auth_id 1 only and the count is 1.
    2.how many user_id is common between auth_id 609 and 610
    how many user_id is common between auth_id 609 and 611
    how many user_id is common between auth_id 609 and 612
    and so on.
    I have re-written the problem bellow
    Regards,
    Edited by: user576726 on Feb 13, 2011 3:54 AM

    Hi,
    user576726 wrote:
    Hi,
    Thanks for the response.
    drop table test_3;
    create table test_3 (user_id number, auth_id number);
    insert into test_3 values (133,609);     --row 1
    ...Thanks. That makes the problem a lot clearer.
    My desired output is:
    auth_id_1 auth_id_2 count1 count2
    1 12 1 --(user_id 144) 2 --(row 15, row 16)
    1 610 1 --(user_id 144) 1 --(row 19)
    11 609 1 --(user_id 137) 1 --(row 13)
    11 610 1 --(user_id 137) 2 --(row 11, row 12)
    12 1 1 --(user_id 144) 1 --(row 4)
    12 610 1 --(user_id 144) 1 --(row 19)
    609 11 1 --(user_id 137) 1 --(row 14)
    609 610 2 --(user_id 133 & 137) 3      --(row 2, row 11 and row 12)
    609 611 1 --(user_id 133) 1 --(row 3)
    610 1 1 --(user_id 144) 1 --(row 4)
    610 11 1 --(user_id 137) 1 --(row 14)
    610 12 1 --(user_id 144) 2 --(row 15, row 16)
    610 609 2 --(user_id 133 & 137) 4 --(row 1, row 13, row 17 and row 18)
    610 611 1 --(user_id 133) 1 --(row 3)
    611 609 1 --(user_id 133) 3 --(row 1, row 17 and row 18)
    611 610 1 --(user_id 133) 1 --(row 2)               1 --(user_id 133)               1 --(row 2)
    Count1 is the number of common different user id between auth_id_1 and auth_id_2
    example
    for the first row in the output:-
    common user ids between 609 and 610 are 133 and 137. so the count1 should be 2
    Count2 is how many rows are there for auth_id_2 where user id is common for auth_id_1 and auth_id_2
    example
    for the first row in the output:-
    the common user_id for 609 and 610 are 133 & 137
    the rows in the test_3 table that has auth_id 610 and user_id 133 & 137 are
    row 2, row 11 and row 12 so the count is 3.
    What I have done is
    I have writtent the following query to get the first two columns of the output:
    select tab1.auth_id auth_id_1, tab2.auth_id auth_id_2
    from
    (select user_id, auth_id
    from test_3
    group by user_id, auth_id
    ) tab1,
    (select user_id, auth_id
    from test_3
    group by user_id, auth_id
    ) tab2
    where tab1.user_id = tab2.user_id
    and tab1.auth_id <> tab2.auth_id
    group by tab1.auth_id, tab2.auth_id
    order by 1,2;You're on the right track. You're doing a self-join and getting the right combinations of auth_id_1 and auth_id_2.
    Why are you doing the GROUP BY in sub-queries tab1 and tab2? Eventually, you'll need to count identical rows, like these:
    insert into test_3 values (137,610);     --row 11
    insert into test_3 values (137,610);     --row 12If you do a GROUP BY in the sub-queries, all you'll know is that user_id=137 was related to auth_id=610. You won't know how many times, which is what count2 is based on. So don't do a GROUP BY in the sub-queries; just do the GROUP BY in the main query. That means you won't need to do sub-queries; you might as well just join two copies of the original test_3 table.
    Count1 is the number of common different user id between auth_id_1 and auth_id_2Great; that's very clear. In SQL, how do you count the number of different user_ids in such a group? (Hint "different" means the same thing as "distinct".)
    Count2 is how many rows are there for auth_id_2 where user id is common for auth_id_1 and auth_id_2
    example
    for the first row in the output:-The first row in the output you posted was
    1 12 1 --(user_id 144) 2 --(row 15, row 16)Isn't this one that you're explaining here the 8th row of output?
    the common user_id for 609 and 610 are 133 & 137
    the rows in the test_3 table that has auth_id 610 and user_id 133 & 137 are
    row 2, row 11 and row 12 so the count is 3.So, for count2, you want to know how many distinct rows from tab2 are in each group. If you had a primary key in the table, or anything that uniquely identified the rows, you could count the distinct occurrences of that, but you're not storing anything unique on each row (at least you haven't mentioned it in your sample data). If that's really the case, then this is one place where the ROWID pseudocolumn is handy; it uniquely identifies any row in any table, so you can just count how many different values of tab2.ROWID are in each group.

  • Can Analytical function give me this result?

    Hi Friends
    I have the following query:
    SELECT DISTINCT
          DATE_FIELD
          ,ACCT_ID
          ,CITY
          ,STATE
          ,ZIP
          ,UNIQUE_ID
          ,OPEN_DT
          ,TO_CHAR (ROW_NUMBER () OVER (PARTITION BY ACCT_ID ORDER BY ACCT_ID,OPEN_DT ) ) rn
    FROM TABLE1
    WHERE 1=1
    AND OPEN_DT IS NOT NULL This query gives me the following result:
    DATE_FIELD     | ACCT_ID     CITY | STATE | ZIP | UNIQUE_ID |OPEN_DT|RN
    1/02/2010|111|'CITY1'|'STATE1'|3333|2325|9/01/1987|1
    1/02/2010|111|'CITY2'|'STATE1'|3333|2090|19/01/1996|2
    1/02/2010|111|'CITY2'|'STATE1'|3333|2090|20/06/2002|3
    1/02/2010|111|'CITY2'|'STATE1'|3333|2090|20/06/2002|4
    1/02/2010|111|'CITY1'|'STATE1'|3333|2325|20/06/2002|5
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|9/08/1974|1
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|11/12/1980|2
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|5/12/1989|3
    1/02/2010|222|'CITY4'|'STATE1'|3350|8308|5/12/1989|4
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|5/12/1989|5
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|5/12/1989|6
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|4/08/1994|7
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|4/08/1994|8
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|4/08/1994|9
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|30/06/2000|10
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|4/12/2003|11
    1/02/2010|222|'CITY3'|'STATE1'|3350|9747|20/09/2004|12
    1/02/2010|222|'CITY4'|'STATE1'|3350|1794|22/10/2004|13
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|20/08/2009|14
    1/02/2010|222|'CITY4'|'STATE1'|3350|2278|17/09/2009|15
    1/02/2010|222|'CITY4'|'STATE1'|3350|2278|28/09/2009|16
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|1/10/2009|17
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|1/10/2009|18
    1/02/2010|222|'CITY4'|'STATE1'|3350|8308|2/10/2009|19
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|2/10/2009|20
    1/02/2010|333|'CITY5'|'STATE2'|5001|9905|17/06/2002|1
    1/02/2010|333|'CITY6'|'STATE2'|5016|3948|24/06/2002|2
    1/02/2010|333|'CITY5'|'STATE2'|5001|9905|3/09/2009|3
    1/02/2010|333|'CITY7'|'STATE2'|5020|6444|3/09/2009|4All I want is the rownumer having maximum rn value from abouve quey.
    How do I achieve this? Much appreciate a quick response.

    Hi,
    Not sure I understand what you mean by maximum rn value? Is it the same value in every row for each partition?
    If that's the case you could use count:
    SELECT DISTINCT
          DATE_FIELD
          ,ACCT_ID
          ,CITY
          ,STATE
          ,ZIP
          ,UNIQUE_ID
          ,OPEN_DT
          ,COUNT(*) OVER (PARTITION BY ACCT_ID) cnt
    FROM TABLE1
    WHERE 1=1
    AND OPEN_DT IS NOT NULLIf not, then perhaps can you post sample data showing what is it that you expect from the output, please? Something along the lines of what you have posted for the current output you're obtaining.

  • How to use time series functions for this requirement

    we are on OBIEE 11g (11.1.1.5)
    Any pointers and links are really helpful.
    I have a requirement where YTD sales are displayed in a column. We wan to compare that number to what that number was last year at the same time. Tried to use TODATE, AGO and it did not work.
    || used for column seperation below.
    ProductGroup || YTD Sales Rev||YTD Sales Rev 1 Year Ago||YTD Sales Rev 2 Years Ago
    Climate Solutions || 1.7 mil (1/1/2011 - 7/1/2011) || 1.45 mil (1/1/2010 - 7/1/2010) || 1.15 mil (1/1/2009 - 7/1/2009)
    Thanks in advance
    kris
    Edited by: user566193 on Aug 10, 2011 6:06 PM

    Kris,
    Basically you want to combine the 2 time series functions here i.e. TODATE & AGO.
    Here you go..
    You can create first a YTD logical column in BMM say YTD Sales Rev..Then create another logical column with calculation as AGO(YTD Sales Rev, YEARDIM, 1) or AGO(YTD Sales Rev, MONTHDIM, 12).
    Similarly, you create other measures...OBIEE 11g has time series function in Answers as well but I'd say try to create using RPD as you to calculate 1 logical column based on another. Better to push it on RPD side.
    Hope this helps

  • Please help me to write a function for this requirement!

    Hi,
        I have created a stored procedure which accepts 2 input parameters (param1 & param2 ) and its output is 'Score'
    Eg:
    Exec uspScorecalculation StudentID,DeptID 
    output: 85
    Now, My requirement is , I want to populate this value as one of the columns in a 'Select' statement.
    Can you please give me some input like how can i write a funtion to retrieve this score from the procedure and use it in the select statement?
    I assume,  the funciton should pass the two parameters into the stored procedure 'uspScorecalculation'  and retreives the Score.
    Can you please help me on this?
    thanks!

    >> I have created a stored procedure which accepts 2 input parameters (param1 & param2 ) and its output is 'Score' <<
    We have no idea from this posting what this procedure does. No code. No spec. Only a vague, useless narrative. 
    We do not put that silly “usp_” prefix on a proc name; this is one version of tibbling. When we wrote in FORTRAN I and II, we had to put “fn_” on user functions name. A procedure uses a “<verb>_<object>” format. Have you read ISO-11179 Standards
    or any book on data modeling?  
    EXEC Calculate_Something_Score student_id, dept_id; 
    >> Now, My requirement is, I want to populate this value as one of the columns in a 'SELECT' statement. <<
    Populate a column? We do not do that in a declarative language like SQL. The row with that column comes into existence all at once, and all the rows in the table come into existence all at once. This is a set-oriented language. 
    >> Can you please give me some input like how can I write a function to retrieve this score from the procedure and use it in the SELECT statement? <<
    NO! An SQL programmer will take the body of the procedure and replace the parameters with column names. It will be part of a SELECT statement and not a function call. We hate UDFs and other procedural constructs. 
    Please post the code and DDL, if you want help. Your failure and rudeness in not following Netiquette only hurt yourself. Your mindset is still locking into 1960's FORTRAN, not SQL. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Babylon 9 can not function in this version 9.0.1, while jv version 3.5.26 it works. why?

    as i said i have babylon dictionary and so far it works with firefox version 3.5, but recently i downloaded version 9. unfortunately babylon doesn't work with this new version.

    You can install the portable Firefox 3.6.x version, that comes with its own profile, to access websites that do not work with Firefox 5+.
    *http://portableapps.com/apps/internet/firefox_portable#legacy
    *http://portableapps.com/apps/internet/firefox_portable/localization#legacy36
    You probably need to create a new profile because the SQLite version used in Firefox 3.5 is not compatible the the SQLite version that is used by current Firefox versions.
    See "Basic Troubleshooting: Make a new profile":
    *https://support.mozilla.com/kb/Basic+Troubleshooting#w_8-make-a-new-profile
    If that new profile works then you can transfer some files from the old profile to that new profile, but be careful not to copy corrupted files.
    See:
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • How to use analytical function in this case

    SELECT COUNT (rms.status_code) rms_status_count,
    rms.status_name rms_status_name,
    TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date, 'YYYY') month_year,
    MAX (rtd.add_date) date_for_sort
    FROM ri_mast_status rms, ri_tran_data rtd
    WHERE rtd.status_code = rms.status_code
    AND TRUNC (MONTHS_BETWEEN (SYSDATE, rtd.add_date)) < 36
    AND NVL (rtd.delete_flg, '0') = '0'
    GROUP BY TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date, 'YYYY'),
    rms.status_name
    ORDER BY MAX (rtd.add_date);
    it gives output for the last 3 years based on month and year.

    r you trying this ?
    select *from
    select rms.*,
    row_number() over(partition by TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date,rms.status_name 'YYYY') order by rtd.add_date) RN,
    MAX(rtd.add_date) over(partition by TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date,rms.status_name 'YYYY')  order by rtd.add_date) date_for_sort,
    COUNT(rms.status_code) over(partition by TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date,rms.status_name 'YYYY')  order by rtd.add_date) rms_status_count
    FROM ri_mast_status rms, ri_tran_data rtd
    WHERE rtd.status_code = rms.status_code
    AND TRUNC (MONTHS_BETWEEN (SYSDATE, rtd.add_date)) < 36
    AND NVL (rtd.delete_flg, '0') = '0'
    where rn=1

  • Analytical function in OWB 10.2.0.4.0

    Dear -
    I am trying to implement analytical function in OWB but not sure how to do it. Can anyone help me?
    My SQL query looks like
    select sum (aamtorg),
    sum(sum(aamtorg)) over
    (order by cbssuntgbk, caccgbk, caccroo, ccrytrngbk, creftrl,
    cmgmint, cbasent, cbok, tamtlbl,
    cctygbk, caffgbk, dacggll, dctx
    rows between unbounded preceding and current row) cumulative_amountcctybbl
    from fmbnd_evt
    where cbssuntgbk = 'FM001'
    and caccgbk = '14300000029'
    and caccroo = '9146581'
    and ccrytrngbk = 'AUD'
    and creftrl = '~'
    and cmgmint = '~'
    and cbasent = 'U2725'
    and cbok = '0000'
    and tamtlbl = '~'
    and dacggll between '01aug2011' and '04aug11'
    group by cbssuntgbk, caccgbk, caccroo, ccrytrngbk, creftrl,
    cmgmint, ctrdnbmgint, cbasent, cbok, tamtlbl,
    cctygbk, caffgbk, dacggll, dctx
    I want to implement cumulative_amountcctybb column in the mapping.
    Can anyone help?

    Hi Arun,
    analytical functions don't require GROUP BY clause and that's why you can use an expression operator. You also have a normal SUM (aggregate) function in your query, which requires GROUP BY and can only be implemented using aggregator operator. If I understand your problem correctly, you need to use aggregate SUM with GROUP BY on your data set first, and then use analytical SUM on this set (which is already processed with an aggregate SUM). Your query would look something like this:
    select sum_aamtorg,
    sum(sum_aamtorg) over
    (order by cbssuntgbk, caccgbk, caccroo, ccrytrngbk, creftrl,
    cmgmint, cbasent, cbok, tamtlbl,
    cctygbk, caffgbk, dacggll, dctx
    rows between unbounded preceding and current row) cumulative_amountcctybbl
    from (
    select sum (aamtorg) sum_aamtorg,
    cbssuntgbk, caccgbk, caccroo, ccrytrngbk, creftrl,
    cmgmint, cbasent, cbok, tamtlbl,
    cctygbk, caffgbk, dacggll, dctx
    from fmbnd_evt
    where cbssuntgbk = 'FM001'
    and caccgbk = '14300000029'
    and caccroo = '9146581'
    and ccrytrngbk = 'AUD'
    and creftrl = '~'
    and cmgmint = '~'
    and cbasent = 'U2725'
    and cbok = '0000'
    and tamtlbl = '~'
    and dacggll between '01aug2011' and '04aug11'
    group by cbssuntgbk, caccgbk, caccroo, ccrytrngbk, creftrl,
    cmgmint, ctrdnbmgint, cbasent, cbok, tamtlbl,
    cctygbk, caffgbk, dacggll, dctx)
    Operator sequence would then look like: TABLE -> FILTER -> AGGREGATOR ->EXPRESSION.
    Hope this helps
    Mate
    Edited by: mate on Sep 26, 2011 1:36 PM
    Edited by: mate on Sep 26, 2011 1:36 PM

  • Analytic Functions in PL/SQL

    This procedure won't compile - the word PARTITION seems to be the problem - with this error...
    PLS-00103: Encountered the symbol "(" when expecting one of the following: , from
    The query in the cursor runs correctly as a stand-alone query. Can analytic functions not be used in PL/SQL cursors?
    Thanks.
    CREATE OR REPLACE
    PROCEDURE TestAnalyticFunction IS
    CURSOR GetAllTransTypes_Cursor IS
    select transaction_class.trans_desc,
    transaction_code.trans_type ,
    transaction_code.trans_code,
    transaction_code.trans_code_desc,
    sum(tr_tx_amt) as trans_sum,
    RATIO_TO_REPORT(sum(tr_tx_amt)) OVER
    (PARTITION BY transaction_code.trans_type) AS Percentage
    from transaction_code,
    transaction_class,
    transactions
    where TR_POST_DT IS NOT NULL
    AND TR_POST_DT >= '01-DEC-2000'
    AND TR_POST_DT <= '31-JAN-2001'
    AND TRANSACTION_CODE.TRANS_CLASS = TRANSACTION_CLASS.TRANS_CLASS_ID
    AND TRANSACTION_CODE.TRANS_CODE = TRANSACTIONS.TR_TX_CODE
    AND TRANSACTION_CODE.TRANS_TYPE in (1,2,3,4,5,8)
    group by transaction_code.trans_type,
    trans_class,
    trans_desc,
    trans_code,
    trans_code_desc
    order by transaction_code.trans_type, trans_code;
    TYPE TransClassDescType IS TABLE OF transaction_class.trans_desc%TYPE;
    TYPE TransCodeTypeType IS TABLE OF transaction_code.trans_type%TYPE;
    TYPE TransCodeCodeType IS TABLE OF transaction_code.trans_code%TYPE;
    TYPE TransCodeDescType IS TABLE OF transaction_code.trans_code_desc%TYPE;
    TYPE TotalType IS TABLE OF NUMBER(14,2);
    TYPE TotalPctType IS TABLE OF NUMBER(6, 2);
    TransClassDesc TransClassDescType;
    TransCodeType TransCodeTypeType;
    TransCodeCode TransCodeCodeType;
    TransCodeDesc TransCodeDescType;
    Total TotalType;
    TotalPct TotalPctType;
    BEGIN
    OPEN GetAllTransTypes_Cursor;
    FETCH GetAllTransTypes_Cursor BULK COLLECT INTO TransClassDesc,TransCodeType,TransCodeCode,TransCodeDesc,
    Total, TotalPct;
    CLOSE GetAllTransTypes_Cursor;
    END TestAnalyticFunction;
    null

    Some functions just don't seem to work in PL/SQL even though they work fine in SQL*Plus.
    Two such functions I found were NVL2 and RATIO_TO_REPORT.
    Have no clue why yet.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Dale Johnson ([email protected]):
    This procedure won't compile - the word PARTITION seems to be the problem - with this error...
    PLS-00103: Encountered the symbol "(" when expecting one of the following: , from
    The query in the cursor runs correctly as a stand-alone query. Can analytic functions not be used in PL/SQL cursors?
    Thanks.
    CREATE OR REPLACE
    PROCEDURE TestAnalyticFunction IS
    CURSOR GetAllTransTypes_Cursor IS
    select transaction_class.trans_desc,
    transaction_code.trans_type ,
    transaction_code.trans_code,
    transaction_code.trans_code_desc,
    sum(tr_tx_amt) as trans_sum,
    RATIO_TO_REPORT(sum(tr_tx_amt)) OVER
    (PARTITION BY transaction_code.trans_type) AS Percentage
    from transaction_code,
    transaction_class,
    transactions
    where TR_POST_DT IS NOT NULL
    AND TR_POST_DT >= '01-DEC-2000'
    AND TR_POST_DT <= '31-JAN-2001'
    AND TRANSACTION_CODE.TRANS_CLASS = TRANSACTION_CLASS.TRANS_CLASS_ID
    AND TRANSACTION_CODE.TRANS_CODE = TRANSACTIONS.TR_TX_CODE
    AND TRANSACTION_CODE.TRANS_TYPE in (1,2,3,4,5,8)
    group by transaction_code.trans_type,
    trans_class,
    trans_desc,
    trans_code,
    trans_code_desc
    order by transaction_code.trans_type, trans_code;
    TYPE TransClassDescType IS TABLE OF transaction_class.trans_desc%TYPE;
    TYPE TransCodeTypeType IS TABLE OF transaction_code.trans_type%TYPE;
    TYPE TransCodeCodeType IS TABLE OF transaction_code.trans_code%TYPE;
    TYPE TransCodeDescType IS TABLE OF transaction_code.trans_code_desc%TYPE;
    TYPE TotalType IS TABLE OF NUMBER(14,2);
    TYPE TotalPctType IS TABLE OF NUMBER(6, 2);
    TransClassDesc TransClassDescType;
    TransCodeType TransCodeTypeType;
    TransCodeCode TransCodeCodeType;
    TransCodeDesc TransCodeDescType;
    Total TotalType;
    TotalPct TotalPctType;
    BEGIN
    OPEN GetAllTransTypes_Cursor;
    FETCH GetAllTransTypes_Cursor BULK COLLECT INTO TransClassDesc,TransCodeType,TransCodeCode,TransCodeDesc,
    Total, TotalPct;
    CLOSE GetAllTransTypes_Cursor;
    END TestAnalyticFunction;<HR></BLOCKQUOTE>
    null

  • Analytic Functions in CONNECT BY Queries

    Can analytic functions be used in a CONNECT BY query? Are there limits?
    This problem occurs in Oracle 11.1.0.6.0, 10.2 and 10.1.
    Here is the presenting problem:
    Starting with data like this:
    CREATE TABLE     enrollment
    (      name          VARCHAR2 (10)
    ,      coursenumber     NUMBER
    INSERT INTO enrollment (name, coursenumber) VALUES ('Ted',      101);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Ted',      102);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Ted',      103);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Mary',      102);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Mary',      104);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Hiro',      101);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Hiro',      104);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Hiro',      105);
    COMMIT;I'm trying to get cross-tab output like this:
    NAME       TXT
    Hiro         101            104  105
    Mary              102       104
    Ted          101  102  103without knowing before-hand what course numbers, or even how many course numbers, will be in the results.
    My strategy was to use LPAD to make the course numbers always occupy 5 spaces.
    If n "columns" needed to be left blank before the number, I wanted to add 5n extra spaces.
    I tried this:
    WITH     universe     AS
         SELECT     name
         ,     coursenumber
         ,     DENSE_RANK () OVER ( ORDER BY        coursenumber)     AS cnum
         ,     ROW_NUMBER () OVER ( PARTITION BY  name
                                   ORDER BY          coursenumber
                           )                         AS snum
         FROM     enrollment
    SELECT     name
    ,     REPLACE ( SYS_CONNECT_BY_PATH ( LPAD ( TO_CHAR (coursenumber)
                                              , 5 * (cnum - LAG (cnum, 1, 0)
                                                                   OVER ( PARTITION BY  name
                                                                             ORDER BY          coursenumber
              )     AS txt
    FROM     universe
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     snum     = 1
    CONNECT BY     snum     = PRIOR snum + 1
    AND          name     = PRIOR name
    ORDER BY     name
    ;but the txt column was always NULL.
    I tried showing some of the intermediate calculations:
    WITH     universe     AS
         SELECT     name
         ,     coursenumber
         ,     DENSE_RANK () OVER ( ORDER BY        coursenumber)     AS cnum
         ,     ROW_NUMBER () OVER ( PARTITION BY  name
                                   ORDER BY          coursenumber
                           )                         AS snum
         FROM     enrollment
    SELECT     name
    ,     REPLACE ( SYS_CONNECT_BY_PATH ( LPAD ( TO_CHAR (coursenumber)
                                              , 5 * (cnum - LAG (cnum, 1, 0)
                                                                   OVER ( PARTITION BY  name
                                                                             ORDER BY          coursenumber
              )     AS txt
    ,     coursenumber
    ,     cnum
    ,     LAG (cnum, 1, 0) OVER ( PARTITION BY  name
                                                ORDER BY          coursenumber
                         )      AS lag_cnum
    FROM     universe
    -- WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     snum     = 1
    CONNECT BY     snum     = PRIOR snum + 1
    AND          name     = PRIOR name
    ORDER BY     name
    ;and they all seemed reasonable:
    NAME       TXT                            COURSENUMBER       CNUM   LAG_CNUM
    Hiro                                               101          1          0
    Hiro                                               104          4          1
    Hiro                                               105          5          4
    Mary                                               102          2          0
    Mary                                               104          4          2
    Ted                                                101          1          0
    Ted                                                102          2          1
    Ted                                                103          3          2but txt was still NULL.
    I got around the problem by computing the LAG in a sub-query (see [this thread|http://forums.oracle.com/forums/message.jspa?messageID=3875566#3875566]), but I'd like to know why LAG didn't work in the CONNECT BY query, or at least within SYS_CONNECT_BY_PATH.
    I've had other problems before trying to use analytic functions in CONNECT BY queries. Sometimes, the presence of an analytic function woudl cause CONNECT BY to never work, sometimes it would destroy the order of the output. (Sorry, I don't have those examples handy now.)
    Are there limitations on using analytic functions in a CONNECT BY query?
    is there a work-around other than computing the analytic functions in a sub-query?
    Thanks.

    how about
    SQL> with temp as
      2  (select name
      3       , coursenumber
      4    from enrollment
      5  )
      6  , courses as
      7  (select distinct
      8          coursenumber
      9     from enrollment
    10  )
    11  select name
    12       , replace (sys_connect_by_path (case when t_course is not null
    13         then rpad (t_course, 8, ' ')
    14         else rpad (' ', 8, ' ')
    15         end, ';'), ';', ' ') scbp
    16    from (
    17  select t.name
    18       , t.coursenumber t_course
    19       , c.coursenumber c_course
    20       , row_number() over (partition by t.name
    21                                order by c.coursenumber
    22                           ) rn
    23    from temp  t partition by (name)
    24    right outer
    25    join courses c
    26      on c.coursenumber = t.coursenumber
    27  )
    28   where connect_by_isleaf = 1
    29   start with rn = 1
    30   connect by rn = prior rn + 1
    31   and name = prior name;
    NAME       SCBP
    Hiro        101                        104      105
    Mary                 102               104
    Ted         101      102      103

  • How can we write this in analytical function..

    select a.employee_id,a.last_name,b.count from employees a, (select manager_id, count(manager_id) as count from employees group by manager_id) b where a.employee_id=b.manager_id;
    As per my requirement I need each manager name and no of employees reporting to him... above query works.. Could anybody help to write the same using analytic function.... Hw this same can be written in effiect way??? (quick performance)
    Please also share the link to download some doc to have good understanding of analytical function..
    Thanks in advance....

    are you trying to do a hierarchical type of query?
    select ename, count(ename) -1 numr_of_emps_under_this_mgr  from  emp
    connect by  empno =prior mgr
    group by ename
    order by count(ename) desc ;
    ENAME     NUMR_OF_EMPS_UNDER_THIS_MGR
    KING     13
    BLAKE     5
    JONES     4
    CLARK     1
    FORD     1
    SCOTT     1
    ADAMS     0
    TURNER     0
    MARTIN     0
    JAMES     0
    SMITH     0
    MILLER     0
    ALLEN     0
    WARD     0Here is the table structure I used (I think you can download it from oracle somewhere)
    CREATE TABLE EMP
      EMPNO     NUMBER(4)                           NOT NULL,
      ENAME     VARCHAR2(10 BYTE),
      JOB       VARCHAR2(9 BYTE),
      MGR       NUMBER(4),
      HIREDATE  DATE,
      SAL       NUMBER(7,2),
      COMM      NUMBER(7,2),
      DEPTNO    NUMBER(2)
    SET DEFINE OFF;
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7369, 'SMITH', 'CLERK', 7902, TO_DATE('12/17/1980 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        800, 20);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Values
       (7499, 'ALLEN', 'SALESMAN', 7698, TO_DATE('02/20/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        1600, 300, 30);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Values
       (7521, 'WARD', 'SALESMAN', 7698, TO_DATE('02/22/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        1250, 500, 30);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7566, 'JONES', 'MANAGER', 7839, TO_DATE('04/02/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        2975, 20);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Values
       (7654, 'MARTIN', 'SALESMAN', 7698, TO_DATE('09/28/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        1250, 1400, 30);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7698, 'BLAKE', 'MANAGER', 7839, TO_DATE('05/01/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        2850, 30);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7782, 'CLARK', 'MANAGER', 7839, TO_DATE('06/09/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        2450, 10);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7788, 'SCOTT', 'ANALYST', 7566, TO_DATE('12/09/1982 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        3000, 20);
    Insert into EMP
       (EMPNO, ENAME, JOB, HIREDATE, SAL, DEPTNO)
    Values
       (7839, 'KING', 'PRESIDENT', TO_DATE('11/17/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        5000, 10);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Values
       (7844, 'TURNER', 'SALESMAN', 7698, TO_DATE('09/08/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        1500, 0, 30);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7876, 'ADAMS', 'CLERK', 7788, TO_DATE('01/12/1983 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        1100, 20);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7900, 'JAMES', 'CLERK', 7698, TO_DATE('12/03/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        950, 30);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7902, 'FORD', 'ANALYST', 7566, TO_DATE('12/03/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        3000, 20);
    Insert into EMP
       (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
    Values
       (7934, 'MILLER', 'CLERK', 7782, TO_DATE('01/23/1982 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
        1300, 10);
    COMMIT;

  • I'm getting the error msg "apple application support was not found.  Apple application support is required to run itunes. error 2.  How can i fix this?

    Hi,  I was running itunes software just fine. I got some malware and unintalled everything that was from apple.  Now, I reinstalled itunes but can't run it because I get the msg "Apple application support was not found. Apple application support is required to run itunes. Error msg 2.
    What can I do to fix this?
    Thank you.

    With the Error 2, let's try a standalone Apple Application Support install. It still might not install, but fingers crossed any error messages will give us a better idea of the underlying cause of the issue.
    Download and save a copy of the iTunesSetup.exe (or iTunes64setup.exe) installer file to your hard drive:
    http://www.apple.com/itunes/download/
    Download and install the free trial version of WinRAR:
    http://www.rarlab.com/download.htm
    Right-click the iTunesSetup.exe (or iTunes64Setup.exe), and select "Extract to iTunesSetup" (or "Extract to iTunes64Setup"). WinRAR will expand the contents of the file into a folder called "iTunesSetup" (or "iTunes64Setup").
    Go into the folder and doubleclick the AppleApplicationSupport.msi to do a standalone AAS install.
    Does it install properly for you?
    If instead you get an error message during the install, let us know what it says. (Precise text, please.)

  • Can anyone tell me what this Time Machine error means? The network backup disk does not support the required AFP features?

    Can anyone tell me what this Time Machine error means? The network backup disk does not support the required AFP features?

    AFP - Apple Filing Protocol
    The Network Attached Storage (NAS) that you are pointing Time Machine at does not have the features needed by Time Machine in order to do its Thing.  Time Machine needs some specific features that are not typically available on generic networked storage devices.
    There are manufactures that support the Mac OS X HFS+ file system formats and implement all the needed AFP protocol packets necessary so that they can be used with Time Machine, but apparently yours does not.
    If you are not using a networked mounted volume for Time Machine, then more information will be needed about your Time Machine setup.

Maybe you are looking for

  • Value mapping in xslt mapping

    Hi, I have 2 mapping program one is main .xsl program and other one is value mapping program .xsl . I have zipped both the program and imported into Imported archive in IR but while testing in interface mapping i am getting error. error:could not com

  • 810 inbound INVOICE

    Hello,       When i try to post an inbound invoice 810 through edi. i have congifured all the FI part , i get the following error. please let me know what to do No tax code found for difference Message no. M8309 Diagnosis The invoice to be checked co

  • Add new topic in survey list

    Hello, How to add new topic/survey topic in survey list keeping previous one. And how to display survey list as a web part on a page. Thanking you in advance. Regards, Jayashri

  • The Moto X is no longer available for $.01 it ended 4/13/14 but still on Verizons sight

    Just a statement to let others know.

  • Tacac+ logins asking for enable password

    Hi, 7609 with the following IOS version.  Cisco IOS Software, c7600s72033_rp Software (c7600s72033_rp-ADVIPSERVICES-M), Version 15.2(4)S4a, RELEASE SOFTWARE (fc1) Tacacs+ users can successfully login via telnet but its asking for the enable password