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
2010-09-16 15:23:15
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
2010-09-17 23:51:07
I looked at 'INSERT INTO SELECT' and got the answer for the multi-column command :
Seamus
2010-09-25 10:01:07
INSERT INTO T2(ind,command) SELECT 1 + (Level -1) * 1,'do this' from dual connect by Level < 10;
Seamus
2010-09-25 10:02:30