If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > insert into table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-26-03, 09:12
raf raf is offline
Registered User
 
Join Date: Jul 2002
Posts: 214
insert into table

hi
I've a table A

ID NUM NAME IP
1 10 TOM 500
2 20 SAM 510
3 30 TOM 630
4 40 SAM 800

This table has more 1000 same records

I'd like insert into A same records change just the name:

ID NUM NAME IP
1 10 TOM 500
1 10 SAM 500
2 20 SAM 510
2 20 TOM 510
3 30 TOM 630
3 30 SAM 630
4 40 SAM 800
4 40 TOM 800

How can I create a script for this??

Thanks
Raf
Reply With Quote
  #2 (permalink)  
Old 03-26-03, 09:44
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: insert into table

Quote:
Originally posted by raf
hi
I've a table A

ID NUM NAME IP
1 10 TOM 500
2 20 SAM 510
3 30 TOM 630
4 40 SAM 800

This table has more 1000 same records

I'd like insert into A same records change just the name:

ID NUM NAME IP
1 10 TOM 500
1 10 SAM 500
2 20 SAM 510
2 20 TOM 510
3 30 TOM 630
3 30 SAM 630
4 40 SAM 800
4 40 TOM 800

How can I create a script for this??

Thanks
Raf
Are there just those 2 names TOM and SAM? If so, you can use a DECODE or CASE:

INSERT INTO a
SELECT id, num, DECODE(name.'TOM','SAM','TOM'), ip
FROM a;

INSERT INTO a
SELECT id, num, CASE WHEN name = 'TOM' THEN 'SAM' ELSE 'TOM' END, ip
FROM a;
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On