Case function in predicates

Hi,
I've come across strange query like that:
select * from table
where
SYSDATE > uwn_data
AND CASE
WHEN TRUNC (SYSDATE) - TRUNC (uwn_data) > 0
THEN 25
ELSE TO_NUMBER (TO_CHAR (SYSDATE, 'hh24'))
END >= trw_godzina_od
thats something new for me, looks like troubles for CBO, Do You
got similiar experience ?
Regards.
GG

What trouble does CBO has with this? This looks very common to me. There is nothing unusual about it.
Cheers
Sarma.

Similar Messages

  • What is the difference betwee decode & case function

    Hi
    What is the difference betwee decode & case function
    1.decode can't used in pl/sql 1) case can be user
    2.in decode we can't use (>,<,>=) 2) we can use
    any other do u have....
    thanks in advance....

    DECODE works with expressions which are scalar values.
    CASE can work with predicates and subqueries in searchable form.
    There is one more Important difference between CASE and DECODE
    DECODE can be used Only inside SQL statement....
    But CASE can be used any where even as a parameter of a function/procedure
    Eg:-
    SQL> create or replace procedure pro_01(n number) is
      2  begin
      3  dbms_output.put_line(' The number  = '||n);
      4  End;
      5  /
    Procedure created.
    SQL> set serverout on
    SQL> var a varchar2(5);
    SQL> Begin
      2  :a := 'ONE';
      3  End;
      4  /
    PL/SQL procedure successfully completed.
    SQL> Begin
      2   pro_01(Decode(:a,'ONE',1,0));
      3  End;
      4  /
    pro_01(Decode(:a,'ONE',1,0));
    ERROR at line 2:
    ORA-06550: line 2, column 9:
    PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL
    statement only
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignored
    SQL> Begin
      2    pro_01(case :a when 'ONE' then 1 else 0 end);
      3  End;
      4  /
    The number  = 1
    PL/SQL procedure successfully completed.Message was edited by:
    Avi
    Message was edited by:
    Avi

  • Subtotal issue when subtotaling on a calc field built using CASE function

    Okay, I hpe I can explain this well. May be possible that this is something cannot handle in Discoverer. I am using Discoverer Plus to develop a new workbook - cross project expenditure inquiry. A requirement is to not allow a worksheet user to see labor cost (since possible to figure out someone's salary) amount unless they are allowed to view labor cost. I have a function that returns a Y/N value that tells me if they can view labor cost. That works out just fine. So what I am doing is taking my database cost column (which is defined as Number(22,5) in the Oracle table. I create a new calculated column, basically like this -
    CASE WHEN expenditure type <> LABOR THEN cost WHEN view labor cost = 'Y' THEN cost ELSE NULL END.
    That calculated column is working just fine. I am seeing my desired results in that column. Okay so far.
    Next, the users want subtotals by project organization and project. So I created a new total. When I did that, my subtotal row amount is blank.
    Okay, I have seen this happen with NULLS before. Like in the gl_je_lines tables, where the accounted_Dr and accounted_Cr may be null, and have to do a NVL function to convert the null to 0 and allow me to subtotal on the column in a Discoverer workbook.
    So I tried creating a second calculation -
    NVL(Cost,0)
    So I return the cost if not null, otherwise I return 0. Second calc column results look okay.
    Now I did a subtotal on the second calculation. Oops. Wrong result. Amount is shown as 0.
    For grins, I went back to my CASE statement on my first calculation and changed the ELSE condtion from NULL to 0. When I did that, the subtotal on that column changes from a blank (Null) value to a 0 value. Well, better, but still just like my second calculation subtotal.
    Obviously the users have the option to export to Excel and subtotal in Excel.
    Does anyone know of a way to get a good subtotal in this kind of situation, where I am attempting to subtotal on a calculated field that is built on a CASE function? Or am I out of luck when it comes to Discoverer?
    John Dickey

    Okay, I did find a workaround, though I do not understand why the workaround works, but why the way I first tried to get a subtotal did not work. What I did is that I had to go to Discoverer Administrator. I picked my folder and did an Insert/Item. I created my new item building the same CASE statement that I used in my worksheet to create a new calculation. I then closed Discoverer Plus and reopened Discoverer Plus. Opened my worksheet. Edited the worksheet and brought in my new (derived) item from my folder. Then I created my subtotals for this secured cost amount. Voila. I get a number now, and the subtotal amount appears to be correct (still testing/verifying, but looks okay so far). So I deleted my subtotals on my calculated column and then deleted the calculation, to get that stuff out of the report. Sure would be nice if there was documentation in the Discoverer manuals about this.
    John Dickey

  • How to use, Case function and Filter in Column Formula?

    Hello All,
    I am using case function and also would like to filter value to populate.
    Below is showing error :
    case
    when '@{Time}' = 'Year' then "Time"."Fiscal Year"
    when '@{Time}' = 'Quarter' then "Time"."Fiscal Quarter"
    when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')
    else ifnull('@{Time}','Selection Failed') end
    Thanks, AK

    when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')I dont think Filter this works here or any other data types except number.
    Try to use option Column's->Filter->Advanced->Convert this filter to SQL
    If helps mark

  • XSLT upper-case function()

    Does anybody know how to use a upper-case() function in XSLT? I have it in a XSL mapping of a routing service. I want it as below:
    <xsl:when test='(upper-case(/imp1:GENERIC4) = "YES") or (/imp1:AWARDTYPE = "227")'>
    <top:ccFlag>
    <xsl:text disable-output-escaping="no">Y</xsl:text>
    </top:ccFlag>
    I want it to be true no matter what case of YES is. It can be yes/Yes/YES/or anything.
    I also tried the following,
    <xsl:variable name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
    <xsl:variable name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
    <xsl:choose>
    <xsl:when test='(translate(/imp1:GENERIC4,$lower,$upper) = "YES") or (/imp1:AWARDTYPE = "227")'>
    <top:ccFlag>
    <xsl:text disable-output-escaping="no">Y</xsl:text>
    </top:ccFlag>
    </xsl:when>
    <xsl:otherwise>
    <top:ccFlag>
    <xsl:text disable-output-escaping="no">N</xsl:text>
    </top:ccFlag>
    </xsl:otherwise>
    </xsl:choose>
    But doesnt work.
    Thanks for helping.

    this code works for me
        <ns1:testBPELProcessRequest>
          <ns1:input>
            <xsl:value-of select="xp20:upper-case(/ns1:testBPELProcessRequest/ns1:input)"/>
          </ns1:input>
        </ns1:testBPELProcessRequest>
      </xsl:template>maybe you need to use the namespace in front of the upper-case

  • CASE function problem in forms

    I am using the CASE function in View. Whenever i execute it using SQL plus it runs successfully. I have developed a form on this view and the form does not reflect the CASE function changes. Just an example i am using the CASE function to set the number format but it is not depicting on form.
    SELECT (CASE when TO_NUMBER(123123.12/1000000) < 1 THEN TO_CHAR(TO_NUMBER(123123.12/1000000),'0.99999')
    ELSE LTRIM(TO_CHAR(TO_NUMBER(123123.12/1000000),'999,999.999999')) END) as targetamount
    FROM DUAL

    This is not that diffucult.....I rememeber doing this in one of my forms....
    I would have three content areas
    ContentArea A (Portrait) linked to Subform A
    ContentArea B (Landscape) linked to Subform B
    ContentArea C (Portrait) linked to Subform C
    Now I will set the Min, Max and Initial values for each of those Subform using Binding tab.
    Then I will manage the page layout selection with each of those subforms using Object>>Pagination>>Place and link those to the Content area A B or C based on the layout they should go on. That should do the trick.
    If this is not helpful just forward me a copy at n_varma(AT)lycos.com....I will try my best.
    Good Luck,

  • CASE function is not working

    Hi,
    I want to use the CASE function in a sql statement used at form level but it's not working. I can't compile the form. I am using developer 6i at font end and Oracle 10g database at back end. Is it possible to use case function at form level sql statement. If so then please help me about it.
    Best Regards

    Forms has it's own PL/SQL engine, and in Forms 6i it's version 8 where no CASE was available. So if you want to use CASE you'll have to use a view or put your logic in a stored procedure.

  • Concatenation in CASE function

    Hi Gurus,
    In 9.0.4, the concatenation is not working in case statement. The append works fine in WHEN condition in CASE function and the result is the concatenated result. If I put the same condition without concatenation in ELSE statement, it gives datatype inconsistency error. Is there a way to do it?
    Thanks,
    Pooja

    Hi Pooja,
    Use the "To_Char()" function in ur concate function ,
    Because concat function only accept the string not an integer.
    Manikandan
    GKB Consulting Inc.,

  • Grand total of calculated column and case function in the same calcultd col

    Hi Gurus,
    In 9.0.4, the Grand total of the calculated column is not working as per the CASE function. It is taking the ELSE formula for all records. Is there a way to correct it.
    Thanks,
    Pooja

    Hi Pooja,
    In the totals ,which u mentioned try using cell sum function instead of sum function.
    Manikandan
    GKB Consulting Inc.,

  • CASE function in determining turn around time

    I am working with a customer that submits work for processing that must be accomplished on very short turnaround. There is a submission date in one table and in a joined table there is an accomplishment date. I can use the CASE calculation with a simple "like" condition to compare submission dates with accomplishment dates to answer "yes" or "no" if they match or do not match. How can I report a turnaround time of 2 days or 3 days, where the accomplishment date is 2 or 3 days after the submission date. Can I use a variation of the CASE calculation to derive a "yes" or "no" answer to these variations?

    I am working with a customer that submits work for
    processing that must be accomplished on very short
    turnaround. There is a submission date in one table
    and in a joined table there is an accomplishment
    date. I can use the CASE calculation with a simple
    "like" condition to compare submission dates with
    accomplishment dates to answer "yes" or "no" if they
    match or do not match. How can I report a turnaround
    time of 2 days or 3 days, where the accomplishment
    date is 2 or 3 days after the submission date. Can I
    use a variation of the CASE calculation to derive a
    "yes" or "no" answer to these variations?I think that I was able to find an answer to my question in an earlier forum response to someone who wanted to know how to determine difference in workdays. I really wanted the simplicity of the "yes" or "no" answer allowed by the CASE function. The forum response date I found was Nov 15, 2006

  • Syntax for CASE Function when multiple values equates to the same result?

    Tried using the 'IN' keyword with the CASE function but it does not work, does each case have to be stated separately? trying to save some lines..
    tried:
    case me607.rmc_code
    when in ('M','MS','MP') then 'H311'
    end as carrier_code
    Do i have to do:
    case me607.rmc_code
    when 'M' then 'H311'
    when 'MS' then 'H311'
    when 'MP' then 'H311'
    end as carrier_code,
    etc..
    Thanks for any help..

    One other thing forgot to ask, how do you do a second case selection as:
    case when me607.rmc_code
    in ('M','MP','MS') then 'H311'
    case when me607.rmc_code
    in ('1','2') then 'H252'
    end as carrier code
    wanting to keep the results in carrier_code..
    Thanks..
    Edited by: user12296489 on Dec 10, 2009 3:53 PM

  • Case function with group by

    Hi,
      I am having a scenario like :
    Column 1:  BrokerList(dimension1)
    Column 2 : Broker(dimension2)
    Column 3 : Metric value(measure)
    so i am having a case when (dimension 3) Custodian = 'ss' then sum(metirc) group by dimension1,dimension2 but the result value is not matching
    BrokerList
    Broker
    Metric
    a1
    a
    10
    b
    20
    c
    30
    a1 :total
    60
    a2
    a
    50
    c
    60
    d
    10
    a2:total
    120
    Grand total
    180
    Here the metric is based on other case condition.. so the total value is not matching.. Is there any other way to do a case function with group by funtions. Please advise.
    regards,
    Guru

    Use filter on metric by ss value and then go for group by from Criteria
    something like
    sum(FILTER(metric USING (Custodian = 'ss')) by dimension1,dimension2)
    mark if helps
    ~ http://cool-bi.com

  • Case function

    hi
    can i write case function below like this
    select case (when information_type='SQ_IQAMA' then pei_information) end
    from per_people_extra_info
    information_type has two types like
    information_type pei_information1
    sq_iqama 2073636454
    sa_passport A 559873
    now i want show this in report with diff. columns
    can anyone help me.
    thnks

    user615979 wrote:
    hi
    can i write case function below like this
    select case (when information_type='SQ_IQAMA' then pei_information) end
    from per_people_extra_info
    information_type has two types like
    information_type pei_information1
    sq_iqama 2073636454
    sa_passport A 559873
    now i want show this in report with diff. columns
    can anyone help me.
    thnksYou can use DECODE. Which looks much simpler for this.
    select max(decode(informatino_type, 'sq_iqama',  pei_information1)) sq_iqama,
            max(decode(information_type, 'sa_passport', pei_information1)) sa_passport
      from <table_name>

  • Case function for time period

    I want to count the rows based on the date values and time periods of a date column. e.g.
    08/01/01 00:00 - 01:30 (row count)
    08/01/01 01:30 - 02:00 (row count) etc.
    I'm using the case function to create the time periods from the date column but I'm getting a syntax error, 'missing keyword' at between. How can I code the case statement to create the time periods. The following is the sql code I'm using.
    select TO_CHAR(START_TIME, 'yyyy-mm-dd') as process_date,
         case START_TIME
                   when TO_CHAR(START_TIME, 'hh24:mm') between '00:00' and '01:30' then '12:00 - 1:30 AM'
                   else 'unknown'
         end as process_time,
         count(*)
    from V8_Event_Vw event
    group by TO_CHAR(START_TIME, 'yyyy-mm-dd'), START_TIME
    Thanks,
    Tom

    select TO_CHAR(START_TIME, 'yyyy-mm-dd') as process_date,
    case when TO_CHAR(START_TIME, 'hh24:mm') between '00:00' and '01:30' then '12:00 - 1:30 AM'
    else 'unknown'
    end as process_time,
    count(*)
    from V8_Event_Vw event
    group by TO_CHAR(START_TIME, 'yyyy-mm-dd'),
    case when TO_CHAR(START_TIME, 'hh24:mm') between '00:00' and '01:30' then '12:00 - 1:30 AM'
    else 'unknown'
    end
    *untested (as if I really needed to say that)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is CASE function allowed in forms 6i???

    Hi,
    Is CASE function allowed in forms 6i???
    Thanks
    ESL

    Hi!
    The case statement come first with Oracle Database 9i.
    In Forms 6i it will not work.
    Regards

Maybe you are looking for

  • Creating SNP planned order using ''BAPI_MOSRVAPS_SAVEMULTI3'

    Hi Experts,                   I am new to SAP-APO, kindly clarify my question. I am using 'BAPI_MOSRVAPS_SAVEMULTI3' with source of supply PDS for creating SNP planned order by passing 'EE' in the  table parameters 'ORDER_HEAD-MASTER_ATPCAT'. It is c

  • [SOLVED]cannot connect to wireless network due to a channel setting

    Hello guys, I recently came across a problem with my wireless network. It was first a system-wide upgrade(adapted from the pacman's log): [2010-08-22 15:10] Running 'pacman -Syu' [2010-08-22 15:10] synchronizing package lists [2010-08-22 15:10] start

  • Can't upgrade/change/install versions of Flash Player? To ZoneAlarm users here's a fix.

    For the past couple of weeks now I've been plagued with the problem of not being able to properly upgrade my flash player to version 9. I'd get pass the installation, sure, but they'd be corrupted installations. I can't view some flash websites and t

  • Can ADE be used with Windows 8.1?

    My old computer with ADE crashed.  Do I need to reinstall on my new PC which has Windows 8.1?  Can you give me instructions as to how to do that?  I'm a senior lady and not very technically savvy, so the more detailed your instructions, the easier it

  • Local class and switch statement -- compiler bug?

    Does anybody know why the following does not compile with "LocalClass cannot be resolved to a type" error in the case 1: block public class ProblemClass {      public void localClassProblem() {                class LocalClass {                     vo