Results 1 to 5 of 5

Thread: Decode

  1. #1
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Decode

    SELECT decode(TO_CHAR(TO_DATE('11-JUN-00','DD-MON-YY'),'MONTH') ,
    'FEBRUARY','02',
    'JUNE', '06',
    'APRIL', '04',
    'JULY', '07',
    'LAST OPTION' ) FROM DUAL
    The expected output of the above query is 06, But it is displaying LAST OPTION. What is the wrong with above query?


  2. #2
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: Decode

    Use This
    select DECODE(to_char(to_date('11-JUN-00','DD-MON-YY'),'MON'),'FEB','02','JUN','06','APR','04','JULY','07','LAST OPTION') FROM DUAL


  3. #3
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Decode

    That is ok.
    What it wrong with first query?
    SELECT TO_CHAR(TO_DATE('11-JUN-00','DD-MON-YY'),'MONTH') from dual returns JUNE.


  4. #4
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: Decode

    use this
    SELECT DECODE(rtrim(TO_CHAR(TO_DATE('11-JUN-00','DD-MON-YY'),'MONTH')),
    'FEBRUARY','02',
    'JUNE','06',
    'APRIL','04',
    'JULY','07','LAST OPTION') FROM DUAL


  5. #5
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Decode

    Quote Originally Posted by krishnaindia2007 View Post
    That is ok.
    What it wrong with first query?
    SELECT TO_CHAR(TO_DATE('11-JUN-00','DD-MON-YY'),'MONTH') from dual returns JUNE.
    You need to do as suggested in the previous post because after conversion MONTH retrives month name with length of 9, padded with space to the right side because maximum month name is SEPTEMBER. The same rule applies for name of days also max being WEDNESDAY.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact