1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

What's wrong with my decode query

Discussion in 'SQL PL/SQL' started by mukulverma2408, Nov 8, 2015.

  1. mukulverma2408

    mukulverma2408 Active Member

    Messages:
    38
    Likes Received:
    1
    Trophy Points:
    90
    Location:
    New delhi
    Hi Experts,

    This seems to be pretty simple but I don't know what am I doing wrong as I am not getting correct output.
    Code (Text):

    Name     sex       age
      X          M        28
      Y          F         26
      Z          M        22
      T          F         18
     
    I am trying to identify the male and female passenger using below query :
    Code (Text):

    SELECT DECODE(SEX,'M',1,0) FROM FLIGHT;
     
    Below is the output i am getting which is not correct :
    Code (Text):

    0
    0
    0
    0
     
    What am i doing wrong?
     
  2. jagadekara

    jagadekara Forum Guru

    Messages:
    1,126
    Likes Received:
    145
    Trophy Points:
    1,805
    Location:
    Pulivendula
    Hi,

    Your query looks correct. Provide table structure, creation scripts and insert scripts.

    We will look into that
     
  3. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,347
    Likes Received:
    348
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    You have a space after the M in the sex column, I'll wager:

    SQL> SELECT DECODE(SEX,'M',1,0) FROM FLIGHT;

    DECODE(SEX,'M',1,0)
    -------------------
    0
    1

    SQL> select * From flight;

    NAME SE AGE
    ---------------------------------------- -- ----------
    Lorpa F 33
    Lorpa M 33

    SQL> update flight set sex = 'M ' where sex = 'M';

    1 row updated.

    SQL> commit;

    Commit complete.

    SQL> select * From flight;

    NAME SE AGE
    ---------------------------------------- -- ----------
    Lorpa F 33
    Lorpa M 33

    SQL> SELECT DECODE(SEX,'M',1,0) FROM FLIGHT;

    DECODE(SEX,'M',1,0)
    -------------------
    0
    0

    SQL>
     
    mukulverma2408 likes this.
  4. mukulverma2408

    mukulverma2408 Active Member

    Messages:
    38
    Likes Received:
    1
    Trophy Points:
    90
    Location:
    New delhi
    Thanks, it's now fine.