Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL script help please - creating 'batches' of rows in a table

Ramky99Feb 19 2009 — edited May 4 2010
I 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
This post has been answered by BluShadow on Feb 19 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2010
Added on Feb 19 2009
18 comments
2,698 views