SQL script help please - creating 'batches' of rows in a table
Ramky99Feb 19 2009 — edited May 4 2010I have a table, ADAM_TEST1, that contains just 1 column - AMOUNT:
SQL> desc adam_test1;
Name Null? Type
----------------------------------------- -------- ----------------------------
AMOUNT NUMBER(12)
..I have 5000 rows in this table.
I need to insert rows into another table, ADAM_TEST, which contains these values but also assign each item a unique item_number and a batch_id for every 1000 rows.
SQL> desc adam_test;
Name Null? Type
----------------------------------------- -------- ----------------------------
BATCH_ID NUMBER(4)
ITEM_NUMBER NUMBER(4)
AMOUNT NUMBER(4)
e.g. BATCH_ID 1 will contain 1000 rows with the amounts from ADAM_TEST1 with item_numbers of 1-1000, then BATCH_ID 2 with the next 1000 rows with item numbers 1-1000 etc ...
I can populate the table with 1 batch_id and use a sequence to number them all but I'm having problems splitting them into their batches and resetting the sequence after each batch_id increment.
Some help here would be great!
Thanks,
Adam