Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Posts
    227

    Unanswered: 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

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: insert into table

    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;

Posting Permissions

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