3

How would i insert a number of rows into a table given an incremental range, with one column of the row containing the values?

1 Answer 1

8
  INSERT INTO YourTable(YourColumn)
  SELECT 1 + (Level -1) * YourIncrement from dual connect by Level < TotalNumbers)

  i.e.


  INSERT INTO YourTable(YourColumn)
  SELECT 1 + (Level -1) * 1 from dual connect by Level < 100)

create sequence 1,2,3...99

  INSERT INTO YourTable(YourColumn)
  SELECT 1 + (Level -1) * 2 from dual connect by Level < 100)

create sequence 1, 3, 5 .. 100

Or you can use SEQUENCES

3
  • How can the example you gave 1,2,3..99 work when inserting more than one column? For ex. 1,sysdate 2,sysdate Also if using sequences, then for a range of, say 10k values, I would need to execute 10k insert commands, right?
    – Seamus
    Sep 17, 2010 at 23:51
  • I looked at 'INSERT INTO SELECT' and got the answer for the multi-column command :
    – Seamus
    Sep 25, 2010 at 10:01
  • INSERT INTO T2(ind,command) SELECT 1 + (Level -1) * 1,'do this' from dual connect by Level < 10;
    – Seamus
    Sep 25, 2010 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.