Using DECODE, CASE

Hi All,
The Transformation Guide of OWB mentions that DECODE, CASE can be used. But I am unable to find either of these functions in the Expression Builder. Can you please tell me wher should I search for these functions, or if you could tell me if there is any other way of implementing IF THEN ELSE logic.
-Arnab

Hello Arnab,
Just type your CASE ... END expression directly in the expr. builder window.
Always press the Validate button for syntax verification when you have changed your expression.
Regards, Hans Henrik

Similar Messages

  • Problem using Decode/Case

    I have one table which stores candidates' response. The structure is like this
    (Seatno, Questionnumber, Answer).
    And I have another table Master as (Questionnumber, Answer)
    Now I want to calculate marks by comparing Candidate's response with Master.
    I tried to use decode and case. But was not successful.
    My query with decode was ...
    select c1.candidatesrno, sum(decode(c1.answer,(c1.answer=m1.answer),1,0))
    from candidate c1,master q1
    where c1.question=m1.question
    group by c1.candidatesrno
    And query with CASE was...
    select c1.candidatesrno,
    case when (c1.answer=m1.answer) then 1 else 0
    end resultset
    from candidate c1,master m1
    where c1.questionnumber=m1.questionnumber
    group by c1.candidatesrno
    Can anybody help ?

    I want to compare candidate's response with master
    table.
    Now for each question of Candidate, if its answer
    matches with answer in Master table I have to give 1
    marks...if it does not match I have to give 0
    marks...like this there are two-three conditions...
    Something like this ?
    test@ORA10G>
    test@ORA10G> with master as (
      2    select 'Q1' as question_num, 'A1' as answer_num from dual union all
      3    select 'Q2', 'A2' from dual union all
      4    select 'Q3', 'A3' from dual),
      5  candidate_response as (
      6    select 'S1' as seat_num, 'Q1' as question_num, 'A1' as answer_num from dual union all
      7    select 'S1', 'Q2', 'A2' from dual union all
      8    select 'S1', 'Q3', 'A3' from dual union all
      9    select 'S2', 'Q1', 'A5' from dual union all
    10    select 'S2', 'Q2', 'A6' from dual union all
    11    select 'S2', 'Q3', 'A3' from dual)
    12  --
    13  select
    14    cr.seat_num,
    15    cr.question_num,
    16    cr.answer_num,
    17    case when m.question_num is null and m.answer_num is null then '0 point'
    18         else '1 point'
    19    end as points
    20  from candidate_response cr, master m
    21  where cr.question_num = m.question_num(+)
    22  and cr.answer_num = m.answer_num(+)
    23  order by cr.seat_num, cr.question_num, cr.answer_num;
    SE QU AN POINTS
    S1 Q1 A1 1 point
    S1 Q2 A2 1 point
    S1 Q3 A3 1 point
    S2 Q1 A5 0 point
    S2 Q2 A6 0 point
    S2 Q3 A3 1 point
    6 rows selected.
    test@ORA10G>
    test@ORA10G> with master as (
      2    select 'Q1' as question_num, 'A1' as answer_num from dual union all
      3    select 'Q2', 'A2' from dual union all
      4    select 'Q3', 'A3' from dual),
      5  candidate_response as (
      6    select 'S1' as seat_num, 'Q1' as question_num, 'A1' as answer_num from dual union all
      7    select 'S1', 'Q2', 'A2' from dual union all
      8    select 'S1', 'Q3', 'A3' from dual union all
      9    select 'S2', 'Q1', 'A5' from dual union all
    10    select 'S2', 'Q2', 'A6' from dual union all
    11    select 'S2', 'Q3', 'A3' from dual)
    12  --
    13  select cr.seat_num, count(*) as score
    14  from candidate_response cr, master m
    15  where cr.question_num = m.question_num
    16  and cr.answer_num = m.answer_num
    17  group by cr.seat_num
    18  order by cr.seat_num;
    SE      SCORE
    S1          3
    S2          1
    test@ORA10G>
    test@ORA10G>pratz

  • Query to find out sum by using decode or case

    Hi, I have data like below and required an output as given below, could you please help me to get the same by using decode / case .....Thanks for your help
    INSNAME INSID STATUS
    AAA 1000 Scheduled
    AAA 1000 Processing
    BBB 1001 Inspector
    BBB 1001 Scheduled
    BBB 1001 Processing
    BBB 1001 Inspector
    CCC 1002 Scheduled
    CCC 1002 Processing
    CCC 1002 Inspector
    CCC 1002 Scheduled
    CCC 1002 Processing
    CCC 1002 Inspector
    Required Output...
    INSNAME INSID sum_of_scheduled sum_of_Processing sum_of_Inspector
    AAA 1000 1 1 0
    BBB 1001 1 1 2
    CCC 1002 2 2 2

    And if you want it with CASE statement:
    WITH test_table AS
       SELECT 'AAA' insname, 1000 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'AAA' insname, 1000 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Inspector'   status FROM DUAL
    SELECT insname
          ,insid
          ,SUM(CASE WHEN status = 'Scheduled'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_scheduled
          ,SUM(CASE WHEN status = 'Processing'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_processing
          ,SUM(CASE WHEN status = 'Inspector'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_inspector         
      FROM test_table
    GROUP BY insname
            ,insid;
    Regards
    Arun

  • Help with Decode/Case

    Hello All,
    Can I use decode/case function within a decode function?
    {code}
    SELECT TO_CHAR (
              EDMS_STRAGG_WC (
                 DISTINCT DECODE (
                             eqs.attrib_code,
                             'PRODUCT_AUTHORIZATION',    'Authorization: '
                                                      || CASE eqs.qual_value
                                                            WHEN 'LIST'
                                                            THEN
                                                               (SELECT lookup_desc
                                                                  FROM edmsadm.edms_lookup
                                                                 WHERE     lookup_type =
                                                                              'PARTNER_AUTHORIZATION'
                                                                       AND lookup_code =
                                                                              eqls.list_value)
                                                            ELSE
                                                               (SELECT lookup_desc
                                                                  FROM edmsadm.edms_lookup
                                                                 WHERE     lookup_type =
                                                                              'PARTNER_AUTHORIZATION'
                                                                       AND lookup_code =
                                                                              eqs.qual_value)
                                                         END,
                             'PRODUCT_CERTIFICATION',    'Certification: '
                                                      || CASE eqs.qual_value
                                                            WHEN 'LIST'
                                                            THEN
                                                               eqls.list_value
                                                            ELSE
                                                               eqs.qual_value
                                                         END,
                             'PRODUCT_SPECIALIZATION',    'Specialization: '
                                                       || (SELECT lookup_desc
                                                             FROM edmsadm.edms_lookup
                                                            WHERE     lookup_type =
                                                                         'PARTNER_SPECIALIZATION'
                                                                  AND lookup_code =
                                                                         CASE eqs.qual_value
                                                                            WHEN 'LIST'
                                                                            THEN
                                                                               eqls.list_value
                                                                            ELSE
                                                                               eqs.qual_value
                                                                         END))))
              program_value
      FROM edms_qual_stg eqs, edms_qual_list_stg eqls
    WHERE     1 = 1
           AND eqs.qual_id = eqls.qual_id(+)
           AND eqs.req_id = 192647
           AND eqs.disc_line_id = 598631
           AND eqs.attrib_code IN
                  ('PRODUCT_CERTIFICATION',
                   'PRODUCT_AUTHORIZATION',
                   'PRODUCT_SPECIALIZATION');
    {code}
    Edms_qual_stg:
    AND_OR_CONDITION
    ATTRIBUTE_SOURCE
    ATTRIB_CODE
    CREATED_BY
    CREATED_DT
    DISC_LINE_ID
    END_DT
    EXCLUDE_INCLUDE
    GROUP_AND_OR_CONDITION
    GROUP_CODE
    MAX_VALUE
    MIN_VALUE
    MODIFIED_BY
    MODIFIED_DT
    QUAL_APPL_PRECEDENCE
    QUAL_ID
    QUAL_OPERATOR
    QUAL_TYPE
    QUAL_VALUE
    REQ_ID
    START_DT
    Edms_qual_list_stg:
    ATTRIBUTE_SOURCE
    ATTRIB_CODE
    CREATED_BY
    CREATED_DT
    END_DT
    INCLUDE_AFFILIATES
    INCLUDE_EXCLUDE
    LIST_VALUE
    MODIFIED_BY
    MODIFIED_DT
    PRIMARY_PARTY
    QUAL_ID
    QUAL_LIST_ID
    REFERENCE_ID
    START_DT
    Edms_lookup:
    CREATED_BY
    CREATED_DT
    DISPLAY_SEQ
    EDMS_LOOKUP_ID
    END_DATE
    LOOKUP_CODE
    LOOKUP_DESC
    LOOKUP_REFERENCE
    LOOKUP_TYPE
    MODIFIED_BY
    MODIFIED_DT
    START_DATE
    SELECT eqs.qual_id, eqs.disc_line_id, eqs.req_id, eqs.attrib_code, eqs.qual_value, eqls.list_value
      FROM edms_qual_stg eqs, edms_qual_list_stg eqls
    WHERE     1 = 1
           AND eqs.qual_id = eqls.qual_id(+)
           AND disc_line_id = 598631
           AND req_id = 192647
           AND eqs.attrib_code IN
                  ('PRODUCT_CERTIFICATION',
                   'PRODUCT_AUTHORIZATION',
                   'PRODUCT_SPECIALIZATION');
    7509575    598631    192647    PRODUCT_CERTIFICATION    LIST    GOLD
    7509575    598631    192647    PRODUCT_CERTIFICATION    LIST    SILVER
    7509576    598631    192647    PRODUCT_AUTHORIZATION    LIST    ATP - JOULEX PROVIDER ESCO
    7509576    598631    192647    PRODUCT_AUTHORIZATION    LIST    ATP - JOULEX PROVIDER IDENTIFY
    7509577    598631    192647    PRODUCT_SPECIALIZATION    LIST    ADVANCED SECURITY
    7509577    598631    192647    PRODUCT_SPECIALIZATION    LIST    EXPRESS FOUNDATION
    Required Output:
    Certification: GOLD, SILVER, Authorization: ATP - JOULEX PROVIDER ESCO, ATP - JOULEX PROVIDER IDENTIFY,  SPECIALIZATION: ADVANCED SECURITY, EXPRESS FOUNDATION.
    Thx
    Shank.

    Hi,
    Sure; a DECODE or CASE expression that returns a NUMBER can be used any place a NUMBER is expected, including within another DECODE or CASE expression.  A DECODE or CASE expression that returns a DATE can be used any place a DATE is expected, including within another DECODE or CASE expression.  A DECODE or CASE expression that returns a VARCHAR2 can be used almost any place a VARCHAR2 is expected.  (There a  couple of special situations where a string literal is absolutely required.)
    There are not many situations where you really need to do that, though.  It's usually simpler and more efficient to use a single CASE expression; nesting is rarely needed.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Simplify the problem as much as possible, so that it contains only enough to show the part you don't already know how to do.
    If you really need a user-defined function to show the problem, then include a CREATE FUNCTION statement, and explain what the function does.  Again, simplify: if the function isn't what you don't understand, post a problem that doesn't use the function.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Using 'DECODE'  instead of 'CASE' in select

    Hi,
    I am using CASE statements in my Select clause using 9i.
    SELECT
                     CASE
                           WHEN S.cmpy_num = S.cpty_borg_num THEN
                           ''OURS''
                           ELSE
                           ''THEIRS''
                           END AS SDIOwner,
                           S.active_flag,
    from SDI sI wud like to try this in 8I but 8i doesnt support CASE statements
    in Select clauses.
    It was recommended to use Decode in place of CASE in 8I
    How can i write the decode statement for the above CASE statement in 9I

    GOT IT RUNNIG.THANKS A LOT JAMES...
    I AM TESTING SYSTEMS ON 9I AND 8I...

  • More effecient way of using Decode and CASE

    Is it possible to use both case and decode together? I feel I have too many decode and I am not sure how to write this in a more efficient way.
    I would really appreciate any help.
    Thank you so much in advance!!!
    SELECT  Person_ID,Work_ID,
        CASE WHEN NBR = 1 THEN
                MIN(DECODE(NBR, 1, field1)) aug_one_field1;
                MIN(DECODE(NBR, 1, field2)) aug_one_field2;
                MIN(DECODE(NBR, 1, field3)) aug_one_field3;
                MIN(DECODE(NBR, 1, field4)) aug_one_field4;
                MIN(DECODE(NBR, 1, field5)) aug_one_field5;
                MIN(DECODE(NBR, 1, field6)) aug_one_field6;
        CASE WHEN NBR = 2 THEN
                MIN(DECODE(NBR, 2, field1)) aug_two_field1;
                MIN(DECODE(NBR, 2, field2)) aug_two_field2;
                MIN(DECODE(NBR, 2, field3)) aug_two_field3;
                MIN(DECODE(NBR, 2, field4)) aug_two_field4;
                MIN(DECODE(NBR, 2, field5)) aug_two_field5;
                MIN(DECODE(NBR, 2, field6)) aug_two_field6;
        CASE WHEN NBR = 3 THEN
                MIN(DECODE(NBR, 3, field1)) aug_three_field1;
                MIN(DECODE(NBR, 3, field2)) aug_three_field2;
                MIN(DECODE(NBR, 3, field3)) aug_three_field3;
                MIN(DECODE(NBR, 3, field4)) aug_three_field4;
                MIN(DECODE(NBR, 3, field5)) aug_three_field5;
                MIN(DECODE(NBR, 3, field6)) aug_three_field6;
        CASE WHEN NBR = 4 THEN
                MIN(DECODE(NBR, 4, field1)) aug_four_field1;
                MIN(DECODE(NBR, 4, field2)) aug_four_field2;
                MIN(DECODE(NBR, 4, field3)) aug_four_field3;
                MIN(DECODE(NBR, 4, field4)) aug_four_field4;
                MIN(DECODE(NBR, 4, field5)) aug_four_field5;
                MIN(DECODE(NBR, 4, field6)) aug_four_field6;
    END
       FROM (SELECT Person_ID,Work_ID, NBR
                   fiel1, field2, field3,field4,field5, field6,
                  FROM field_rep
       GROUP BY Person_ID,Work_ID

    Thanks alot John and Frank.
    John to answer your question, I just felt the 24 or more decode will slow down the systems performance, hence I was trying to find a better way to do it.
    Frank
    This is a sample data but I want it pivoted hence the reason for using the decode. I have oracle 10g. These are sample data
    Person_id work_id NBR      field1     field2     field3     field4 field5 field6
    1       ao334   1     1/2/2009   1/9/2010     block_A        HH       55667      1
    1       ao334   2     5/2/2011   9/9/2013     block_Z        HL       11111      3
    1       ao334   2     1/2/2009   1/9/2010     block_A        HH       22222      1
    1       ao334   4     1/2/2009   1/9/2010     block_A        HH       zzzzz      7
    1       z5521   1     10/5/2006  12/31/2012     block_C        SS       33322      1
    1       z5521   2     1/2/2009   1/9/2010     block_C        SS       21550      1
    1       z5521   3     1/2/2009   1/9/2010     block_R        SS       10000      1
    1       z5521   4     1/2/2009   1/9/2010     block_D        SS       99100      5
    1       z5521   5     1/2/2009   1/9/2010     block_P        SS       88860      1
    1       z5521   6     1/2/2009   1/9/2010     block_G        SS       99660      8
    1       ob114   1     1/2/2009   1/9/2010     block_A        HH       52333      1
    1       ob114   2     1/2/2009   1/9/2010     block_A        HH       88888      1Output will look like this
    Person_id work_id  aug_one_field1 aug_one_field2 aug_one_field3 aug_one_field4 aug_one_field5 aug_one_field6 aug_two_field1 aug_two_field2 aug_two_field3 aug_two_field4 aug_two_field5  aug_two_field6
    1       ao334        1/2/2009       1/9/2010       block_A       HH             55667          1              5/2/2011       9/9/2013       block_Z        HL                      11111          3

  • How to use index, when query has decode/case

    Hi,
    I have the following query
    i have a index on party_id,party_type_Code in the zx_party_tax_profile table But this index is not used as Iam using a decode on the columns of the zx_party_tax_profile table,
    Is there any way i can rewrite the query so that it uses index
    sELECT /*+ INDEX(ZX_PARTY_TAX_PROFILE_U2) */ party_tax_profile_id FROM (SELECT
    ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    ThirdPartyTaxProfileEO.CUSTOMER_FLAG,
    ThirdPartyTaxProfileEO.SITE_FLAG,
    ThirdPartyTaxProfileEO.PARTY_TAX_PROFILE_ID,
    ThirdPartyTaxProfileEO.PARTY_ID,
    ThirdPartyTaxProfileEO.REP_REGISTRATION_NUMBER,
    ThirdPartyTaxProfileEO.OBJECT_VERSION_NUMBER,
    ThirdPartyTaxProfileEO.REGISTRATION_TYPE_CODE,
    ThirdPartyTaxProfileEO.COUNTRY_CODE,
    ThirdPartyTaxProfileEO.MERGED_TO_PTP_ID,
    ThirdPartyTaxProfileEO.MERGED_STATUS_CODE,
    ThirdPartyTaxProfileEO.PROGRAM_APP_NAME,
    ThirdPartyTaxProfileEO.PROGRAM_NAME,
    PartyPEO.PARTY_NAME,
    PartyPEO.PARTY_ID AS PARTY_ID1,
    PartyPEO.PARTY_NUMBER,
    decode(ThirdPartyTaxProfileEO.CUSTOMER_FLAG,
    'Y',decode(ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    'Y', 'SC',
    'C'),
    decode(ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    'Y', 'S',
    NULL)
    ) AS PARTY_USAGE,
    ThirdPartyTaxProfileEO.REP_REGISTRATION_NUMBER AS TAX_REG_NUMBER,
    LkupPartyUsage.MEANING AS PARTY_USAGE_DESC,
    PartyPEO.PARTY_NAME AS PARTY_FULL_NAME,
    PartyPEO.ADDRESS1||','||
    PartyPEO.ADDRESS2||','||
    PartyPEO.ADDRESS3||','||
    PartyPEO.CITY||','||
    PartyPEO.postal_code||','||
    PartyPEO.COUNTRY AS ADDRESS,
    PartyPEO.COUNTRY AS COUNTRY_CODE_TCA,
    TerritoryPEO.TERRITORY_SHORT_NAME AS COUNTRY_NAME,
    PartyPEO.JGZZ_FISCAL_CODE AS TAX_PAYER_ID,
    PartyPEO.DUNS_NUMBER_C AS DUNS_NUMBER,
    PartyPEO.Party_Number as Party_Num_Calc,
    null as REGISTRATION_TYPE_NAME,
    null as ROUNDING_LEVEL_NAME,
    null as ROUNDING_RULE_NAME,
    null as COUNTRY_NAME_PTP,
    'ZX_PARTY_TAX_PROFILE' as TAX_REPORTING_ENTITY_CODE
    FROM ZX_PARTY_TAX_PROFILE ThirdPartyTaxProfileEO,
    HZ_PARTIES PartyPEO,
    FND_LOOKUP_VALUES_VL LkupPartyUsage,
    FND_TERRITORIES_VL TerritoryPEO
    WHERE ThirdPartyTaxProfileEO.PARTY_ID = PartyPEO.PARTY_ID AND
    LkupPartyUsage.LOOKUP_CODE = decode(ThirdPartyTaxProfileEO.CUSTOMER_FLAG,
    'Y',decode(ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    'Y', 'SC',
    'C'),
    decode(ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    'Y', 'S',
    NULL)
    ) AND
    PartyPEO.COUNTRY = TerritoryPEO.Territory_Code (+) AND
    LkupPartyUsage.LOOKUP_TYPE = 'ZX_TP_PARTY_USAGE'
    ORDER BY UPPER(PARTY_FULL_NAME)) QRSLT WHERE UPPER(PARTY_NAME) IS NOT
    NULL
    Any help will be appreciated

    You can rewrite your where clause to not use decode or case statements e.g. this:
      AND LkupPartyUsage.LOOKUP_CODE = DECODE( ThirdPartyTaxProfileEO.CUSTOMER_FLAG
                                , 'Y', DECODE( ThirdPartyTaxProfileEO.SUPPLIER_FLAG, 'Y', 'SC', 'C' )
                                     , DECODE( ThirdPartyTaxProfileEO.SUPPLIER_FLAG, 'Y', 'S', NULL ) )
                                     )can be rewritten to this:
    and (
          ( ThirdPartyTaxProfileEO.CUSTOMER_FLAG = 'Y'  AND
              ((ThirdPartyTaxProfileEO.SUPPLIER_FLAG = 'Y' AND LkupPartyUsage.LOOKUP_CODE = 'SC') or
                ThirdPartyTaxProfileEO.SUPPLIER_FLAG != 'Y' AND LkupPartyUsage.LOOKUP_CODE = 'C')) or
          ( ThirdPartyTaxProfileEO.CUSTOMER_FLAG != 'Y'  AND
              ((ThirdPartyTaxProfileEO.SUPPLIER_FLAG = 'Y' AND LkupPartyUsage.LOOKUP_CODE = 'S') or
                ThirdPartyTaxProfileEO.SUPPLIER_FLAG != 'Y' AND LkupPartyUsage.LOOKUP_CODE is null))
        )It's not as sussinct, but it avoids the use of functions that could be preventing the optimiser from using an index.

  • Problem using DECODE() function with a Query of Queries

    I
    posted
    on my blog about an issue I was having trying to use the PL/SQL
    DECODE() function with a Coldfusion Query of Queries. This function
    works fine when you query a database for information. However, when
    you query another query, it seems that CF doesn't recognize it. I
    got errors stating that it found a left parenthesis where it
    expected a FROM key word. Here is a simplified version of what I am
    trying to do:
    quote:
    <!--- Simulated query; similar to what I was calling from
    my database --->
    <cfscript>
    qOriginal = queryNew("Name,Email,CountryCode",
    "VarChar,VarChar,VarChar");
    newRow = queryAddRow(qOriginal, 5);
    querySetCell(qOriginal, "Name", "Joe", 1);
    querySetCell(qOriginal, "Email", "[email protected]", 1);
    querySetCell(qOriginal, "CountryCode", "AMER", 1);
    querySetCell(qOriginal, "Name", "Sally", 2);
    querySetCell(qOriginal, "Email", "[email protected]", 2);
    querySetCell(qOriginal, "CountryCode", "AMER", 2);
    querySetCell(qOriginal, "Name", "Bob", 3);
    querySetCell(qOriginal, "Email", "[email protected]", 3);
    querySetCell(qOriginal, "CountryCode", "ASIA", 3);
    querySetCell(qOriginal, "Name", "Mary", 4);
    querySetCell(qOriginal, "Email", "[email protected]", 4);
    querySetCell(qOriginal, "CountryCode", "EURO", 4);
    querySetCell(qOriginal, "Name", "John", 5);
    querySetCell(qOriginal, "Email", "[email protected]", 5);
    querySetCell(qOriginal, "CountryCode", "EURO", 5);
    </cfscript>
    <cfquery name="qCountries" dbtype="query">
    SELECT DISTINCT(CountryCode) AS CountryCode,
    DECODE(states, "AMER", "North America &amp; Canada",
    "EURO", "Europe &amp; Africa", "ASIA", "Japan &amp;
    Asia","") CountryName
    FROM qOriginal
    ORDER BY CountryCode
    </cfquery>
    <cfdump var="#qCountries#">
    <!--- ========== END OF CODE ========== --->
    So running this returned the following error:
    Query Of Queries syntax error.
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    Does anybody know why this doesn't work? Is it just not
    supported? Please note that I have also tried to use the CASE()
    function instead of DECODE() and that resulted in basically the
    same error. For now I an looping over my distinct query with a
    switch statement and manually loading a new query with the data how
    I want it. But it would be a lot cleaner and less code to have the
    DECODE() to work. Thx!

    DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
    very limited subset of SQL and lacks many functions and clauses
    available in standard SQL, especially what you may be used to using
    in your particular RDBMS.
    See
    Query
    of Queries user guide
    Phil

  • Using DECODE Function in SQL

    I need to know if there is any way to use a range of values from
    database and decode to certain text. I am able to do with one
    value.
    for example:
    DECODE(column_name,'216767111','Unlimited',column_name)
    above argument works with one value only. How about a range,
    ex: 216767000 to 216767111. I need to use only SQL. No PL/SQL.
    Kinldly need some body's help
    Thanks
    Munis

    Which version of the database? If it's 8i+ then you can use
    the CASE function
    for example:
    (CASE WHEN column_name between 216767000 and 216767111
    THEN 'Unlimited' ELSE column_name END)
    This won't work in PL/SQL because they're introducing a CASE
    statement does soemthing different.
    rgds, APCHello Andrew
    Thank you for response. I am using 8i. 8.1.6. However using
    CASE, I get inconsistent data type, ORA-00932: inconsistent
    datatypes. I able to work it out with other response using
    DECODE(sign(. Do you have any idea why i am getting this error.
    If time permits, let me know

  • How to use the CASE Expression in Where Cluase?

    Hi All,
    I'm trying to use the CASE Expression in the Where Clause at some trigger on the Form?
    I've tried this Code:
    Declare
    N Number;
    begin
    SELECT COUNT(E.EMP_SID)
         INTO N
         FROM EMPLOYEES E, RANKS R
         WHERE CASE WHEN R.qualification_sid = 1104 AND E.rank_sid = 8 THEN
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.spe_per)+1)
         ELSE
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.mili_yea_per)+1)
         END
         BETWEEN TO_DATE('01-07-2011', 'DD-MM-RR') AND TO_DATE('31-07-2011', 'DD-MM-RR');
    END;
    When I run this code as a normal query at any SQL editor it works successfully, But When I Compile it at some trigger on the Form it gives me this error:
    Encountered the symbol "CASE" when expecting one of the following:
    ( - + mod ......
    Heeey how to specify the previous code to be shown as code in the thread?
    Note: I'm using Forms 6i

    OK I tried it and worked but for one condition:
    WHERE DECODE (E.qualification_sid, 1104,
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.spe_per)+1),
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.mili_yea_per)+1))
         BETWEEN TO_DATE('01-07-2011', 'DD-MM-RR') AND TO_DATE('31-07-2011', 'DD-MM-RR')
    But how to put two conditions for the same Expression:
    WHERE DECODE ((E.qualification_sid, 1104) AND (E.RANK_SID, 8),
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.spe_per)+1),
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.mili_yea_per)+1))
         BETWEEN TO_DATE('01-07-2011', 'DD-MM-RR') AND TO_DATE('31-07-2011', 'DD-MM-RR')
    The previous code gives me this error: missing right parenthesis

  • 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

  • How to use DECODE function in Exspression?

    Hi,
    Can we use DECODE in Expression?
    I'm trying to use DECODE function but there is an error during the validation. But when i validate the mapping, it is successfully compiled but it is failed during deployment.
    But if I use CASE instead of DECODE, it works fine.
    Can we use DECODE in OWB???
    Thanks
    Raj

    Hi,
    In OWB 10gR2, if your are using only one DECODE in an expression, it's working. The package will compile when deploying the mapping. OWB will replace the DECODE by a CASE.
    But when you are using nested decode in an expression ( for example : decode(col1, 1, 'M', decode(col2, 'Madame', 'Mme', null)) ) only the first one is replaced by a case at deployment.
    In ROW_BASED mode, text of the expression is used outside of an sql statement and deployment will fails with "PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only."
    If operating mode for the mapping is set to SET_BASED, it's working because the expression is used in an sql statement.
    I have logged a SR in metalink for this issue and a bug is opened (bug 5414112).
    But I agree with you, it's better to use case statement.
    Bernard

  • Decode/Case in Where clause

    Hello,
    We are experiencing an issue with a Select statement that uses Decode in the Where clause. Specifically, it seems to be ignoring a nested Decode and just returning the default value. We have another nested decode that works fine, though.
    A member of our team mentioned that he believed there was an issue with using Decode and Case statements inside of a where clause within HTML DB...Is this correct? If it is, is there a workaround? Since the nested Decode works elsewhere in this statement, that doesn't seem right.
    My select statement looks like:
    SELECT
       SUBSTR(OBOB.OBOB_CNAME, 0, 30) d,
       OBOB.OBOB_UID r
    FROM
       ISR_OBOB_OBJECT OBOB,
       ISR_OBAF_OBJECT_AFFILIATION OBAF,
       ISR.ISR_OBSD_SDR OBSD
    WHERE
       OBOB.OBOB_UID = OBSD.OBOB_UID AND
       OBOB.OBOB_UID = OBAF.OBOB_B_UID AND
    /*If Personal radio button is selected, displays all SDRs associated with user.
      If All is selected, displays all SDRs associated with IS group selected from drop down list
          or every SDR.
       OBAF.OBOB_A_UID = DECODE(:P1_DISPLAY_ALL,
                                       'Personal', :F101_APP_USER_UID,
    /*This is the decode statement that it seems to ignore. If ALL is selected, the query should see if a group has
        has been selected from a drop down list that appears when the ALL button is chosen. If a group is selected
        (the item isn't 0), only SDRs for that group should be shown. Otherwise, all SDRs for every group should display.
                                       'ALL', DECODE(:P1_SEARCH_IS_SUPPORT_GROUP, 0, OBAF.OBOB_A_UID, :P1_SEARCH_IS_SUPPORT_GROUP),
                                       OBAF.OBOB_A_UID) AND
    /*If Personal radio button is selected, display SDRs where user is the Primary assignee.
       OBAF.OBAT_UID = DECODE(:P1_DISPLAY_ALL, 'Personal', (select OBAT_UID from ISR_OBAT_OBJ_AFFIL_TYPE WHERE OBAT_APP_REF = 'SDR_PRIMARY'), OBAF.OBAT_UID) AND
    /*If a SDR Status (open, completed, on hold, not started...) is selected, only display the SDRs with that status.
       OBSD.KTTR_STATUS_UID = DECODE(:P1_ISR_STATUS_UID, 0, OBSD.KTTR_STATUS_UID, :P1_ISR_STATUS_UID) AND
    /*If SDR_History textbox is Null, or Open, Not Started, or On Hold SDR status has been selected, then all SDRs with
        a create date between today and 99999 months ago will display. Otherwise, only SDRs with a create date between
        today and however many months are in the textbox will display (i.e. Completed SDRs created in the past 6 months.)
       MONTHS_BETWEEN(sysdate, OBSD.OBSD_CREATE_DATE) <= DECODE(:P1_SDR_HISTORY, NULL, 99999, DECODE(:P1_ISR_STATUS_UID,
                                                              (select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_OPEN'), 99999,
                                                              (select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_NOT_STA'), 99999,
                                                              (select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_HOLD'), 99999,
                                                              :P1_SDR_HISTORY))
    /*Alphabetical order
    Order by
       dWe originally wrote this as a PL/SQL statement that returned a query string since most of the where clause is dependent on items the user may or may not select, but we have moved the query into a multiselect list, which only seems to allow SQL Queries.
    Any help or advice would be appreciated.
    Thanks,
    Scott

    Scott: Did you try running that SQL statement in SQL Workshop in Apex? You can run it as it is, it will popup a window asking you to enter values for the bind variables.
    JAC73: I don't think an IN clause doesn't work that way, you need a actual SQL sub-query, not an expression from a DECODE/CASE statement. Search this site for str2tbl and see Tom's excellent discussion at
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:110612348061

  • Using decode function

    Hi
    Help needed.... i need to create column as L, R in fact table in business layer using below mentioned logic
    select count(decode (type, '41',1,'51',1,'61',1))L, count(decode(type, '71',1,'31',1,'81',1))R
    Waiting for the reply soon.
    thanks & regards
    Edited by: user11933655 on 29-Oct-2009 10:26

    Similar thread/question:
    Re: How to count distinct excluding a value in business layer?
    You may use:
    L -> case when table.column in ('41', '51', '61') then 1 else 0 end
    R -> case when table.column in ('71', '31', '81') then 1 else 0 end
    Assuming that table.column is dimension attribute and you joined this table dimension to a fact table (steps 2 and 3 from the link above, add physical join to dimension table in the logical fact table source). L and R are two logical columns, using COUNT or SUM as aggregation rule.
    Follow steps 1-7 (1-9 for complete) from the link above.
    Regards
    Goran
    http://108obiee.blogspot.com

  • Using decode function without negative values

    Hi friends
    I am using oracle 11g
    I have at doubt regarding the following.
    create table Device(Did char(20),Dname char(20),Datetime char(40),Val char(20));
    insert into Device values('1','ABC','06/13/2012 18:00','400');
    insert into Device values('1','abc','06/13/2012 18:05','600');
    insert into Device values('1','abc','06/13/2012 18:55','600');
    insert into Device values('1','abc','06/13/2012 19:00','-32768');
    insert into Device values('1','abc','06/13/2012 19:05','800');
    insert into Device values('1','abc','06/13/2012 19:10','600');
    insert into Device values('1','abc','06/13/2012 19:15','900');
    insert into Device values('1','abc','06/13/2012 19:55','1100');
    insert into Device values('1','abc','06/13/2012 20:00','-32768');
    insert into Device values('1','abc','06/13/2012 20:05','-32768');
    Like this I am inserting data into table for every 5 minutes Here i need the result like
    output:
    Dname 18:00 19:00 20:00
    abc 400 -32768 -32768
    to retrieve this result i am using decode function
    SELECT Dname,
    MAX(DECODE ( rn , 1,val )) h1,
    MAX(DECODE ( rn , 2, val )) h2,
    FROM
    (SELECT Dname,Datetime,row_number() OVER
    (partition by Dname order by datetime asc) rn FROM Device
    where substr(datetime,15,2)='00' group by Dname.
    According to above data expected result is
    Dname 18:00 19:00 20:00
    abc 400 600(or)800 1100
    This means I dont want to display negative values instead of that values i want to show previous or next value.
    Edited by: 913672 on Jul 2, 2012 3:44 AM

    Are you looking for something like this?
    select * from
    select dname,
           datetime,
           val,
           lag(val) over (partition by upper(dname) order by datetime) prev_val,
           lead(val) over (partition by upper(dname) order by datetime) next_val,
           case when nvl(val,0)<0  and lag(val) over (partition by upper(dname) order by datetime) >0 then
             lag(val) over (partition by upper(dname) order by datetime)
           else 
             lead(val) over (partition by upper(dname) order by datetime)
           end gt0_val
    from device
    order by datetime
    where substr(datetime,15,2)='00';Please take a look at the result_column gt0_val.
    Edited by: hm on 02.07.2012 04:06

Maybe you are looking for