SQL way to do this ? -
05-02-2006
, 02:27 PM
Not sure best way to explain this but I'll try. I have a table with
some of list ids,
I need to merge them together under one list id. We separate our
list_id in blocks of 20000
So lets say the dest list_id = 2000 and source list_id = 3000
I need to update all source list_id from 3000 to 2000 but only 20000 at
a time.
if source list id 3000 has 56,000, the first 20,000 will have b_id of 1
and next
20,000 will have b_id of 2, and the next 16,000 will have b_id of 3.
I also have to take in account that the desti list_id doesnt
overflow with more then 20k per b_id.
so given the following data
count(*) b_id dest list_id
20,000 1 2000
20,000 2 2000
7,000 3 2000
count(*) b_id source list_id
20,000 1 3000
20,000 2 3000
16,000 3 3000
after the update the final data should be
count(*) b_id dest list_id
20,000 1 2000
20,000 2 2000
20,000 3 2000
20,000 4 2000
20,000 5 2000
3,000 6 2000
Is there any better way to do this in oracle. I can do it
programmatically fine but it seems very
hackish too me. Any help is greatly appreaciated.
note (there could be 1 or more source lists)
Thanks. |