tags:

views:

59

answers:

1

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

+5  A: 
  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

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