GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Database  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 42 of 139    Print  
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?
CREATE TABLE temp(
eno NUMBER CONSTRAINTS pk_eno PRIMARY KEY,
gender CHAR(1) CHECK (gender IN( 'M','F')));

INSERT INTO temp VALUES ('01','M');
INSERT INTO temp VALUES ('02','M');
INSERT INTO temp VALUES ('03','F');
INSERT INTO temp VALUES ('04','M');
INSERT INTO temp VALUES ('05','M');
INSERT INTO temp VALUES ('06','F');
INSERT INTO temp VALUES ('07','M');
INSERT INTO temp VALUES ('08','F');

COMMIT;


UPDATE temp SET gender =DECODE(gender,'M','F','F','M');

commit;



  
Total Answers and Comments: 3 Last Update: November 08, 2007     Asked by: SaratKumar 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Elena
 
update <table name>  set gender=(case gender when 'F' then 'M' when 'M' then 'F' end)

Above answer was rated as good by the following members:
goksn
November 07, 2005 06:51:04   #1  
kautilya        

RE: There is a eno & gender in a table. Eno has primar...

update <TableName> set gender

case where gender 'F' Then 'M'

where gender 'M' Then 'F'


 
Is this answer useful? Yes | No
February 27, 2007 23:49:52   #2  
marutalksin Member Since: February 2007   Contribution: 12    

RE: There is a Eno & gender in a table. Eno has primar...
we can swap like

a b;
b c
c a;

where a f or F
b m or M
c temp
or

if gender 'F'
then convert gender 'm'
else if gender 'M'
then convert gender 'f'
// if we want only in caps
else if gender 'f'
then convert gender 'M'
else if gender 'm'
then convert gender 'F'

 
Is this answer useful? Yes | No
November 08, 2007 01:04:58   #3  
Elena        

RE: There is a Eno & gender in a table. Eno has primar...
update <table name> set gender (case gender when 'F' then 'M' when 'M' then 'F' end)
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape