В Oracle версии 12.1 или новее вы можете использовать match_recognize
примерно так:
with
my_table(col_number) as (
select 1 from dual union all
select 2 from dual union all
select 3 from dual union all
select 4 from dual union all
select 9 from dual union all
select 10 from dual union all
select 12 from dual
)
-- end of sample data (for testing only, not part of the solution)
select min_number, max_number
from my_table
match_recognize(
order by col_number
measures first(col_number) as min_number, last(col_number) as max_number
pattern (a b*)
define b as col_number = prev(col_number) + 1
);
MIN_NUMBER MAX_NUMBER
---------- ----------
1 4
9 10
12 12