Oracle Analytic Function Issue

Hi, I have created a simple table contaning 3 columns and 3 records.
Insert into MYTABLE (ID, AMOUNT, RESULT) Values (1, 1, 1);
Insert into MYTABLE (ID, AMOUNT, RESULT) Values (2, 4, 1);
Insert into MYTABLE (ID, AMOUNT, RESULT) Values (3, 7, 0);
COMMIT;
I can SUM the AMOUNT using the analytic functions as
SELECT ID, AMOUNT, RESULT, SUM(AMOUNT) OVER() as TOTAL
FROM MYTABLE;
ID      AMOUNT      RESULT      TOTAL
1      1      1      12
2      4      1 12
3      7      0      12
What I want to be able to do is summing the AMOUNTs by RESULT in this case 0 and 1.
To get the following result, how should I rewrite the query?
ID      AMOUNT      RESULT      TOTAL RESULT_0_TOTAL RESULT_1_TOTAL
1 1 1      12 7 5
2      4      1      12 7 5
3      7      0      12 7 5

SELECT ID, AMOUNT, RESULT
, SUM(CASE WHEN RESULT = 0 THEN AMOUNT ELSE 0 END) OVER() as TOTAL_0
, SUM(CASE WHEN RESULT = 1 THEN AMOUNT ELSE 0 END) OVER() as TOTAL_1
FROM MYTABLE;

Similar Messages

  • Oracle Analytic function tuning

    Hi all,
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE 10.2.0.3.0 Production
    TNS for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - Productio
    NLSRTL Version 10.2.0.3.0 - Production
    I have a query which has analytic function uses large space on temporary tablespace resulting in direct path temp read and direct path temp write wait events taking too much time. Is there any way to tune such query?
    Thanks in advance.

    user9074365 wrote:
    Hi all,
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE 10.2.0.3.0 Production
    TNS for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - Productio
    NLSRTL Version 10.2.0.3.0 - Production
    I have a query which has analytic function uses large space on temporary tablespace resulting in direct path temp read and direct path temp write wait events taking too much time. Is there any way to tune such query?
    With your version of Oracle, and high-volumes of data going through analytic function, it's likely that this blog note applies. You may need an upgrade or special patch. http://jonathanlewis.wordpress.com/2009/09/07/analytic-agony/
    Regards
    Jonathan Lewis

  • Help with Oracle Analytic Function scenario

    Hi,
    I am new to analytic functions and was wondering if someone could help me with the data scenario below. I have a table with the following data
    COLUMN A COLUMN B COLUMN C
    13368834 34323021 100
    13368835 34438258 50
    13368834 34438258 50
    13368835 34323021 100
    The output I want is
    COLUMN A COLUMN B COLUMN C
    13368834 34323021 100
    13368835 34438258 50
    A simple DISTINCT won't give me the desired output so i was wondering if there is any way that I can get the result using ANALYTIC FUNCTIONS and DISTINCT ..
    Any help will be greatly appreciated.
    Thanks.

    Hi,
    Welcome to the forum!
    Whenever you have a question, please post your sample data in a form that people can use to re-create the problem and test their solutions.
    For example:
    CREATE TABLE     table_x
    (      columna     NUMBER
    ,      columnb     NUMBER
    ,      columnc     NUMBER
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368834, 34323021, 100);
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368835, 34438258, 50);
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368834, 34438258, 50);
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368835, 34323021, 100);Do you want something that works in your version or Oracle? Of course you do! So tell us which version that is.
    How do you get the results that you want? Explain what each row of output represents. It looks like
    the 1st row contains the 1st distinct value from each column (where "first" means descending order for columnc, and ascending order for the others),
    the 2nd row contains the 2nd distinct value,
    the 3rd row contains the 3rd distinct value, and so on.
    If that's what you want, here's one way to get it (in Oracle 9 and up):
    WITH     got_nums     AS
         SELECT     columna, columnb, columnc
         ,     DENSE_RANK () OVER (ORDER BY  columna        )     AS a_num
         ,     DENSE_RANK () OVER (ORDER BY  columnb        )     AS b_num
         ,     DENSE_RANK () OVER (ORDER BY  columnc  DESC)     AS c_num
         FROM     table_x
    SELECT       MAX (a.columna)          AS columna
    ,       MAX (b.columnb)          AS columnb
    ,       MAX (c.columnc)          AS columnc
    FROM              got_nums     a
    FULL OUTER JOIN  got_nums     b     ON     b.b_num     =           a.a_num
    FULL OUTER JOIN  got_nums     c     ON     c.c_num     = COALESCE (a.a_num, b.b_num)
    GROUP BY  COALESCE (a.a_num, b.b_num, c.c_num)
    ORDER BY  COALESCE (a.a_num, b.b_num, c.c_num)
    ;I've been trying to find a good name for this type of query. The best I've heard so far is "Prix Fixe Query", named after the menus where you get a choice of soups (listed in one column), appetizers (in another column), main dishes (in a 3rd column), and so on. The items on the first row don't necessaily have any relationship to each other.
    The solution does not assume that there are the same number of distinct items in each column.
    For example, if you add this row to the sample data:
    INSERT INTO table_x (columna, columnb, columnc) VALUES (13368835, 34323021, 99);which is a copy of the last row, except that there is a completely new value for columnc, then the output is:
    `  COLUMNA    COLUMNB    COLUMNC
      13368834   34323021        100
      13368835   34438258         99
                                  50starting in Oracle 11, you can also do this with an unpivot-pivot query.

  • BO4 - Oracle Analytic Function within agg_aware measure

    Hi,
    We can use an analytic function within idt tool and when in a measures by itself it parses ok.
    However when include in an agg_aware measure it gives an ORA-00937 not a single group group function.
    When create queries with the agg_aware measure behaves ok, generates sql ok and runs ok - please advise.
    Thanks

    Nice, am I coming in here to read the English docs again?

  • Oracle analytic functions

    Hello,
    I must use the integral operator in PL/SQL.
    Does anybody know if Oracle provides a PL/SQL procedure or package to apply directly the integral operator?
    Or is there some package with statistics functions? E.g: Gaussian distribution?
    If not, could you help me with some ideas on how to develop a procedure that calculates the integral of a function?
    Thanks a lot for your help,
    Martha

    Martha:
    Maybe it would be better to export the data to Excel and then apply the functions you want.
    Just a thought.
    There are ohter statistical packages (not Oracle) which you can also use once you expert the data.
    Hope this helps.

  • Analytic function Issue

    Create table Example as
    select 124 Emp_Id, 350 Amt from dual
    Union select 123 Emp_Id, 200 Amt from dual
    Union select 124 Emp_Id, 350 Amt from dual
    Union select 125 Emp_Id, 250 Amt from dual
    Union select 126 Emp_Id, 250 Amt from dual
    Union select 127 Emp_Id, 100 Amt from dual
    I am having the dataet like
    Emp_Id TotalAmt
    123 200
    124 350
    125 250
    126 250
    127 100
    with query
    SELECT EMP_ID,Amt,
    SUM (Amt) OVER ( ORDER BY Amt DESC) AS total
    FROM Example
    WHERE Amt > 0 ;
    query return
    Emp_Id Amt Total
    124 350 350
    *125 250 850*
    *126 250 850*
    123 200 1050
    127 100 1150
    in this second row total amount added with third row.
    Excepted Output is
    Emp_Id Amt Total
    124 350 350
    125 250 600
    126 250 850
    123 200 1050
    127 100 1150

    Hi,
    Add more expressions to the analytic ORDER BY cluase so that there are no ties in the ordering.
    For example:
    SELECT      EMP_ID,Amt,
         SUM (Amt) OVER ( ORDER BY  Amt           DESC
                    ,        emp_id          -- Added
                     ) AS total
    FROM      Example
    WHERE      Amt      > 0 ;"SUM (x) OVER (ORDER BY y)" means you will get the same result for each value of y, and a different result only if y is different.
    If there is nothing else unique about each row, you can use ROWNUM.
    This behavior is a consequence of the default windowing clause "RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW". "RANGE" refers to the value(s) in the ORDER BY clause. SBH (above) gave another solution which explicitly changes the wondowing from RANGE to ROWS, meaning you can get a separate result for each row, regardless of the value(s) of y.
    Edited by: Frank Kulash on Jul 12, 2010 5:40 AM

  • Oracle Max Function Issue

    Hi All
    I have problem in selecting the max value of the field . i have the max value of particular field as 10, When i select using max function it is giving 9 as max value. Can someone help me to find this thing
    Thanks...

    Hi,
    kindly check the data type of column
    SQL> create table demo(c1 number);
    Table created.
    SQL> insert into demo values(10);
    1 row created.
    SQL> insert into demo values(1);
    1 row created.
    SQL> insert into demo values(2);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select max(c1) from demo;
       MAX(C1)
            10
    SQL> create table demo1(c1 varchar2(5));
    Table created.
    SQL> insert into demo1 values('10');
    1 row created.
    SQL> insert into demo1 values('1');
    1 row created.
    SQL> insert into demo1 values('2');
    1 row created.
    SQL> select max(c1) from demo1;
    MAX(C
    2
    SQL> insert into demo1 values('9');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select max(c1) from demo1;
    MAX(C
    9
    SQL> select max(to_number(c1)) from demo1;
    MAX(TO_NUMBER(C1))
                    10- Pavan Kumar N

  • How to use sum analytic function in adf

    Hi
    jdev 11.1.1.5
    oracle 11g r2
    I want to use analytic function (sum,count,avg and ...) .
    I see [url http://andrejusb.blogspot.co.uk/2013/02/oracle-analytic-functions-for-total-and.html]Oracle Analytic Functions for Total and Average Calculation in ADF BC
    and use it in my vo and jsf page,my vo have too much record and I want to have sum in table footer on demand (because of performance) and if user do not want to see the sum in footer of table it do not calculate sum,
    what is your idea?

    Before I read that blog I use another vo for sum but after that blog decide to use analytic fuction becuase we have some page that have to many dvt graph and table and know we use seperate vo for them and it has not good performance and too many query must run in database ,I want to have 1 vo with some analytic function for graph and tables

  • Error using Analytic function in reports

    Hi,
    I am trying to use Oracle analytic function (lag) in a report. But am getting the below error:
    Encountered the symbol "(" when expecting one of the following:
    ,from into bulk
    This is the code in the formula column:
    function extend_lifeFormula return VARCHAR2 is
    l_extend_life VARCHAR2(80);
    l_life_in_months VARCHAR2(80);
    l_asset_id NUMBER;
    begin
    SRW.REFERENCE(:P_BOOK_NAME);
    SRW.REFERENCE(:ASSET_ID);
    SELECT asset_id,
         lag(life_in_months,1,0) over (PARTITION BY asset_id
                   ORDER BY transaction_header_id_in) Extend_Life
    INTO l_asset_id,
    l_life_in_months
    FROM fa_books
    WHERE book_type_code = 'US GAAP'
    AND asset_id = 1;
    return life_in_months;
    end;
    Has anyone experienced this error before? Does client pl/sql engine not support Analytic functions? The above query runs fine in SQL.
    Thanks,
    Ashish

    From our version of 6i Reports Builder Help, I got ...
    Oracle ORACLE PL/SQL V8.0.6.3.0 - Production
    You may check yours.

  • Max  date in analytic function

    I have records that has repeating load dates.
    I would like to pick the records that has the maximum load_dates.
    My source data looks like this -
    ( select 60589 as C_number, to_date('01/08/2012','DD/MM/YYYY') as load_dt from dual union all
    select 60768, to_date('01/08/2012','DD/MM/YYYY') from dual union all
    select 60888, to_date('01/08/2012','DD/MM/YYYY') from dual union all
    select 12345, to_date('01/09/2012','DD/MM/YYYY') from dual union all
    select 54321, to_date('01/09/2012','DD/MM/YYYY') from dual union all
    select 66666, to_date('01/10/2012','DD/MM/YYYY') from dual union all
    select 55555, to_date('01/10/2012','DD/MM/YYYY') from dual)
    I would like to pick records with the max load_dt that means
    C_number load_dt
    666666 01-Oct-12
    555555 01-Oct-12
    I have written an oracle analytic function but it's not working the way it should be -
    My query looks like this -
    select a.*
    from
    select
    c_number,
    load_dt,
    max(load_dt) over (partition by load_dt) as mx_dt
    from table_name
    where
    load_dt = mx_dt;
    It returns all the rows for some reason.
    Any help or guidance is highly appreciated
    PJ

    without analytical..
    with mydata as
    ( select 60589 as C_number, to_date('01/08/2012','DD/MM/YYYY') as load_dt from dual union all
    select 60768, to_date('01/08/2012','DD/MM/YYYY') from dual union all
    select 60888, to_date('01/08/2012','DD/MM/YYYY') from dual union all
    select 12345, to_date('01/09/2012','DD/MM/YYYY') from dual union all
    select 54321, to_date('01/09/2012','DD/MM/YYYY') from dual union all
    select 66666, to_date('01/10/2012','DD/MM/YYYY') from dual union all
    select 55555, to_date('01/10/2012','DD/MM/YYYY') from dual)
    select *
              from mydata
              where load_dt = (select max(load_dt) from mydata);

  • Help - tuning analytic functions

    Where can I find information on hints to speed up oracle analytic functions?
    The table xyz has about 12 million rows.
    The col1 / col2 combinations are effective dated and have an Active /Inactive status.
    Table xyz: col1, col2, effdt, status.
    Goal: I want to eliminate the col1 / col2 combinations where all rows over time have an Inactive status.
    The sq I wrote looks like this:
    select * from
    select col1, col2,
    SUM (1) OVER (PARTITION BY f.col1, f.col2 ORDER BY fcol1, f.col2) total_cnt,
    SUM (CASE WHEN f.status = 'I' THEN 1 ELSE 0 END) OVER
    (PARTITION BY f.col1, f.col2 ORDER BY f.col1) inactive_cnt
    from table xyz f
    where total_cnt > inactive_cnt
    Thanks,
    Frank

    Have a look at these standard threads:
    How to post a tuning request:
    HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long:
    When your query takes too long ...

  • Replacing Oracle's FIRST_VALUE and LAST_VALUE analytical functions.

    Hi,
    I am using OBI 10.1.3.2.1 where, I guess, EVALUATE is not available. I would like to know alternatives, esp. to replace Oracle's FIRST_VALUE and LAST_VALUE analytical functions.
    I want to track some changes. For example, there are four methods of travel - Air, Train, Road and Sea. Would like to know traveler's first method of traveling and the last method of traveling in an year. If both of them match then a certain action is taken. If they do not match, then another action is taken.
    I tried as under.
    1. Get Sequence ID for each travel within an year per traveler as Sequence_Id.
    2. Get the Lowest Sequence ID (which should be 1) for travels within an year per traveler as Sequence_LId.
    3. Get the Highest Sequence ID (which could be 1 or greater than 1) for travels within an year per traveler as Sequence_HId.
    4. If Sequence ID = Lowest Sequence ID then display the method of travel as First Method of Travel.
    5. If Sequence ID = Highest Sequence ID then display the method of travel as Latest Method of Travel.
    6. If First Method of Travel = Latest Method of Travel then display Yes/No as Match.
    The issue is cells could be blank in First Method of Travel and Last Method of Travel unless the traveler traveled only once in an year.
    Using Oracle's FIRST_VALUE and LAST_VALUE analytical functions, I can get a result like
    Traveler | Card Issue Date | Journey Date | Method | First Method of Travel | Last Method of Travel | Match?
    ABC | 01/01/2000 | 04/04/2000 | Road | Road | Air | No
    ABC | 01/01/2000 | 15/12/2000 | Air | Road | Air | No
    XYZ | 01/01/2000 | 04/05/2000 | Train | Train | Train | Yes
    XYZ | 01/01/2000 | 04/11/2000 | Train | Train | Train | Yes
    Using OBI Answers, I am getting something like this.
    Traveler | Card Issue Date | Journey Date | Method | First Method of Travel | Last Method of Travel | Match?
    ABC | 01/01/2000 | 04/04/2000 | Road | Road | <BLANK> | No
    ABC | 01/01/2000 | 15/12/2000 | Air | <BLANK> | Air | No
    XYZ | 01/01/2000 | 04/05/2000 | Train | Train | <BLANK> | No
    XYZ | 01/01/2000 | 04/11/2000 | Train | <BLANK> | Train | No
    Above, for XYZ traveler the Match? clearly shows a wrong result (although somehow it's correct for traveler ABC).
    Would appreciate if someone can guide me how to resolve the issue.
    Many thanks,
    Manoj.
    Edited by: mandix on 27-Nov-2009 08:43
    Edited by: mandix on 27-Nov-2009 08:47

    Hi,
    Just to recap, in OBI 10.1.3.2.1, I am trying to find an alternative way to FIRST_VALUE and LAST_VALUE analytical functions used in Oracle. Somehow, I feel it's achievable. I would like to know answers to the following questions.
    1. Is there any way of referring to a cell value and displaying it in other cells for a reference value?
    For example, can I display the First Method of Travel for traveler 'ABC' and 'XYZ' for all the rows returned in the same column, respectively?
    2. I tried RMIN, RMAX functions in the RDP but it does not accept "BY" clause (for example, RMIN(Transaction_Id BY Traveler) to define Lowest Sequence Id per traveler). Am I doing something wrong here? Why can a formula with "BY" clause be defined in Answers but not the RPD? The idea is to use this in Answers. This is in relation to my first question.
    Could someone please let me know?
    I understand that this thread that I have posted is related to something that can be done outside OBI, but still would like to know.
    If anything is not clear please let me know.
    Thanks,
    Manoj.

  • Function issue in oracle 8i (817)

    Hello,
    Following objects are created in database
    1.     CREATE OR REPLACE TYPE PARAMETER_OBJ AS OBJECT
         RUN                VARCHAR2(2000),
         BATCH_NO                VARCHAR2(2000),
         DAY_NO                VARCHAR2(2000),
         PARAMETER_NAME      VARCHAR2(2000),
         PARAMETER_VALUE      VARCHAR2(2000),
         PARAMETER_UOM           VARCHAR2(2000)
    2.     CREATE OR REPLACE TYPE PARAMETER_TYP AS TABLE OF PARAMETER_OBJ ;
    Info abt the function
    1. function return type is PARAMETER_TYP.
    2. Inside the function i initialize tblParameters PARAMETER_TYP:=PARAMETER_TYP();
    3. Create a temporary table[TMP_PARAMETER] .The structure of the table is same as "PARAMETER_OBJ"
    4. In a loop Insert data into temporary table
    5. At the end issue following select statement
              SELECT CAST (MULTISET (SELECT * FROM TMP_PARAMETER)
    AS PARAMETER_TYP )
    INTO tblParameters FROM DUAL;
    6. issue commit (which flushes temp table)
    7. return RETURN tblParameters
    Finally issue following sql statement to get data from the function
    select * from table(T_Get_ParameterValue('A03052','-1-SPINNER-CELL_AGE-15L,3-SPINNER-DOUBLING_TIME-15L'))
    It works oracle 10g. In oracle 817 function compiles.But if i select as shown above it gives erorr says nested table not found..
    Can any body help me.

    1. CREATE OR REPLACE TYPE PARAMETER_OBJ AS OBJECT
    RUN VARCHAR2(2000),
    BATCH_NO VARCHAR2(2000),
    DAY_NO VARCHAR2(2000),
    PARAMETER_NAME VARCHAR2(2000),
    PARAMETER_VALUE VARCHAR2(2000),
    PARAMETER_UOM VARCHAR2(2000)
    2. CREATE OR REPLACE TYPE PARAMETER_TYP AS TABLE OF PARAMETER_OBJ ;
    # Code
    CREATE OR REPLACE Function T_Get_ParameterValue
    a_run CLOB,
    a_dytblcoleqp CLOB
    -- [T]: TO_REMOVE: Changed return type.
    -- 1. Need to create a temporary table TMP_PARAMETER which has the same structure as your object.
    --RETURN PARAMETER_TYP PIPELINED
    RETURN PARAMETER_TYP
    AS
    PRAGMA AUTONOMOUS_TRANSACTION;
    TYPE cursor_type IS REF CURSOR;
    TYPE STR_LST IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;
    l_sql varchar2(4000);
    l_cr cursor_type;
    -- [T]: TO_REMOVE: Added variable.
    tblParameters PARAMETER_TYP:=PARAMETER_TYP();
    l_batch_lst STR_LST;
    l_tblcl_lst STR_LST;
    l_tbl_lst STR_LST;
    l_col_lst STR_LST;
    l_day_lst STR_LST;
    l_sign_lst STR_LST;
    l_eqp_lst STR_LST;
    l_con CLOB;
    l_tmp varchar2(4000);--Tmp store
    l_pos number:=0; -- LOcator of the seperaotr
    s_pos number:=0; -- start position
    l_k number:=0; -- Array controller
    l_n number:=0; -- Array controller
    f_sp varchar2(1):=','; -- First seperator
    s_sp varchar2(1):='-'; -- Second seperator
    l_col_desc varchar2(2000);
    l_column_type varchar2(2000);
    l_capture_date varchar2(2000);
    -- ipc list
    l_parameter_uom varchar2(2000);
    l_action_limit_max varchar2(2000);
    l_action_limit_min varchar2(2000);
    l_control_limit_max varchar2(2000);
    l_control_limit_min varchar2(2000);
    l_center_line varchar2(2000);
    l_parameter_value varchar2(2000);
    l_batch_id varchar2(2000);
    l_batch_no varchar2(2000);
    l_day_no varchar2(2000);
    l_eqp varchar2(2000);
    l_date date;
    -- Loop Control
    l_cont number;
    i number;
    --remove
    l_sqlerm varchar2(2000);
    BEGIN
    l_pos:=0; -- LOcator of the seperaotr
    -- Parsing
    -- Parsing the tbl and col list
    s_pos:=1;
    l_cont:=1; -- loop control
    i:=0; -- loop control
    while (l_cont=1) loop
    i:=i+1;
    l_k:=l_k+1;
    --determine position
    l_pos:=instr(a_dytblcoleqp,f_sp,1,i);
    if l_pos=0 and i=1 then -- no need to parse ,only 1 record
    l_tmp:=a_dytblcoleqp;
    l_tblcl_lst(l_k):=l_tmp;
    --exit;
    l_cont:=0;
    elsif l_pos=0 and i!=1 then
    l_tmp:=substr(a_dytblcoleqp,s_pos);
    l_tblcl_lst(l_k):=l_tmp;
    l_k:=l_k-1; re caluclate. nothing else to parse
    --exit;
    l_cont:=0;
    else -- continue parse
    l_tmp:=substr(a_dytblcoleqp,s_pos,l_pos-s_pos);
    l_tblcl_lst(l_k):=l_tmp;
    s_pos:=l_pos+1;
    end if;
    end loop; -- end of while loop
    for j in 1..l_k loop
    -- validate sign
    if substr(l_tblcl_lst(j),1,1)='-' then
    l_tblcl_lst(j):=substr(l_tblcl_lst(j),2);
    l_sign_lst(j):='-';
    else
    l_sign_lst(j):='';
    end if;
    l_day_lst(j):=substr(l_tblcl_lst(j),1,instr(l_tblcl_lst(j),s_sp,1,1)-1);
    l_day_lst(j):=l_sign_lst(j)||l_day_lst(j);
    l_tbl_lst(j):=substr(l_tblcl_lst(j),instr(l_tblcl_lst(j),s_sp,1,1)+1,instr(l_tblcl_lst(j),s_sp,1,2)-instr(l_tblcl_lst(j),s_sp,1,1)-1);
    l_col_lst(j):=substr(l_tblcl_lst(j),instr(l_tblcl_lst(j),s_sp,1,2)+1,instr(l_tblcl_lst(j),s_sp,1,3)-instr(l_tblcl_lst(j),s_sp,1,2)-1);
    l_eqp_lst(j):=substr(l_tblcl_lst(j),(instr(l_tblcl_lst(j),s_sp,1,3)+1));
    end loop;
    -- Parsing Batch List
    s_pos:=1;
    l_cont:=1; -- loop control
    i:=0; -- loop control
    while (l_cont=1) loop
    i:=i+1;
    l_n:=l_n+1;
    --determine position
    l_pos:=instr(a_run,f_sp,1,i);
    if l_pos=0 and i=1 then -- no need to parse ,only 1 record
    l_tmp:=a_run;
    l_batch_lst(l_n):=l_tmp;
    l_cont:=0;--exit while loop
    elsif l_pos=0 and i!=1 then
    l_tmp:=substr(a_run,s_pos);
    l_batch_lst(l_n):=l_tmp;
    l_cont:=0;--exit while loop
    else -- continue parse
    l_tmp:=substr(a_run,s_pos,l_pos-s_pos);
    l_batch_lst(l_n):=l_tmp;
    s_pos:=l_pos+1;
    end if;
    end loop;
    --- end of Parsing
    -- Build con catenate list
    for k in 1..l_n loop
    --l_con:=NULL;
    --l_con:='('; 
    --l_con:=l_con||''''||l_batch_lst(k)||''')';
    --dbms_output.put_line(l_con);
    for j in 1..l_k loop
    -- 1 -- Get col desc
    begin
    select COLUMN_DESCR,COLUMN_TYPE,CAPTURE_DATE
    into l_col_desc,l_column_type,l_capture_date
    from MDM_ALL_PARAMETER_LIST
    where table_name=upper(l_tbl_lst(j))
    and column_name=upper(l_col_lst(j));
    exception
    when others then
    l_col_desc:=NULL;
    l_column_type:=NULL;
    l_capture_date:=NULL;
    end;
    --dbms_output.put_line(l_batch_lst(k)||'-'||l_tbl_lst(j)||'-'||l_col_lst(j)||'-'||l_col_desc||'-'||to_char(l_capture_date));
    --Build Sql Statement  
    if l_tbl_lst(j)='THAW' then
    l_sql:=NULL;
    l_sql:='select distinct spinner.BATCH_ID as batch_id,thaw.BIN_NO as bin_no,ipc.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,thaw.'||l_col_lst(j)||','||l_capture_date;
    l_sql:=l_sql||' from SPINNER spinner, BIN_HIER bin_hier, THAW thaw,IPC_LIMITS ipc';
    l_sql:=l_sql||' where spinner.bin_no = bin_hier.bin_no';
    l_sql:=l_sql||' and bin_hier.PROCESS_STEP =30';
    l_sql:=l_sql||' and bin_hier.Revival_no = thaw.Revival_no';
    l_sql:=l_sql||' and spinner.bin_no=ipc.LOT(+)';
    l_sql:=l_sql||' and spinner.BATCH_ID=ipc.BATCH_ID(+)';
    l_sql:=l_sql||' and spinner.BATCH_ID=:1';
    l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
    l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
    l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
    --dbms_output.put_line(l_sql);
    elsif l_tbl_lst(j)='THAW_SAMPLES' then
    if l_col_lst(j)!='CALC' then
    l_sql:=NULL;
    l_sql:='select distinct spinner.BATCH_ID as batch_id,thaw_samples.BIN_NO as bin_no,thaw_samples.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,thaw_samples.'||l_col_lst(j)||',thaw_samples.'||l_capture_date;
    else
    l_sql:=NULL;
    --l_sql:='select spinner.BATCH_ID as batch_id,thaw_samples.BIN_NO  as bin_no,thaw_samples.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,null as Parameter_value,thaw_samples.'||l_capture_date;          
    l_sql:='select distinct spinner.BATCH_ID as batch_id,thaw_samples.BIN_NO as bin_no,thaw_samples.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,Get_IPC_Parameter_Value('''||l_tbl_lst(j)||''''||','||''''||l_col_lst(j)||''',spinner.BATCH_ID,thaw_samples.BIN_NO,thaw_samples.DAY_NO),thaw_samples.'||l_capture_date;
    end if;
    l_sql:=l_sql||' from SPINNER spinner, BIN_HIER bin_hier, THAW thaw,THAW_SAMPLES thaw_samples,IPC_LIMITS ipc';
    l_sql:=l_sql||' where spinner.bin_no = bin_hier.bin_no';
    l_sql:=l_sql||' and bin_hier.PROCESS_STEP =30';
    l_sql:=l_sql||' and bin_hier.Revival_no = thaw.Revival_no';
    l_sql:=l_sql||' and thaw_samples.bin_no=thaw.bin_no';
    l_sql:=l_sql||' and spinner.bin_no=ipc.LOT(+)';
    l_sql:=l_sql||' and spinner.BATCH_ID=ipc.BATCH_ID(+)';
    l_sql:=l_sql||' and spinner.BATCH_ID=:1';
    l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
    l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
    l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
    l_sql:=l_sql||' and ipc.day_no(+)=:5';
    l_sql:=l_sql||' and thaw_samples.day_no=:6';
    elsif l_tbl_lst(j) in ('F1250L_TEST','F200L_TEST','F4000L_TEST','F8000L_TEST') then
    l_sql:=NULL;
    l_sql:='select t.batch_id,t.bin_no,t.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,t.'|| l_col_lst(j)||',t.'||l_capture_date;
    l_sql:=l_sql||' from '||l_tbl_lst(j)||' t,IPC_LIMITS ipc ';
    l_sql:=l_sql||' where 1=1';
    l_sql:=l_sql||' and t.BATCH_ID=ipc.BATCH_ID(+)';
    l_sql:=l_sql||' and t.BIN_NO=ipc.LOT(+)';
    l_sql:=l_sql||' and t.day_no=ipc.day_no(+)';
    l_sql:=l_sql||' and t.batch_id=:1';
    l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
    l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
    l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
    l_sql:=l_sql||' and t.day_no=:5';
    elsif l_tbl_lst(j) in ('SPINNER_SAMPLES') then
    l_sql:=NULL;
    l_sql:='select smp.batch_id,smp.bin_no,smp.DAY_NO as day_no,spn.src_vessel_id as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,smp.'|| l_col_lst(j)||',smp.'||l_capture_date;
    l_sql:=l_sql||' from SPINNER spn , SPINNER_SAMPLES smp,IPC_LIMITS ipc ';
    l_sql:=l_sql||' where 1=1';
    l_sql:=l_sql||' and spn.bin_no=smp.bin_no';
    l_sql:=l_sql||' and smp.BATCH_ID=ipc.BATCH_ID(+)';
    l_sql:=l_sql||' and smp.DAY_NO=ipc.DAY_NO(+)';
    l_sql:=l_sql||' and smp.BIN_NO=ipc.LOT(+)';
    l_sql:=l_sql||' and smp.batch_id=:1';
    l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
    l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
    l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
    l_sql:=l_sql||' and smp.DAY_NO(+)=:5';
    l_sql:=l_sql||' and upper(trim(replace(spn.src_vessel_id,'' '')))=:6';
    elsif l_tbl_lst(j) in ('SPINNER') then
    l_sql:=NULL;
    l_sql:='select t.batch_id,t.bin_no,null as day_no,t.src_vessel_id as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,t.'|| l_col_lst(j)||',t.'||l_capture_date;
    l_sql:=l_sql||' from '||l_tbl_lst(j)||' t,IPC_LIMITS ipc ';
    l_sql:=l_sql||' where 1=1';
    l_sql:=l_sql||' and t.BATCH_ID=ipc.BATCH_ID(+)';
    l_sql:=l_sql||' and t.BIN_NO=ipc.LOT(+)';
    l_sql:=l_sql||' and t.batch_id=:1';
    l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
    l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
    l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
    l_sql:=l_sql||' and upper(trim(replace(t.src_vessel_id,'' '')))=:5';
    else
    -- rest
    l_sql:=NULL;
    l_sql:='select t.batch_id,t.bin_no,ipc.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,t.'|| l_col_lst(j)||',t.'||l_capture_date;
    l_sql:=l_sql||' from '||l_tbl_lst(j)||' t,IPC_LIMITS ipc ';
    l_sql:=l_sql||' where 1=1';
    l_sql:=l_sql||' and t.BATCH_ID=ipc.BATCH_ID(+)';
    l_sql:=l_sql||' and t.BIN_NO=ipc.LOT(+)';
    l_sql:=l_sql||' and t.batch_id=:1';
    l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
    l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
    l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
    end if;
    -- Open the cursor and filled up object
    if l_tbl_lst(j)='THAW_SAMPLES' then
    open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1,l_day_lst(j),l_day_lst(j);
    loop
    null;
    fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
    exit when l_cr%notfound;
    --PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
    -- [T]: TO_REMOVE: Changed code to populate the temporary table.
    INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
    end loop;
    close l_cr;
    elsif l_tbl_lst(j) in ('SPINNER_SAMPLES') then
    open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1,l_day_lst(j),l_eqp_lst(j);
    loop
    null;
    fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
    exit when l_cr%notfound;
    --PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
    -- [T]: TO_REMOVE: Changed code to populate the temporary table.
    INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
    end loop;
    close l_cr;
    null;
    elsif l_tbl_lst(j) in ('SPINNER') then
    open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1,l_eqp_lst(j);
    loop
    null;
    fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
    exit when l_cr%notfound;
    -- PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
    -- [T]: TO_REMOVE: Changed code to populate the temporary table.
    INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
    end loop;
    close l_cr;
    elsif l_tbl_lst(j) in ('F1250L_TEST','F200L_TEST','F4000L_TEST','F8000L_TEST') then
    null;
    open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1,l_day_lst(j);
    loop
    null;
    fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
    exit when l_cr%notfound;
    -- PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
    -- [T]: TO_REMOVE: Changed code to populate the temporary table.
    INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
    end loop;
    close l_cr;
    else
    open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1;
    loop
    null;
    fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
    exit when l_cr%notfound;
    -- PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
    -- [T]: TO_REMOVE: Changed code to populate the temporary table.
    INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
    end loop;
    close l_cr;
    null;
    end if;
    end loop;-- end of for loop for j in 1..l_k loop
    end loop; --end of for j in 1..l_n loop
    -- [T]: TO_REMOVE: Return the data from the temporary table into the table type.
    -- Return data into table type.
    SELECT CAST (MULTISET (SELECT * FROM TMP_PARAMETER)
    AS PARAMETER_TYP )
    INTO tblParameters FROM DUAL;
    -- [T]: TO_REMOVE: Added commit so that the data in the temporary table is deleted.
    COMMIT;
    -- [T]: TO_REMOVE: Return the table type.
    -- return ;
    RETURN tblParameters;
    EXCEPTION
    WHEN OTHERS THEN
    --l_sqlerm:=substr(sqlerrm,1,200);
    ROLLBACK;
    RAISE_APPLICATION_ERROR (-20001, SQLERRM);
    return NULL;
    END;
    # Select sql statement
    select *
    from table(T_Get_ParameterValue('A03052','-1-SPINNER-CELL_AGE-15L,3-SPINNER-DOUBLING_TIME-15L'))

  • Grouping error in Oracle's analytic function  PERCENTILE_CONT()

    Hi,
    I have a question regarding the usage of Oracle's analytic function PERCENTILE_CONT(). The underlying time data in the table is of hourly granularity and I want to fetch average, peak values for the day along with 80th percentile for that day. For the sake of clarification I am only posting relevant portion of the query.
    Any idea how to rewrite the query and achieve the same objective?
    SELECT   TRUNC (sdd.ts) AS ts,
             max(sdd.maxvalue) AS max_value, avg(sdd.avgvalue) AS avg_value,
             PERCENTILE_CONT(0.80) WITHIN GROUP (ORDER BY  sdd.avgvalue ASC) OVER (PARTITION BY pm.sysid,trunc(sdd.ts)) as Percentile_Cont_AVG
    FROM     XYZ
    WHERE
              XYZ
    GROUP BY  TRUNC (sdd.ts)  
    ORDER BY  TRUNC (sdd.ts)
    Oracle Error:
    ERROR at line 5:
    ORA-00979: not a GROUP BY expression

    You probably mixed up the aggregate and analytical versin of PERCENTILE_CONT.
    The below should work, but i dont know if it produces the desireed results.
    SELECT   TRUNC (sdd.ts) AS ts,
             max(sdd.maxvalue) AS max_value, avg(sdd.avgvalue) AS avg_value,
             PERCENTILE_CONT(0.80) WITHIN GROUP (ORDER BY  sdd.avgvalue ASC)  as Percentile_Cont_AVG
    FROM     XYZ
    sorry, what is this where clause for??
    WHERE
              XYZ
    GROUP BY  TRUNC (sdd.ts)  
    ORDER BY  TRUNC (sdd.ts) Edited by: chris227 on 26.03.2013 05:45

  • Analytical Function in Oracle 8.1.5

    I am using the following sql
    select empno,ename,count(*) over()
    from emp;
    But it shows the error
    ORA-00923: FROM keyword not found where expected
    I am using Oracle 8.1.5
    pls help me

    Analytical function were introduced in ORACLE 8iBut only for the Enterprise Edition. If the OP has the Standard Edition they can't use Analytic functions.
    Cheers, APC

Maybe you are looking for

  • Long time required to load variable screen

    Hi Experts, I going to start with the question and after I will explain the details. Is there any way in which I can preload in Cache "program" generated by the query? When I run my queries is taking a long time just to load the variable screen. I th

  • Can I send a gmail with attachment, possibly photo?

    I wanted to send a gmail with aatachment being photo saved to gallery.

  • Image restore affects the wrong image

    Hi, please help me out on this one... I've applied two behaviors to one image, 1st event is that when you hover over "Image A" "image A" should change to "Image A_over" and then restore on MouseOut. 2nd event is that when "Image A" (or "Image A_over"

  • Opening all selected files in Photoshop

    After selecting several photos in Lightroom 2, how do I open them all in Photoshop with one action?  Thanks  jc

  • DW in a wamp environment - database connectivity issues

    I'm new to creating dynamic websites. I'm working with The Missing Manual Tutorial and setting up a wamp localhost testing environment. On the last step in setting up the environment, I'm trying to point DW to the MySql database cosmofarmer and the o