Decode Statement Inside the Case statement

Can we use Decode Statement inside a CASE Statement as show below --
It is giving an error -- Is the a better way to write with out any error
create or replace
function test (a varchar2) RETURN VARCHAR2
is
m varchar2(20);
begin
m :=
CASE
WHEN a IN (
'1009' -- (soon obsolete)
,'1010'
,'1019'
,'1051'
,'XGP'
,'XSC')
THEN (SELECT DECODE(v_lef_cd,'NAM','71','GLB','99','01') into m FROM DUAL)
-- ) THEN '01' -- UNITED STATES OF AMERICA
WHEN a IN (
'1069' -- South Africa
,'SAO' -- South Africa
,'SA' -- South Africa
) THEN '26' -- South Africa
ELSE NULL
END;
return m;
end;

Hi,
You can only use DECODE in SQL statements.
Your SELECT DECODE (...) INTO statement would work anywhere a PL/SQL statement is allowed; but PL/SQL statements are not allowed within CASE expressions.
Remember, the expression that comes after THEN in a CASE expression must be a single value.
I would write a function like this using IF ... ELSIF statements. It's a little more typing than CASE, but a lot easier to code, test and maintain.
If you want to use CASE, here's one way:
...     m := CASE
          WHEN  a  IN ('1069', 'SAO', 'SA')
               THEN  '26'     -- South Africa
          WHEN  a  NOT IN ('1009', '1019', '1051', 'XGP', 'XSC')
          OR    a  IS NULL
               THEN  NULL
          WHEN  v_lef_cd = 'NAM'
               THEN  '71'
          WHEN  v_lef_cd = 'GLB'
               THEN  '99'
               ELSE  '01'     -- USA
          END;This assumes that you have a variable v_lef_cd defined.
If you want, you can nest CASE expressions, like this:
...     m := CASE
          WHEN  a  IN ('1069', 'SAO', 'SA')
               THEN  '26'     -- South Africa
          WHEN  a  IN ('1009', '1019', '1051', 'XGP', 'XSC')
               THEN  CASE  v_lef_cd
                      WHEN  'NAM'
                         THEN  '71'
                      WHEN  'GLB'
                         THEN  '99'
                         ELSE  '01'     -- USA
                     END
          END;Always format your code, so you can see where the CASE expressions and each of the WHEN clauses begin and end.
When posting formatted text on this site, type these 6 characters:
(all small letters, inside curly brackets) before and after sections of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • My screen moved inside the case. Help!

    I recently had to ship my iMac G5 via UPS. I used all of the original packaging so I figured it would be ok. Apparently it was jarred pretty badly, because when I put it on my desk I noticed that the screen had shifted inside the computer. The right side dropped about a quarter inch. Is this something that I should attempt to fix myself or do I dare touch it? Any thoughts?

    If it's still under warranty, then you should take it in for service to keep the rest of your warranty in-tact.
    I imagine they'll charge you since it was an impact that caused it.
    But, if you attempt to adjust it yourself, they may void the rest of your warranty.
    Adjusting the screen is going to require removing everything from the first two iMac G5 versions. And, on the iMac G5 "iSight" version, you cannot open it yourself anyway.
    Of course, you could always bounce it on it's head the other direction
    But, I wouldn't recommend that.
    Personally, I'd pay the service charge for adjustment if it's under warranty.
    If it's not the iSight version, then it can be done yourself. But, there are lots, and lots of connections that you need to make sure to get back in-place properly. I've watched them disassemble and reassemble two of mine to get to the LCD screen. So, I know it's a big job.
    It wouldn't intimidate me. But, I used to build and design computers (and even electrical components) for a living.
    But, for someone who has not done this professionally, I would enter the project cautiously. You can do it. But, you need to pay very close attention to how you dismantle it and get it reassembled exactly the same way.
    Hope this helps.

  • MacBook Pro 13-Inch (Mid-2014): When opening lid I hear a "zipping" sound coming from somewhere inside the case. Is this the fan catching on something or some other component initializing? Or just normal?

    First time MacBook Pro user and being the OSD guy that I am with new electronics I wanted to ask if I should be hearing this sound when I open the lid, I guess by closing the computer goes to sleep, and when it wakes I hear a faint but noticeable "zipping" sound for a quick second or two. Is this just the fan starting back up? Thanks!

    I should note I believe the noise is coming from the right side of the trackpad.

  • What does a red outline inside a Case Statement mean?

    I'm developing some code, and opened an existing VI that has a Queued Message Handler inside it.  One Message Case ("Shutdown") has a thin red outline on the inner border of the Case "box" -- what does this mean, where did it come from, and what should I do about it (including "How do I get rid of it?")?.
    This code was developed in LabVIEW 2012.  I'm pretty sure I haven't seen this previously.  I should probably mention that I tested this VI, it quit unexpectedly (possibly by throwing an error somewhere), and I'm looking at the "saved VI".

    Thanks to GerdW and tst for the rapid responses.  Some observations (before this "goes away").  First, right-clicking on a blank space inside the Case Statement brings up the Function palette (oops -- I didn't read your reply carefully -- you said to click the Breakpoint Tool, just a sec -- yep, that does it, but I don't think I've ever used the Breakpoint tool, rather I manage Breakpoints by right-clicking on wires and going from there).  Second, I used the Breakpoint Tool to put the breakpoint back on this Case, and brought up the Breakpoint Manager by right-clicking the Error line and choosing Breakpoint Manager.  Sure enough, it popped up a notice saying there was one breakpoint set on a Diagram object.  When I cleared it, it cleared the top left red border and about 15% of the left side border (at the top), but most of the red border remained until I clicked away from this case then clicked back.
    Thanks for the explanation.  Where is this noted?  I did a search for Case Statement, didn't see it.  I suppose if I already knew it was a Breakpoint notification, I could have found it under Breakpoint Help ... (nothing like Knowing the Answer to help you Find the Answer).

  • How to increase the performance with the case structure?

    Hiii, All
                I want to stop the looping into my vi, which is occuring because of Case structure, as i ve shown in the figure, i am checking for the trigger, either it is Manual or it is Auto, if auto i am going inside the case and checking the loop of either Auto trigger is for Analog values or for digital values, if it is for analog valus, i am checking the set point that, either P.V. has cross the setpoint or not? if it is then i am starting to write the file and the control comes out again to check the Start trigger again, either it is Auto or manual? and because of these contonuous loops inside the while loop, my other while loops inside the vi, decrease the performance mean they are slowing down also with the current while loop, so i think solution is to stopping these nested loops, but what should i do to stop these nested loops? please suggest something.
    Thanks in Advance,
    Nishant
    Attachments:
    Performance.jpg ‏169 KB

    You can consider multithreading the single loop and using a synchronization resource to communicate between threads.  You should also consider cutting down on the global variable dependancies which makes the code hard to follow.
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • TS3495 My recent blu ray purchase did not come with a digital copy disc as others have in the past, and no place in the case for one to be either, just came with instructions, so now what?

    My new blu ray disc did not come with a seperate digital download dis, now was there even a place for one inside the case, it came with instructions of how to install I tunes, then magically I would be prompted to enter the promo code and have it, no such luck, so now what?

    Have you actually followed the instructions?
    Did you enter the promo code?
    If you did, were there any error messages?

  • Firewire INSIDE the computer? WHY?

    I have noticed quite a few PCI cards have Firewire and/or USB ports that will be inside the case of the computer.
    This was also the case on some G4's
    WHY?
    What could this be used for? What could I use the internal port for?
    Thanks
    Pat

    I have wondered what sort of Firewire or USB devices people would want inside their computer cases, but that is what those ports are for. We have some cards of that type but have never used the internal ports.
    On the other hand, I have installed SATA cards that have internal and external ports. These allow installing a couple of extra hard drives in the case plus several external drives. This not only provides practically unlimited storage, but also allows keeping backup sets of drives in a secure seperate location, such as a bank. We had a fire in 1991 that totally altered my philosophy regarding backups. You can never have too many.
    Webb
    G5 1.8/A , iMac600, 9600/G4, Older Macs/OS 7-9   Mac OS X (10.4.3)   3GB RAM, 2 x Raptor 74, 4 x 300GB Maxtor ext SATA, FW800 & 400 drives

  • How to convert the compund case statement into decode statement

    (CASE
    WHEN FRCST = 0 AND SALE = 0 THEN 'No transaction '
    WHEN FRCST = 0 AND SALE <>0 THEN 'Sale ag. Nil Forecast : '||SALE||' Kgs'
    WHEN FRCST<> 0 AND SALE = 0 THEN 'No Sale ag. Forecast : '||FRCST||' Kgs'
    WHEN FRCST<>0 AND SALE<>0 AND DIFF=0 THEN 'No Variance'
    ELSE TO_CHAR(ROUND((DIFF/FRCST),2))||'%'
    END)VARIANCE
    How to convert this tatement to decode statement ?
    Yogesh

    Decode(FRCST,0,DECODE(SALE,0,'nO TRANSACTION','SALE AGAINST NIL FORECAST'),DECODE(SALE,0,'NO SALE AGAINST FORECAST',
    DECODE(|SALE-FORECAST|,0,'NO VARIANCE',TO_CHAR(ROUND((DIFF/FRCST),2))||'%')))As per me whole case can be replaced by above decode

  • Owb 9 Case / decode statement

    Hi all,
    We using owb 9. Case staments can not be used in this version of owb. Could be done with a decode statement.
    But decode statements requires a static value to result a value.
    In my statement i want to use less the or greater the staments. How can i do that  in a decode.
    I found out a decode does also not work. anyone a idea. except for using a view as source
    so a example what i want:
    a < 180 then 1
    a between 180 and 200 then 2
    a > 200 then 3
    tnx in advanced
    Edited by: user565199 on 22-jun-2011 3:59

    Hi ,
    Did you try with case statement, if you try with case what error your getting?
    Thanks,
    Praveen

  • How do I use the CASE statement  in the where clause?

    Hello Everyone,
    I have 2 queries that do what I need to do but I am trying to learn how to use the CASE statement.
    I have tried to combine these 2 into one query using a case statement but don't get the results I need.
    Could use some help on how to use the case syntax to get the results needed.
    thanks a lot
    select segment_name,
    product_type,
    count (distinct account_id)
    FROM NL_ACCT
    where
    ind = 'N'
    and
    EM_ind = 'N'
    and product_type in ('TAX','PAY')
    and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 60)
    GROUP BY 1,2
    order by product_type
    select segment_name,
    product_type,
    count (distinct account_id)
    FROM NL_ACCT
    where
    ind = 'N'
    and
    EM_ind = 'N'
    and product_type not in ('TAX','PAY')
    and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 30)
    group by 1,2
    order by product_type

    Something like:
    SELECT segment_name, product_type,
           SUM(CASE WHEN account_id IN ('TAX','PAY') and
                         acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60 THEN 1
                    ELSE 0 END) tax_pay,
           SUM(CASE WHEN account_id NOT IN ('TAX','PAY') and
                         acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 30 THEN 1
                    ELSE 0 END) not_tax_pay
    FROM NL_ACCT
    WHERE ind = 'N' and
          em_ind = 'N' and
          acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60
    GROUP BY segment_name, product_type
    ORDER BY product_typeNote: You cannor GROUP BY 1,2, you need to explicitly name the columns to group by.
    HTH
    John

  • Assigning value inside a case statement

    Hi friends
    iam using the below code and can any one tell me why even after assigning the value in the case statement it coming out of it.
    code
       data :
          p1(1) type n.
          case p1.
            when '0'.
              write 'sunday'.
            p1 = 1.
            when '1'.
              write 'monday'.
             p1 = 2.
            when others.
              write 'invalid day'.
         endcase.
    output.
       sunday
    can any one tell me why it is coming out of the case statement even iam assigning p1 = 1

    This is happening b'cause u have already in the when clause where u r setting the value of the variable that is controlling ur case..endcase statement.To meet ur requirement u need to trigger the case..endcase statement again as shown below:
    data :
    p1(1) type n.
    do 3 times.
    case p1.
    when '0'.
    write 'sunday'.
    p1 = 1.
    when '1'.
    write 'monday'.
    p1 = 2.
    when others.
    write 'invalid day'.
    endcase.
    enddo.

  • Help! format of decode statements with between or signs ?

    Looking for an example of a decode statement with either a between/and or < > signs in the comparison field.
    I have tried several variations, but none seem to work. Any help would be appreciated.
    Here's a sample that doesn't work.
    Select course_no, section_no, capacity, decode(capacity, (capacity < 12), Less than 12, (capacity between 13 and 15), 13-15, More than 15) from section;
    Thanks in advance

    Hi,
    There is a limitation to the Case function, as it cannot be used in the PL/SQL (atleast upto Oracle 8i). Therefore, the only option left is Decode.
    If you have to compare the values like capacity < 12 then display Less than 12. You can write it using combination of other functions.
    For e.g. follow the steps below:-
    1)If you deduct 12 from capacity : (capacity-12) [it will give result as +ve, 0 or -ve.]
    2)If you have to narrow down the values to above three options, use function sign:
    SIGN(capacity-12) [will result into +1, 0 or -1]
    3)Then compare the values using Decode:
    DECODE(SIGN(capacity-12),-1,Less than 12,Greater than or equal to 12)
    The Decode can be used inside Decode(nested Decode) in above steps to compare more than one values (range between) to get the desired result. Hope have made it clear enough. If not, please let me know.
    Cheers.
    Yogesh D.

  • How to determine INT and FLOAT in a DECODE statement

    Can anyone help me with the following problem:
    I have a column defined as a NUMBER(15,4). I am trying to determine the java type using the getScale() method in ResultSetMetaData. When the scale is greater than 0, then it is an float, else it is an int. In this case, the getScale() method should return 4. However, when querying with a DECODE statement on the NUMBER(15,4) field, the getScale() method always returns 0 and the value is therefore converted to an int. Anyone knows how to solve this problem?
    Thanks

    Alcides,
    Oracle NUMBER data type is mapped to "java.math.BigDecimal" class.
    You will find more information in the JDBC Developer's Guide and Reference which is part of the Oracle documentation and available from:
    http://www.oracle.com/technology/documentation/index.html
    Good Luck,
    Avi.

  • Problem with Decode statement

    Hi
    I am trying to achieve the following in my report:
    If an employee has a surname of . (dot) or a first name of . (dot), the report should not display a dot. An employee's name is made up of surname, first name and middle name which should all be concatenated together. To try to achieve this, I have the following statement in my report:
    decode(e.Surname, '.', ( LTRIM(RTRIM((INITCAP(e.FIRST_NAME)))||' '||INITCAP(e.MIDDLE_NAME)) ) ,
    e.FIRST_NAME, '.', ( LTRIM(RTRIM((INITCAP(e.Surname)))||' '||INITCAP(e.MIDDLE_NAME)) ) ,
    ( LTRIM(RTRIM((INITCAP(e.SURNAME )))||', '||INITCAP(e.FIRST_NAME)||' '||INITCAP(e.MIDDLE_NAME)) ) ) as emp_name
    FROM Employee e
    Problem: The above statement is only working for those employees with surname of . (dot). It's not working for first names of dot. How can I use the decode statement OR is there any other way of doing it without using the CASE statement?
    It seems my decode statement doesn't work with 2 different fields (surname, firstname) being tested within one decode statement.Thanks.

    Thank you so much InoL . I have used the ltrim with Replace but now have a new problem.
    Because I am joining Surname, First name and middle name together and put a comma after the Surname, the name now appears as follows:
    , Maria Ane (if Surname is a dot)
    Boiler, (if first name is a dot)
    I would like to get rid of a comma and only have comma when surname or first name does not have a dot, i.e. for those people with full names e.g. Blake, Anna Marie.
    InoL, how can I achieve this? Thanks.

  • DECODE statement

    please can someone kindly code the following line of SQL using the DECODE statement:
    case when Student_Status in ('Registered','Repeat','Referral', 'Deferral')and GRADE <> 'MISSING' then EXAM1_RESULT else Null end as Valid_EX1
    It will be most appreciated.
    Thanks

    user607929 wrote:
    I'm ever so sorry, I keep sending the same Wrong thing.
    This is what i need translated to DECODE:
    "case when
    Student_Status in ('Registered','Repeat','Referral', 'Deferral') and GRADE is not 'MISSING'
    then EXAM1_RESULT
    else Null end as Valid_EX1"
    the issue is with the NOT 'MISSING' string.Check this. Just re-arrange of Andrés Muchiut post
    DECODE (
    STUDENT_STATUS
    ,'Registered',DECODE(GRADE,'MISSING',null,EXAM1_RESULT)
    ,'Repeat' ,DECODE(GRADE,'MISSING',null,EXAM1_RESULT)
    ,'Referral' ,DECODE(GRADE,'MISSING',null,EXAM1_RESULT)
    ,'Deferral' ,DECODE(GRADE,'MISSING',null,EXAM1_RESULT)
    , null) Valid_EX1Hope this may help you...

Maybe you are looking for