+ Reply to Thread
Results 1 to 6 of 6

Thread: Sql - There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F with

  1. #1
    Senior Member
    Join Date
    Jan 2007
    Age
    32
    Posts
    283
    Rep Power
    9

    Sql - There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F with

    Sql - There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F with M and M with F?


  2. #2
    Super Moderator sk_kireeti's Avatar
    Join Date
    Feb 2006
    Posts
    2,279
    Rep Power
    65

    Re: Sql - There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F w

    Not sure if this query works or not.... assuming name of the table is emp.

    update emp set GENDER = decode(GENDER,'M','F','F','M');
    or
    update emp set GENDER = decode(GENDER,'M','F','M');

    Thanks,
    Krishna

  3. #3
    Junior Member
    Join Date
    Jan 2007
    Posts
    29
    Rep Power
    7

    Re: Sql - There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F w

    The other alternative is
    update emp set GENDER = 'KK' WHERE GENDER ='M'
    update emp set GENDER = 'M' WHERE GENDER='F'
    update emp set GENDER = 'F' WHERE GENDER ='KK'

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    4
    Rep Power
    4

    Re: Sql - There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F w

    update emp_vas1 x
    set x.gender = (
    select nvl(replace(decode (gender, 'M', '*'),'*', 'F'
    ),'M') /*,emp_id, emp_name*/
    from emp_vas1 x2
    where x.emp_id = x2.emp_id
    )

    Pls correct me if any mistakes

  5. #5
    Member
    Join Date
    Oct 2011
    Posts
    58
    Rep Power
    2

    Re: Sql - There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F w

    UPDATE EMP
    SET GENDER=case gender when 'M' then 'F' when 'F' then 'M' END;

  6. #6
    Member
    Join Date
    Oct 2011
    Posts
    58
    Rep Power
    2

    Re: Sql - There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F w

    This was a check constraint , so it wont accept anything except M & F.
    Last edited by samsi_143; 13-10-11 at 09:36 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Content Relevant URLs by vBSEO 3.5.1 PL1