Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 761175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:48:24+00:00 2026-05-14T15:48:24+00:00

I need to copy some data from one table to another in Oracle, while

  • 0

I need to copy some data from one table to another in Oracle, while generating incremental values for a numeric column in the new table. This is a once-only exercise with a trivial number of rows (100).

I have an adequate solution to this problem but I’m curious to know if there is a more elegant way.

I’m doing it with a temporary sequence, like so:

CREATE SEQUENCE temp_seq
    START WITH 1;

INSERT INTO new_table (new_col, copied_col1, copied_col2)
    SELECT temp_seq.NEXTVAL, o.*
      FROM (SELECT old_col1, old_col2
              FROM old_table,
          ORDER BY old_col1) o;

DROP SEQUENCE temp_seq;

Is there way to do with without creating the sequence or any other temporary object? Specifically, can this be done with a self-contained INSERT SELECT statement?

Please consider a trigger to be a non-option.

MORE INFO: I would like to control the order that the new rows are inserted, and it won’t be the same order they were created in the old table (note I’ve added the ORDER BY clause above). But I still want my new sequential column to start from 1.

There are similar questions, but I believe the specifics of my question are original to SO.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:48:25+00:00Added an answer on May 14, 2026 at 3:48 pm

    You can use ROWNUM. This pseudo-column numbers the rows in your result:

    Insert Into new_table (new_col, copied_col1, copied_col2)
        Select Rownum, old_col1, old_col2
        From old_table;
    

    If you want your records to be sorted, you need to use a sub-query:

    Insert Into new_table (new_col, copied_col1, copied_col2)
        Select Rownum, old_col1, old_col2
        From (
            Select old_col1, old_col2
            From old_table
            Order By old_col1
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 463k
  • Answers 463k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Instead of using AdMob directly, you can try AdWhirl May 16, 2026 at 12:43 am
  • Editorial Team
    Editorial Team added an answer Although I'm sure that some SQL wizard will be able… May 16, 2026 at 12:43 am
  • Editorial Team
    Editorial Team added an answer Wow, I ROCK! and this guy too. http://iphone.zcentric.com/2008/08/29/post-a-uiimage-to-the-web/ Heres what… May 16, 2026 at 12:43 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.