I would like to take a simple query on a list of members that are indexed by a number and group them into 'buckets' of equal size. So the base query is:
select my_members.member_index from my_members where my_members.active=1;
Say I get 1000 member index numbers back, now I want to split them into 10 equally sized groups by a max and min member index. Something like:
Active members in 0 through 400 : 100 Active members in 401 through 577 : 100 ... Active members in 1584 through 1765 : 100
The best I could come up with is repeatedly querying for the max(my_members.member_index) with an increasing rownum limit:
  for r in 1 .. 10 loop
  select max(my_members.member_index)
  into ranges(r)
  from my_members
   where  my_members.active = 1
   and rownum < top_row
   order by my_members.member_index asc;
   top_row    := top_row + 100;
  end loop;