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  >  Tech FAQs  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 53 of 156    Print  
Hi Guys,
i have an interview question. can anyone help me reg this.
i have a table called "phone" and filed as "phone number" and table have values like 2489078905,2345678909
now i want the result as
(248)9078905,(234)5678909 into another table called phone2.


  
Total Answers and Comments: 7 Last Update: March 04, 2007     Asked by: dev 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 23, 2006 12:08:12   #1  
satish        

RE: Hi Guys,i have an interview question. can an...

insert into  phone2 (phoneno)

select '('+ left('phone number',3)+')'+right('phone number',7) from phone

Another simple example is....execute this directly and see the result.

select '('+ left('2489078905',3)+')'+right('2489078905',7)


 
Is this answer useful? Yes | No
October 23, 2006 13:21:23   #2  
Arun        

RE: Hi Guys,i have an interview question. can an...

Answer :

insert into phone2 (select '('||substr(phoneno,1,3)||')'||substr(phoneno,4)  from phone)


 
Is this answer useful? Yes | No
October 24, 2006 03:33:30   #3  
Murugan        

RE: Hi Guys,i have an interview question. can an...

Hi,

     We need to use PL/SQL with explicity cursors. The following anonyms block will work,

declare
ph_num phone.phone_number%type;
ph_num_1 phone2.phone_number%type;
cursor ph_num_2 is select phone_number from phone;
begin
open ph_num_2;
loop
fetch ph_num_2 into ph_num;
exit when ph_num_2%notfound;
ph_num_1 := '(' || substr(ph_num,1,3) || ')' || substr(ph_num,4,10);
insert into phone2(phone_number) values(ph_num_1);
end loop;
close ph_num_2;
end;
/

one thing is important, column phone_number in phone2 should be in varchar2 not in number.

Regards,

M.Murugan


 
Is this answer useful? Yes | No
October 24, 2006 15:23:05   #4  
dev        

RE: Hi Guys,i have an interview question. can an...

Hi All,

Thank u for ur responses and i have one more adjustment in the question like:

Those phone numbers are present in one file not in table. table is also there but it is empty.

File Name is:Data

in this file , we have phone no's like 2489078905,2345678909 and i have an empty table phone with phoneno as a field. i want the results in Phoen2 table with format like this,(248)9078905,(234)5678909.


 
Is this answer useful? Yes | No
October 24, 2006 16:22:08   #5  
dev        

RE: Hi Guys,i have an interview question. can an...

Hi all,

thank u for ur answers.and i have an adgustment in this question.

actually data is not present in a table, it's there in some file.say, "Data" contains information: 2489078905,2345678909 and so on...
and table is also there phone with phoneno as a field but table is empty.now i want the result into table2.

got it, Right!

Let me know if u have any questions.

thanks.

dev


 
Is this answer useful? Yes | No
October 30, 2006 07:26:38   #6  
Swapna Gentyala Member Since: October 2006   Contribution: 10    

RE: Hi Guys,i have an interview question. can an...
Hi you can try this query to update the tableupdate phone set phone2 = "(" & left(phone.phonenumber,3) & ")" & right(phone.phonenumber,7)
 
Is this answer useful? Yes | No
March 04, 2007 11:35:46   #7  
ss_peri Member Since: March 2007   Contribution: 2    

RE: Hi Guys,i have an interview question. can an...
Hi,
You can use the concept of External Tables. These external tables reads the DATA/FLAT File. And now you can read the External table as an ordinary oracle table, and do the data manipulation, and insert into into phone2 table.

 
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