Case of decode

Hello
In this query I used CASE for some conditions. Can I use DECODE instead of CASE? The case statement is bolded.


SELECT B.cmp_snam_e Buyer_Name,
a.code Buyer_Ref,
Open_Date b.enter_dt,
NVL(a.new_ocl,0) OCL_US$,.
a.dec_date_g Last_Revision,
a.new_exp Next_Update,
b.st1_ref Stat_Ref,
initcap (c.mtb_desc) status,
d.source_code Agency_Code,
d.inf_surs Info_Source_Code,
d.cbc_req_dt Date_Requested,
d.crp_date Date_Received,
CASE
WHERE (a.os_rec_status IN ('PC'))
THEN a.os_rec_ref
WHEN (a.os_rec_status) ("IT", "GA", "CL", "AR")
THEN
* (SELECT Pcy_ref *)
OF con_cla_sub_apr_view
WHERE CLA_REF = A.OS_REC_REF
AND byr_ref = a.code
AND cla_sub =
* (SELECT MAX (CLA_SUB) FROM con_cla_sub_apr_view WHERE CLA_REF = A.OS_REC_REF*
*)*
*)*
END AS Policy_Ref, e.hst_remark
Ocl_submission has,.
companies b,.
master_tbl c,
cmp_by_crp d,
e buyer_remarks
WHERE A.code = B.cmp_ref
AND b.st1_ref = c.mtb_ref
AND a.code = d.cmp_ref
AND a.code = e.hst_byr_ref (+)
AND B.cmp_type = 'BYR.
AND B.st1_ref = "ST1-00054'."
AND (b.enter_dt > =: FROM_DATE)
AND b.enter_dt < =: TO_DATE)
AND A.SEQ =
(SELECT MAX (SEQ) - 1 FROM ocl_submission WHERE CODE = B.cmp_ref AND SEQ! = 1).
)
AND d.srno =
(SELECT MAX (TO_NUMBER (srno))
OF cmp_by_crp
WHERE cmp_ref = a.code
AND srno! = 1
)
AND (e.hst_byr_ref, e.hst_byr_sub, e.SEQ) IN
(
SELECT hst_byr_ref, hst_byr_sub, MAX (SEQ) OF buyer_remarks WHERE
(hst_byr_ref, hst_byr_sub) IN
(SELECT hst_byr_ref, MAX (hst_byr_sub)
FROM buyer_remarks WHERE hst_byr_ref = a.code
GROUP BY hst_byr_ref)
Hst_byr_ref GROUP, hst_byr_sub
);

Hello

You can still use DECODE instead (and you can always use CASES instead of DECODE and should almost always).

I agree with Someoneelse and Alex: this is an example of a situation in this CASE is better than DECODE.

DECODE ( a.os_rec_status
       , 'PC'           , a.os_rec_ref
                        , DECODE ( INSTR ( ',IT,GA,CL,AR,'
                                  , ',' || a.os_rec_status || ','
                             )
                      , 0       , NULL
                               , (
                             SELECT  pcy_ref
                             FROM    con_cla_sub_apr_view
                             WHERE   CLA_REF     = A.OS_REC_REF
                             AND         byr_ref     = a.code
                             AND         cla_sub      = (
                                                  SELECT  MAX (CLA_SUB)
                                          FROM       con_cla_sub_apr_view
                                          WHERE       CLA_REF     = A.OS_REC_REF
                                          )
                             )
                      )
     )

This assumes that os_rec_status never contains commas.

I can't imagine a situation in which DECODE would be significantly faster this CASE.
I imagine many situations in which the CASE is significantly faster than DECODE.
I expect, in this case, THAT CASE is only slightly faster than DECODE.

Tags: Database

Similar Questions

  • No CASE or DECODE

    I have a table with say a column called 'COLOUR' with 500 different values - lets say 3 values are red white and blue. There are 497 other

    I want to insert table with the column of color in another table called 'OTHER '.
    But whenever I hit a blue, I want to insert red instead. All other values remain the same as they are.
    I tried CASE and DECODE, but it leaves me with NULL values for others 497 values. Is there a way to do saying only when I hit the blue, I want it to be red, without hard-code all other values? For example:
    Insert into ANOTHER table
    Select
    COLUMN1,
    COLUMN2,
    COLUMN3,
    COLOR (if color is blue, red insert - then let all the other colors to be what they are)
    COLUMN 5

    It would be useful to show the CASE statement that failed. But I think that you would

    INSERT INTO destinationTable( list_of_columns )
      SELECT list_of_columns,
             (CASE WHEN color = 'BLUE' THEN 'RED' ELSE color END) color
         FROM sourceTable
    

    Justin

  • Help in to convert CASE to DECODE in 11g sql

    11 GR 2, Windows.

    Can someone help me rewrite under sql CASE statement to DECODE?
    SELECT INVOICE_ID,sum(TOTAL_EXCL_VAT),LEVEL2 as descr,
    sum(case when instr(LEVEL2,'Internet')>0 then SUM_QUANTITY else 0 end) as KB  --- >> Here
    from rator_cdr.INVOICE_DETAIL_LINE 
    WHERE INVOICE_ID ='000000000000000000' and CALLER='0000000000' and LEVEL1='Gesprekskosten' 
    group by LEVEL2,INVOICE_ID;
    Thank you

    Why would you want to replace the much more expressive syntax of CASES with a DECODING?

    If you are really determined

    DECODE( instr( level2, 'Internet' ), 0, 0, sum_quantity )
    

    I would strongly prefer the option CASE, however.

    Justin

  • How to use the case and decode to extract data

    Hello gurus of PL/SQL,.

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version

    I have a table in the following form-
    drop table TT2;
    create table TT2(College, Class,gender,status,fees) as select
    'IITB','MBA','M','P',255600 from dual union all select
    'IITK','MTech','M','P',300000 from dual union all select
    'IITD','MBA','F','P',450000 from dual union all select
    'IITKH','MBA','F','P',350000 from dual union all select
    'IITC','MTech','F','P',420000 from dual union all select
    'IITB','MTech','M','P',185000 from dual union all select
    'IITC','MTech','M','P',235000 from dual union all select
    'IITD','MBA','F','F',175000 from dual union all select
    'IITM','MBA','M','F',257000 from dual union all select     
    'IITKH','MTech','F','P',335000 from dual union all select
    'IITD','MBA','F','P',540335 from dual union all select
    'IITC','MBA','F','F',125089 from dual union all select
    'IITD','MTech','M','P',290756 from dual union all select
    'IITM','MBA','M','P',200000 from dual union all select     
    'IITKH','MBA','F','F',534990 from dual union all select
    'IITD','MBA','F','P',221000 from dual ;
    certain conditions of extraction are as follows-

    MATTER OF STATE
    College of 'IITB' and status = 'P'-'good WestRegion '.
    College of 'IITC' and status = 'P'-'good SouthRegion '.
    College 'IITD' and 'IITK' and status = 'P' and type = 'F' - 'female NothRegion spent.
    College not in 'IITK' and status = 'F' - 'Ex Kanpur Failed'

    Results-
    Region Statnding     Fees
    WestRegion Passed     440460
    SouthRegion Passed     655000
    NothRegion Female Passed     1386335
    Ex Kanpur Failed     1092079
    Used SQL
    I use the following query that only make sure of the case, but it's not how I want to exit, if I try to use the case to breast to decode then how to work on it.
    SELECT (CASE WHEN College in ('IITB') and status='P' then sum(fees) else 0 end) WP,
    (case when College in ('IITC') and status='P' then sum(fees) else 0 end) SP,
    (case when College in ('IITD','IITK') and gender='F' and status='P' then sum(fees) else 0 end) NFP,
    (case when College in ('IITK') and status='F' then sum(fees) else 0 end) ExKF
    FROM 
    TT2
    GROUP BY College, Class,gender,status
    SELECT CASE WHEN College in ('IITB') and status='P'
                        then 'WestRegion Passed'
                when College in ('IITC') and status='P'
                        then 'SouthRegion Passed'
                when College in ('IITD','IITK') and gender='F' and status='P'
                        then 'NothRegion Female Passed'
                when College in ('IITK') and status='F'
                        then 'Ex Kanpur Failed'
                else 'Others' end region_standing,
                sum(fees) fees
    FROM TT2
    GROUP BY  CASE WHEN College in ('IITB') and status='P'
                        then 'WestRegion Passed'
                when College in ('IITC') and status='P'
                        then 'SouthRegion Passed'
                when College in ('IITD','IITK') and gender='F' and status='P'
                        then 'NothRegion Female Passed'
                when College in ('IITK') and status='F'
                        then 'Ex Kanpur Failed'
                else 'Others' end;
    
  • How to use CASE or DECODE into that?

    Hi, I have a query like this
    AND ...smthng
    AND --smtg
    AND age BETWEEN ....
    For the last clause AND the age column, I have the values passed param in the AOC as strings
    0 '-30', 31-60, 61-90, and ' 91 +'. The setting IN of course is VARCHAR2.

    What I want to do in this clause AND
    for example, for age will '' 0-30, the clause AND should be

    AND BETWEEN age (if this interval is 0 '-30' then) AND 30 0 (if it falls between 31-60'), then BETWEEN 31 AND 60... and so on...
    However this BETWEEN will work up to 61-90 of range but for 91 +, there is no upper limit so it should be
    AND age > 91

    Now, I don't know how to achieve both BETWEEN and ' > ' clauses in the same statement AND.

    DECODE will not work and do not know how to use the CASE in this situation that even this cannot solve this problem.

    Don't want to do the last clause AND Dynamics

    Please suggest me how to do this.

    Thank you
    Aashish

    Published by: Sylvie S. on October 21, 2011 18:01

    A third possibility would be to choose a sufficiently high value as a high-end for the Group 91 + and use something like:

    age between to_number(CASE WHEN instr(:param, '+') = 0
                                  THEN substr(:param, 1, instr(:param, '-') -1)
                                  ELSE substr(:param, 1, instr(:param, '+') -1) end) and
                to_number(CASE WHEN instr(:param, '+') = 0
                               THEN substr(:param, instr(:param, '-') +1)
                               ELSE '9999' END)
    

    John

  • Help on the conversion of questions with case in decode

    Can Hi anyone help me to revise my request plsql? Here's some og the procedure I change to meet with Oracle 8i.

    SELECT SUM (NVL (CASE WHEN (weeks = 'wk1') THEN END qty, 0)) wk1
    SUM (NVL (CASE WHEN (weeks = "wk2") THEN END qty, 0)) wk2,.
    SUM (NVL (CASE WHEN (weeks = 'wk3') THEN END qty, 0)) wk3.
    SUM (NVL (CASE WHEN (weeks = 'wk4') THEN END qty, 0)) wk4

    FROM TABLE1

    Thanks in advance.
    WITH
    TABLE1 AS
    (SELECT 'wk1' WEEKS, 11 AS QTY FROM  DUAL UNION ALL
    SELECT 'wk2' WEEKS, 12 AS QTY FROM  DUAL UNION ALL
    SELECT 'wk3' WEEKS, 13 AS QTY FROM  DUAL UNION ALL
    SELECT 'wk4' WEEKS, 14 AS QTY FROM  DUAL
    )
    
    SELECT
    SUM(NVL(DECODE(weeks,'wk1',qty,0),0)) wk1,
    SUM(NVL(DECODE(weeks,'wk2',qty,0),0)) wk2,
    SUM(NVL(DECODE(WEEKS,'wk3',QTY,0),0)) WK3,
    SUM(NVL(DECODE(weeks,'wk4',qty,0),0)) wk4
    
    FROM TABLE1
    

    Try it please

  • How solve [CASE or DECODE]

    Suppoe I ve 2 columns

    Col_1, Col_2 both are a number

    How to write this condtion in query
    if
    col_1>col_2 then
    return coL_1-col_2
    else
    return
    col_2_col1
    I tried decode and case... but fail to build the query.

    Waiting for answer

    Concerning
    Danish Hayder

    Slow me down... but anyway: this?

    select case
              when col_1 > col_2
                 then col_1 - col_2
              else col_2_col1
           end
      from your_table
    
  • by using a subquery in a case or decode

    Dear Expert;

    I'm still thinking about the perfect solution to this problem

    I have the following sample below tables
    create table t_play
    (
       pid varchar2(60),
       expired number(6)
    );
    
    insert into t_play
      (pid, expired)
    values
      ('A', 1);
    insert into t_play
      (pid, expired)
    values
      ('B', 0);
    insert into t_play
      (pid, expired)
    values
      ('C', 1);
    create table t_play2
    (
       pid varchar2(60),
       zone_place number(6)
    );
    
    insert into t_play2
      (pid, zone_place)
    values
      ('A', 4);
    insert into t_play2
      (pid, zone_place)
    values
      ('C', 5);
    insert into t_play2
      (pid, zone_place)
    values
      ('B', null);  
    Now this is what I want to see
    PID   EXPIRED     RESULT
    A         1            PASSED
    B         0            FAILED
    C         1            PASSED
    Basically, what happens is that if there is a number in the zone_place associated with this particular pid, the result will be passed, if there is no number that then the result will don't has failed, that's why B has a failure...

    Please note, this is just one example of data... All the ideas will help.

    Thank you.

    Published by: user13328581 on January 11, 2011 10:23

    You mean like this?

    SELECT t1.pid,
           t1.expired,
           CASE
             WHEN t2.zone_place IS NULL THEN
              'FAILED'
             ELSE
              'PASSED'
           END RESULT
      FROM t_play  t1,
           t_play2 t2
     WHERE t1.pid = t2.pid
    ORDER BY t1.pid
    
  • Disqualification - CASE or DECODE statement writing

    Test

    Edited by: user4362313 may 3, 2013 05:00

    Hi Bala,

    If I interpreted the statement correctly, then you are wanting fill the digits left of the decimal point to four characters, so 12.345 becomes 0012.345.

    The best way to achieve this is by using a processor of Expression (see the online help for details of full syntax). Assuming that the input attribute is called 'col1' then the following expression should lead to the desired result:

    substr ('000' | col1, indexof (col1, ".") - 1).

    Kind regards
    Nick

  • Need help in writing the SQL CASE or DECODE statement

    Hi experts,

    I need to write a SQL select order_num, cntry_cde, prod_id and Qty by joining order_num on PROD_ORDER and PROD_ORDER_TXT.

    Here is my sample data

    PROD ORDER_
    order_num Prod_id Qty cntry_cde
    100 US A1 5
    101 US 10 A2
    102 IN A3 4
    103 TO THE A4 9
    104. IN A5 3

    PROD ORDER_TXT_
    cntry_cde Prod_id order_num
    100 US A1
    101 US A2
    102 NZ A3
    103 TO THE A4
    A5 104

    Here's the requirement,

    (1) if the cntry_cde in PROD_ORDER is the same as cntry_cde in PROD_ORDER_TXT then select PROD_ORDER.cntry_cde (orders 100, 101, 103)
    (2) if they are different, choose PROD_ORDER_TXT (order 102, to THE NZ <>) country code
    (3) if they are different and PROD_ORDER_TXT.cntry_cde is null, I can't use it like cntry_cde in my report (order 104). It happenend just because of bad data to the source.
    I can't avoid it. Then just use the cntry_cde of PROD_ORDER

    Expected results
    100 US A1 5
    101 US 10 A2
    102 NZ A3 4 - changed in NZ
    103 TO THE A4 9
    104. IN A5 3 - IN retained as PROD_ORDER_TXT.cntry_cde is null


    instructions for creation and insertion of sample table are lower than

    create the table prod_order
    (number of order_num,
    cntry_cde CHAR (2),
    prod_id VARCHAR2 (6).
    number of quantity)

    create the table prod_order_txt
    (number of order_num,
    cntry_cde CHAR (2),
    prod_id VARCHAR2 (6))

    insert into prod_order values (100, 'WE', 'A1', 5);
    insert into prod_order values (101, 'WE', 'A2', 1);
    insert into prod_order values (102, ' to THE ', 'A3', 4);
    insert into prod_order values (103, ' to THE ', 'A4', 9);
    insert into prod_order values (104, 'IN', 'A5', 3);



    insert into prod_order_txt values (100, 'WE', 'A1');
    insert into prod_order_txt values (101, 'WE', 'A2');
    insert into prod_order_txt values (102, 'NZ', 'A3');
    insert into prod_order_txt values (103, ' to THE ', 'A4');
    insert into prod_order_txt values (104, 'A5', NULL);

    commit;

    Thank you for your help in advance

    Published by: manon March 28, 2012 13:39
  • function of case in which clause

    I insert the lines below into a cash_book table.

    PRJ_CODE PRJ_NAME
    ------------- -----------------------------------
    1203 SHIFA
    1203 SHIFA
    1203 SHIFA
    FATIMA 1202
    FATIMA 1202
    1203 SHIFA

    so if I select 1202 return code lines of code 1202, if I select 1203 then returns lines of code 1203, if I select other that the two values, and then returns all rows. How can I set in a query with the use (case or decode function) in where clause?

    Maybe something like this:

    create table test
    as
    select 1200 + rownum prj_code
      from dual
    connect by level <= 10;
    
    select * from test;
    
      PRJ_CODE
    ----------
          1201
          1202
          1203
          1204
          1205
          1206
          1207
          1208
          1209
          1210
    
    var v_PRJ_CODE number
    
    exec :v_PRJ_CODE := 1200;
    
    select *
      from test
     where PRJ_CODE = :v_PRJ_CODE
        or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
    
      PRJ_CODE
    ----------
          1201
          1202
          1203
          1204
          1205
          1206
          1207
          1208
          1209
          1210
    
    exec :v_PRJ_CODE := 1203;
    
    select *
      from test
     where PRJ_CODE = :v_PRJ_CODE
        or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
    
      PRJ_CODE
    ----------
          1203
    

    Concerning

    Martin

  • Nested to decode

    Hi All-
    I have a requirement where I need to convert a nested in a case statement decode statement here's the scenario


    CASE WHEN CD_FAM_01 = "Y" THEN ' N
    WHEN CD_FAM_02 = 'Y', AND THEN 'Y '.
    WHEN CD_FAM_03 = 'Y', AND THEN 'Y '.
    WHEN CD_FAM_04 = 'Y', AND THEN 'Y '.
    WHEN CD_FAM_05 = 'Y', AND THEN 'Y '.
    WHEN CD_FAM_01 IS SET TO NULL, AND CD_FAM_02 IS SET TO NULL AND CD_FAM_03 IS SET TO NULL AND CD_FAM_04 IS SET TO NULL AND CD_FAM_05 IS NULL THEN 'N.'
    WHEN CD_FAM_01 = ' no AND CD_FAM_02 = ' no AND CD_FAM_03 = 'N AND CD_FAM_04 =' N AND CD_FAM_05 = 'No THEN' don't END

    I am facing a moment torrid in the conversion of this instruction can help me here
    SQL> create table ca_test (cd_fam_01 VARCHAR2(1),cd_fam_02 VARCHAR2(1),cd_fam_03 VARCHAR2(1),cd_fam_04 VARCHAR2(1),cd_fam_05 VARCHAR2(1));
    
    Table created.
    
    Elapsed: 00:00:00.02
    SQL>
    SQL> insert into ca_test VALUES ('Y','Y','Y','Y','Y');
    
    1 row created.
    
    Elapsed: 00:00:00.02
    SQL> insert into ca_test VALUES ('N','Y','Y','Y','Y');
    
    1 row created.
    
    Elapsed: 00:00:00.02
    SQL> insert into ca_test VALUES ('N','N','Y','Y','Y');
    
    1 row created.
    
    Elapsed: 00:00:00.02
    SQL> insert into ca_test VALUES ('N','N','N','Y','Y');
    
    1 row created.
    
    Elapsed: 00:00:00.02
    SQL> insert into ca_test VALUES ('N','N','N','N','Y');
    
    1 row created.
    
    Elapsed: 00:00:00.01
    SQL> insert into ca_test VALUES ('N','N','N','N','N');
    
    1 row created.
    
    Elapsed: 00:00:00.01
    SQL> insert into ca_test VALUES (null,null,null,null,null);
    
    1 row created.
    
    Elapsed: 00:00:00.00
    SQL> insert into ca_test VALUES ('N','N','N',null,null);
    
    1 row created.
    
    Elapsed: 00:00:00.00
    SQL>
    SQL> SELECT
      2    cd_fam_01
      3   ,cd_fam_02
      4   ,cd_fam_03
      5   ,cd_fam_04
      6   ,cd_fam_05
      7   ,DECODE
      8      (CD_FAM_01,'Y','N'
      9                    ,DECODE
     10                      (CD_FAM_02,'Y','Y'
     11                                    ,DECODE
     12                                        (CD_FAM_03,'Y','Y'
     13                                                      ,DECODE
     14                                                          (CD_FAM_04,'Y','Y'
     15                                                                        ,DECODE
     16                                                                           (CD_FAM_05,'Y','Y'
     17                                                                                         ,DECODE
     18                                                                                            (COALESCE
     19                                                                                                 (CD_FAM_01
     20                                                                                                 ,CD_FAM_02
     21                                                                                                 ,CD_FAM_03
     22                                                                                                 ,CD_FAM_04
     23                                                                                                 ,CD_FAM_05),NULL,'N'
     24                                                                                                                 ,DECODE
     25                                                                                                                    (GREATEST(CD_FAM_01
     26                                                                                                                             ,CD_FAM_02
     27                                                                                                                             ,CD_FAM_03
     28                                                                                                                             ,CD_FAM_04
     29                                                                                                                             ,CD_FAM_05),LEAST(CD_FAM_01
     30                                                                                                                                              ,CD_FAM_02
     31                                                                                                                                              ,CD_FAM_03
     32                                                                                                                                              ,CD_FAM_04
     33                                                                                                                                              ,CD_FAM_05),DECODE(GREATEST
     34                                                                                                                                                                   (CD_FAM_01
     35                                                                                                                                                                   ,CD_FAM_02
     36                                                                                                                                                                   ,CD_FAM_03
     37                                                                                                                                                                   ,CD_FAM_04
     38                                                                                                                                                                   ,CD_FAM_05),'N','N'))))))))
     39    FROM ca_test
     40   /
    
    C C C C C D
    _ _ _ _ _ _
    Y Y Y Y Y N
    N Y Y Y Y Y
    N N Y Y Y Y
    N N N Y Y Y
    N N N N Y Y
    N N N N N N
              N
    N N N
    
    8 rows selected.
    
    Elapsed: 00:00:00.02
    

    Sounds good? Furthermore, why are you doing this? The case statement is surely preferable.

  • Decode with joker

    Hello

    I have a request to work like this:

    Select id, rank() over (PARTITION BY ORDER OF DECODER id (code, 'ETPL', 1, 'FEPL', 2, 'ETAR', 3, 'FEAR', 4, 'ETJO', 5, 'ETLE', 6, 'ETDP', 7, 8)) rn
    FROM MyTable

    But now I need to enter a wildcard here somehow. I was hoping it would work

    SELECT id, rank() over (PARTITION BY ORDER OF DECODER id (code, 'ETPL %', 1, 'FEPL %', 2, 'ETAR %', 3, 'FEAR', 4, 'ETJO %', 5, 'ETLE %', 6, 'ETDP %', 7, 8) rn
    FROM MyTable

    This however isn't. Any ideas on how to work around this problem?

    Hello

    DavidNils wrote:
    ... But now I need to enter a wildcard here somehow. I was hoping it would work

    SELECT id, rank() over (PARTITION BY ORDER OF DECODER id (code, 'ETPL %', 1, 'FEPL %', 2, 'ETAR %', 3, 'FEAR', 4, 'ETJO %', 5, 'ETLE %', 6, 'ETDP %', 7, 8) rn
    FROM MyTable

    '%' has special meaning only when used on the right side of a LIKE operator. It has no special meaning to DECODE.

    This however isn't. Any ideas on how to work around this problem?

    The answer to «How can I do this with DECODE...» "is"do not DECODE. Instead use CASES. "DECODE is good for simple comparisons. If you have to ask, then it is not very simple.
    In fact, Etbin gave a good solution using DECODE, which is based on the fact that you are still interested in the first 4 characters of the column in code. If you were always interested in the first 4 characters, then you might do something like this:

    ... ORDER BY  CASE
                WHEN  code LIKE 'ETPL%'  THEN  1
                WHEN  code LIKE 'FOO%'   THEN  2
                WHEN  code LIKE '%BAR'   THEN  3
                                ELSE  4
               END
    
  • Decode the help function

    Hello

    I'm new to the development of Oracle.

    MY requirement:

    I need to fill a column "ISMSG" by YES / NO based on the following condition

    When the code = the of ' or 'O'... the 'ISMSG' column should display any other YES no.

    That is, output should be like

    CODE ISMSG

    A NO
    S YES
    S YES
    O YES

    My code for the Decode function:

    CASE
    WHEN s = c.code ' THEN decode (c.code, the of ',' YES, 'NO')
    WHEN c.code = 'o' THEN decode (c.code, 'O', 'YES', 'NO')
    END ISMSG

    My code is correct? If Yes is the best way to do it?
    If this is not the case, correct the code.

    Is there an effective way to do it?

    Thanks in advance.

    Hello

    You can use CASES or DECODE for this; There is no need to use both.
    With the help of CASE:

    SELECT  c.code
    ,     CASE
             WHEN  c.code  IN  ('S', '0')  THEN  'YES'
                                               ELSE  'NO'
         END     AS ismsg
    FROM    table_x   c;
    

    Using DECODE:

    SELECT  c.code
    ,     DECODE ( c.code
                , 'S'      , 'YES'
                , '0'      , 'YES'
                              'NO'
                )          AS ismsg
    FROM    table_x   c;
    

    I suggest that you forget to DECODE and use always the CASE, at least while you are beginner.

    CASE may do everything they can to DECODE. There is a little bit simple, situations where DECODE is a little shorter than the CASE and therefore a bit clearer, but only a little and, as I said, these are just simple situations, and CASE is clear enough in them.
    DECODE is never much shorter or clearer than the CASE. The reverse is not true: there are many situations where the CASE is much, much shorter and lighter than DECODE.

  • case where the condition

    Hello
    I want to use the case (or decode etc.) in which a part of sql.
    I want to find the number of rows depending on where the conditions.
    For example, I have a table b, d, e, p and s are fields of this table.
    If the value of the field b is 1 then my condition clause that will be value fields d, e value fields
    If the value of the fields of b is 2 then my condition clause where the declaration will be p field value < s value fields.


    Select count (*) of A
    where
    (if b = 1 then) d, e
    (if b = 2 then) p < s

    How can I achieve this?
    where (b = 1 and d		   

Maybe you are looking for

  • IPhone 5 c Activation lock by ex-employee of the company

    I put a case with assistance from Apple to get an iPhone 5 irreversible c and it takes 3 days already, but gave us a receipt to show proof of purchase.  I'm quite impatient with the time it takes to get there.  Is there a foolproof way to keep employ

  • Tecra A8 - VAP download password required

    Hello I have a Tecra A8 and need to download VAP, the only problem is that I keep getting request user name and password, but when I enter these details that they are not accepted.I would really appreciate ideas especially from someone at Toshiba. Th

  • Laptop frozen on the login page

    HelloAnyone got any ideas before considering shop? My Toshiba laptop has frozen on the main login page. The cursor blinks but the mouse is frozen and none of the keys work so I can't even shift tab to open a session. The last time that I used, it was

  • Is it possible to recover (identify) the product code for my license, XP operating system. I can read 22 of 25 characters.

    My laptop Toshiba "atom" has XP OEM operating system. The hard disk of the computer has lost the OEM operating system.   The sticker on the back with the product key is scratched, obscuring three of 25 characters.  It seems that these three character

  • Cannot install mercurial 3.2.3

    Hello I installed the prerequisite python 2.7 I disabled DEP on windows server 2008 I run the installer in compatibility mode. In the application log, I see the message given Log name: ApplicationSource: Application errorDate: 20/02/2015 03:03:38Even