Oracle Procedure- Get aggrigate value based on comparing two columns

Hi All,
I have written a Procedure which accepts one input parameter and returns one refcursor.
The logic used in the procedure is:
The procedure is used to display summary as well as detail report. When the input parameter have more than one comma saperated values then it will act as a summary report and when there will be just one value as the input then it will act as a detail report.
The input parameter is like 'AA12345,BB45434,HJ89736' the first two character is Brand_id and the rest of the 5 character is the propery_id.
The aggrigation aggrigation query is :
Select Month_name,Year,sum(REVPAR),Sum(ADR) from FIS_KPI_TREND where
Brand_id='AA' and SIte_id='12345' group by Month_name,Year;
The above query will worke fine for the Detail report when there will be just one value for the input as 'AA12345'.
The problem is comming for the Summary report when I need to get the aggrigated value for all the brand and site which came in the input parameter.
So i changed the query as:
Select Month_name,Year,sum(REVPAR),Sum(ADR) from FIS_KPI_TREND where
Brand_id||SIte_id in ('AA12345','BB45434','HJ89736')  group by Month_name,Year;
(I'm using parser function to parse comma saperated values.)
By doing this i'm getting the desired result but the performance has decrised as the Index is based on Brand_id and Site_id but i'm Using Brand_ID||Site_id for my search.
Can any one suggest any other way to rewrite this query so that it can take the index as well as give me the sesired output.
Database used : Oracle 10g
Thanks in advance.
Sumit Narayan
Edited by: Sumit Narayan on Apr 11, 2010 10:00 PM

I'd be inclined to do something like this to parse the comma separated list, which would allow you to join without concatenating columns like you're doing now.
ME_XE?select
  substr(column_value, 1, 2)            as brand_id,
  substr(column_value, 3, length(column_value))   as site_id
from table(sys.ODCIVARCHAR2LIST('AA12345','BB45434','HJ89736'));
  2    3    4 
BRAND_ID   SITE_ID
AA         12345
BB         45434
HJ         89736
3 rows selected.
Elapsed: 00:00:00.20
ME_XE?
ME_XE?select * from v$version;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE  10.2.0.1.0  Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
5 rows selected.
Elapsed: 00:00:00.39
ME_XE?So for your case ...
Select
  f.Month_name,
  f.Year,
  sum(f.REVPAR),
  Sum(f.ADR)
from FIS_KPI_TREND f, table(sys.ODCIVARCHAR2LIST('AA12345','BB45434','HJ89736')) t
where f.Brand_id = t.brand_id
and   f.SIte_id  = t.site_id
group by f.Month_name, f.Year;Edited by: Tubby on Apr 11, 2010 10:12 PM

Similar Messages

  • Tableview - column color disaply based on comparing other column on the tab

    Hi,
    Can any one give me some idea about how to compare two columns of table on IF_HTMLB_TABLEVIEW_ITERATORRENDER_CELL_START ?. I have to compare the column 3 with column 4 and display the color on column 3. I am trying to do that on IF_HTMLB_TABLEVIEW_ITERATORRENDER_CELL_START but this is not working out. Any suggestion ?.

    Hi,
    in IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START you only have the actual row in P_ROW_DATA_REF.
    Either you make the the availabe as iterator's attribute when instantiating or you collect the row P_ROW_DATA_REF when in RENDER_CELL_START to a class attribute.
    Regards,
    Sebastian

  • Learning to use lookup transformation - match value in one of two columns

    Im a little new to using lookup transforms.  Been reading a bit, but using two columns is throwing me off.
    Have a dataflow with the source having a column I want to use to lookup in a table in another DB.  The match could be in one of two columns in that table.  
    If a match is found, I need a different value from the lookup table added to the source flow that is going into the destination.
    How can I match on one of two columns in the lookup table, and use a totally different column added to the final input going into the destination ?  
    In the Lookup configuration, I can set the lookup operation to replacing the value in the source, but I want EITHER value match from the two columns from the lookup table to go into the value that will go into the destination.
    With TSQL - I would use a case statement and compare the source column to BOTH of the lookup table columns.

    You can handle this within single lookup using below query
    SELECT CASE WHEN <condn1> THEN Field1 ELSE Field2 END AS lookupField,
    CASE WHEN <condn1> THEN Field3 ELSE Field4 END AS MatchField
    FROM Table2
    Then just do single relationship with LookupField and select MatchField to be aded to output
    the condition will specify your fields value condition based on which you determine which column to be matched against
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Create ViewCriteria comparing two columns from same table

    Does anyone know how I can create a ViewCriteria where clause that compares two columns from the same table?
    For example if I had two integer columns (MINSAL and MAXSAL) and wanted to see if they are equal. I would normally do the following SQL below.
    SELECT * FROM EMPL
    WHERE MINSAL = MAXSAL

    It works, but it is not ideal.
    Setup a Transient column that performs a groovy evaluation of MINSAL=MAXSAL and then my ViewCriteria evaluates the column to true and I set Query Execution Mode to Both.

  • On making call to Oracle procedures from Java, Value becomes null on oracle

    We are using some user defined Oracle data types in my Java/J2EE application
    and some of them are Oracle collections(ex. VARRAY).
    We are making a call to Procedures/Functions from Java, there are some
    parameters of user defined data types declared in the
    procedures/functions, from java the values are properly setting to these
    user defined data type parameters and sending to Procedures.
    We are not getting any exception at Java side and Oracle side and values
    are becoming blank/null at oracle procedure side for the parameters of
    user defined data types.
    But when do the count of collection of user defined data type then it is
    properly giving the size of collection(VARRAY).
    When we are trying to read the values from the collection(VARRAY) it is
    giving blank/null value and there is no exception.
    Please let me know if you have any suggestion on this?

    user7671994 wrote:
    When we are trying to read the values from the collection(VARRAY) it is
    giving blank/null value and there is no exception.If you are talking about VARCHAR2 parameters of the objects - then you should add orai18n.jar to classpath.

  • How to get ATINN value based on material number and Class Type ?

    I have below SELECT stmt code which gives the correct value of atwrt based on materil no and ATINN.
    However in quality system, it is failing because in quality system "atinn" value is not 0000000381. It is different.
    So how can I get ATINN(Internal characteristic) value based on material number and Class Type?
    -Obtain the batch characterstic value for the Material******************
      SELECT atwrt
        UP TO 1 ROWS
        INTO v_charvalue
        FROM ausp
       WHERE objek = mcha-matnr
         AND atinn = '0000000381'   " 'US80_FRENCH_ON_LABEL'
         AND klart = '001'.
    THANKS N ADVANCE.

    Hi SAm,
    use the Below function module to get the Atinn for Atwrt for thr Class and MAterial combination..
    CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
          EXPORTING
            classtype          = '023'       "Class type
            object             = w_object  "Material number with Leading zeros
            no_value_descript  = 'X'      "Default X
            objecttable        = 'MCH1'    "Table name Mara or MCH1 or MARC
          TABLES
            t_class            = t_class   "It return the Batch class available for the above combination
            t_objectdata       = t_char  "Return Batch characteristics(ATWRT) and their value ATINN in this table
          EXCEPTIONS
            no_classification  = 1
            no_classtypes      = 2
            invalid_class_type = 3
            OTHERS             = 4.
    Regards,
    Prabhudas

  • Comparing two column values with multiple Parameter in VC (Indicator)

    Hello VC experts,
    GM
    I would like to know about how to indicate multiple parameter with different colour in same column and also comparing value with adjucent column.
    Eg.
    Parameters     ,,           Column1      ,,              Column 2       ,,            Indicator (Image)
    Parameter 1    ,,             a1             ,,                     b1          ,,                  RED
    Parameter 2    ,,            a2              ,,                     b2          ,,                  GREEN
    Parameter 3    ,,            a3              ,,                     b3          ,,                 
    Parameter 4    ,,            a4              ,,                     b4          ,,
    In case I  : Parameter -1     Column 1 ( value)  =  more is better compared to Column 2
    In case II : Parameter -2     Column 1 ( value)  =  Less is better compared to Column 2
    How to acheive this  INDICATOR based value comparison.
    Edited by: Sunil  B. Mundhe on Mar 7, 2009 6:30 AM
    Edited by: Sunil  B. Mundhe on Mar 7, 2009 6:38 AM

    Hi
    This is possible in VC. You have to insert 'Image' UI in the required table. Add images of alert through 'Image manager' (Tools tab). Select relevant images of alert in 'Image' UI. In display there is option for 'visibility condition' there you enter condition (like if greater than ,true,false).
    Like wise you can add multiple 'Image' UIs in that table & based on visibility conditions you will get these alert images in table.
    Regards
    Sandeep

  • Compare two columns and match ALL recurring values, not just the first instance

    Hi everybody...
    I was looking for a way to compare values in two columns, identifying every duplicate value instance on a third column.
    Searching around the forums, I found a solution, albeit a partial one; I am using this formula: =IFERROR("Duplicate in row "&MATCH($A,$B,0),"") along column C, to compare values between columns A and B. When applied, the formula will render the first instance where there is a duplicate; unfortunately MATCH will only register the first instance of the duplicated values.
    For example:
    The first value on column A is 'Apple'. On column B there are three instances for the value 'Apple', the formula identifies the first of these values, but not the remaining two.
    I am not an advanced Numbers or Excel user, and the answer to this problem eludes me. I am attempting to compare columns that have no less than 1000 rows each, so you can imagine how, finding a solution to my problem would be really great.
    Thanks in advance,
    Pablo

    Unfortunately I can't see your screenshot, but supposing you have a table like this:
    Col1
    Col2
    1
    3
    Dupe
    2
    4
    Dupe
    3
    5
    Dupe
    4
    6
    5
    7
    Then here is one way to flag the duplicates.
    The formula in C2, copied down, is:
    =IF(COUNTIF($A,$B2)≥1,"Dupe","")
    Then filter on column C for 'Dupe', and copy the values in column B to wherever you need them.
    SG

  • I want to compare two columns and replace any equal values with the value in a specific cell

    I want to compare the numbers in two columns and replace all matching numbers in the second columns with the corresponding value from a cell in the same row as the matching number. 

    Me too.
    Barry

  • How/where to get the values stored in these two structure fields?

    hi
       need your help to find out where the following two fields get stored in tables...or is there any fm or bapi to get the data stored in these two fields?
    1) Create Scheduling agreement:
    Tcode: ME31L
    Field label - Agreement type
    Field name - EVART
    Structure - RM06E
    2) Purchase order display:
    Tcode: ME23
    Provide any Purchase order craeted already (where release strategy is implemented)
    Select the line item & click release strategy icon at the top.
    You will find a new pop-up menu. In that place the cursor on the startegy code like
    Final release or XX or etc.
    Field name - ANZEF
    Structure - RM06B
    Sathish. R

    Hello Sathish:
    1) EKKO-BSART
    Regards,
    John.

  • Merging values of CKFs in two columns into single column

    Hi ,
    I want to merge values present in two different columns.The values present in rows of one column are not present in rows of other column, I have to merge the values into a single column.so that in the single column i can get all the values.how to do it in BEx.
    regards ,
    man.

    Hi,
    Dear murali , the solution you gave has helped me a bit as i am able to get the values for both the formula KF's in the same column,But another problem has arisen.
       For both the formula KF's I had to choose 'New Selection' (and not 'New formula')after R-cllick on the structure, as I had to use a Characteristic as restriction for Each of the KF's, and also to use the Characteristic I had to associate it with some KF so that the Characteristic wil be used as a KF in the formula.
       Now what is happening is that I am getting the values of that associated KF also in the empty rows.(i.e. the rows where the value of both the KF1 and KF2 is not present)
       What has to be done to remove them and keep the empty rows empty and not show the value of the KF taken with the Characteristic for restriction. Also its value is summing up with KF1 and KF2 in the coulmn which is having both KF1 and KF2 together.
    Regards
    man

  • Compare two columns character by character

    Hi
    In a form I have block A. Which contains two columns Old Value and New Value both are of varchar datatype. I want to compare Old Value and New Value character by character and display the characters which are there in New Value but not in Old Value in a different colour when this block is being called.
    Example1 :Old Value : 13-Jul-2007
    And New Value : 19-Jul-2007
    I need the output to be display in this way - 19(in different clour)-Jul-2007. Only 9 should be in different colour.
    Example2 :Old Value : - (No value Previously)
    And New Value : SI DONE
    So output to be display in this way New Value "SI DONE" should be in different colour.
    Just to hightlight the users that this is change made instead of they manually compare field by field for the changes to take note..
    Pls help me this is bit urgent. Help me to suggest any java related coding can help me or any plugins that we can call thru forms to do it.. Pls help.
    Rishi

    You take a variable i (integer type) and initialize it to 1.
    Take a loop where u'll find one by one character in loop as follows.
    DECLARE
    i NUMBER(10) := 1;
    old_str VARCHAR2(240); -- For Old String
    new_str VARCHAR2(240); -- For New String
    differed_str VARCHAR2(240) := '';
    BEGIN
    WHILE i <= GREATEST(LENGTH(old_str),LENGTH(new_str))
    LOOP
    IF SUBSTR(old_str,i,1) <> SUBSTR(new_str,i,1) THEN
    differed_str := differed_str||SUBSTR(new_str,i,1);
    END IF;
    i := i + 1;
    END LOOP;
    END;
    So, now ur extra characters in New Field will be :differed_str.
    May be u can give a msg with that string.
    Thanx,
    Cheers,

  • How do I compare two columns of data in Numbers to find the unique results?

    Hello all,
    I'm looking for a way to compare the data from two columns so I can find the unique results and display that data in a third column. To be specific, here's what I'm doing.
    Column A is a list of email addresses for people I have already written. Column B is a list of email addresses for people I would like to contact. I am not sure if there are email address from Column A in Column B, but there may be and if there are, I must find out so that I don't send a second email to these recipients. How can I have Numbers look at both columns and tell me which email addresses in Column B are not in Column A?
    Thanks for the help!!!

    gfmp123,
    Here's an alternate use of MATCH to find duplicates. I hope you find one of the two solutions, Wayne's or this one, useful for your case.
    The expression in Column C is:
    =IFERROR("Dup in Row "&MATCH(B, A,0), "")
    Regards,
    Jerry

  • Compare two columns

    hello,
    i want to compare the two columns A and B which contain numbers and then select a table with "A is smaller", "B is smaller" or "A and B are equal".
    for example if i have this table:
    A______________B
    1______________5
    3______________2
    4______________7
    9______________-1
    2______________2
    the result should look like this:
    RESULT
    A is smaller
    B is smaller
    A is smaller
    B is smaller
    A and B are equal
    how should my query look like?
    thanks in advance!

    SQL> select * from t;
                       A                    B
                       1                    5
                       3                    2
                       4                    7
                       9                   -1
                       2                    2
                       0
                                           42
    8 rows selected.
    SQL> select a
      2        ,b
      3        ,case
      4             when a > b then 'B is smaller'
      5             when a < b then 'A is smaller'
      6             when a = b then 'A and B are equal'
      7             else 'can''t compare nulls'
      8         end result
      9  from t;
                       A                    B RESULT
                       1                    5 A is smaller
                       3                    2 B is smaller
                       4                    7 A is smaller
                       9                   -1 B is smaller
                       2                    2 A and B are equal
                       0                      can't compare nulls
                                           42 can't compare nulls
                                              can't compare nulls
    8 rows selected.

  • Tabular Form Validation: Comparing Two Columns vs Check Constraint

    What is the best approach for validating that one column needs to be greater than another column in a tabular form when attempting to save. (E.g. An effective date and expirey date column. The expirey date column >= effective date column)
    At the moment I have a check constraint on the two columns at the database level which is fine but it returns and passes up a pretty cryptic (from a business user perspective) unfriendly message to the user as follows:
    Error in mru internal routine: ORA-20001: Error in MRU: row= 1, ORA-02290: check constraint (IDMTC.ADDRESS_TYPE_CON) violated, update "IDMTC"."ADDRESS_TYPE" set "ID" = :b1, "CODE" = :b2, "NAME" = :b3, "LOV_SORT_ORDER" = :b4, "DESCRIPTION" = :b5, "EFFECTIVE_DATE" = :b6, "EXPIRY_DATE" = :b7 where "ID" = :p_pk_col
    Unable to process update.
    Is there a way to inject, detect and/or replace this with a friendlier business user message? I have confirmed that the "Unable to process update." text at the bottom below the MRU Internal routine error raised from my check constraint is the process error message for my Apply MRU process.
    I was hesitating going down a larger page level validation where I loop through the tabular form array and/or inject some client side Javascript.
    Any advice? Have I simply overlooked some tabular form options for validating using cross column values?
    Thanks,
    Jeff

    Jeff..Thanks for the response.
    However because I am working in a tabular form at design time I don't know which controls I can reference in a dynamic action, or custom Javascript routine other than selecting all elements in a column using JQuery, etc.
    I have decided to go with for the time being an approach I found here: doing validation on tabular form
    My code ended up looking something like and was entered into a page level validation as a PL/SQL function body returning error text.:
    DECLARE
    l_error VARCHAR2 (4000);
    BEGIN
    FOR i IN 1 .. apex_application.g_f02.COUNT
    LOOP
    --If Expiry date is older then effective date
    IF nvl(apex_application.g_f08 (i), to_date('31-DEC-9999', 'dd-mon-yyyy')) < apex_application.g_f07 (i) THEN
    l_error :=
    l_error
    || '</br>'
    || 'Row '
    || i
    || ': Expiry date must be greater than effective date '
    || ' for maintenance item name: '
    || apex_application.g_f03 (i);
    END IF;
    END LOOP;
    RETURN LTRIM (l_error, '</br>');
    END;
    I had been hoping with Apex 4+ that there was additional native functionality to do this type of validation or somehow be able to reference a column or control name instead of a generic array column so that my code was better self documenting.
    It works for now...but would love to revisit with maybe a cleaner client side solution that does the validation and highlights the invalid element since I still maintain data integrity at the db with the check constraint.
    Thanks,
    Jeff

Maybe you are looking for