GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 166 of 168    Print  
Data Conversion
Have 2 table Emp1 (Column Name: Ename), 2nd table Emp2 (Column Name: First and Column Name: Last

Table Name :Emp1
EName
Hunt, Michael
Graham, Smith
Nelson, Ryan


Table Name: Emp2
First Last
Michael Hunt
Smith Graham
Ryan Nelson

Need to write a SQL query to convert the data from Emp1 to Emp2 in this way.
Can any body help me.

Thanks




  
Total Answers and Comments: 3 Last Update: July 03, 2008     Asked by: ssq1999 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 20, 2008 11:11:29   #1  
subrat_rout Member Since: October 2005   Contribution: 1    

RE: Data Conversion
I guess by using the help of INSTR and SUBSTR, we can break the one column(ename) data to two columns first and last column data.
 
Is this answer useful? Yes | No
June 25, 2008 22:31:29   #2  
astaputra Member Since: June 2008   Contribution: 7    

RE: Data Conversion

select SUBSTR('Hunt, Michael',1,INSTR('Hunt, Michael',',')-1) LAST_NAME,SUBSTR('Hunt, Michael',INSTR('Hunt, Michael',',')+1) FIRST_NAME from dual

Here is the example how to use and accordingly change the query and insert into another table.

Thks...


 
Is this answer useful? Yes | No
July 03, 2008 10:19:15   #3  
sam2233 Member Since: July 2008   Contribution: 1    

RE: Data Conversion
 create table emp2 as(select Substr(ename,1,instr(ename,',')-1) as last,
   substr(ename,instr(ename,',')+1,length(ename)) as first  from emp1)

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape