Q:

Select limited amount of rows with at most n rows of type A

Is it possible to select a limited amount M of rows with at most N rows of some type T(string or enum field) in one select statement(M > N)?
So far I've tried using DBMS_RANDOM like so, but it's not pretty and does not do exactly what I need
select id from some_table 
         where ((type = 'A' and round(dbms_random.value(0,100)) > 75)
                or (type <> 'A'))
               and rownum < 1000;

EDIT:
What i'm dealing with is a kind of queue implemented using database. there are K different types of messages. The A type of messages are low priority and they are inserted around 100k records at a time once or twice a day. other types of messages have higher priority and are inserted constantly. So what i've tried to achieve is to process those records in such a way that when messages of type A are inserted messages of other types won't starve.

A:

I suppose you could use rownum and union all but that can get complicated.  I think row_number() is better suited for this purpose:
select t.*
from (select id, row_number() over (partition by type order by dms_random.value()) as seqnum
      from t
     ) t
where (type = 'A' and seqnum <= 100) and
      rownum < 1000;

