with temp1 as(
select 'a' v1,'1,2,3,5' v2 from dual union all
select 'b' v1,'1,2,3,4' from dual union all
select 'c' v1,'2,3,4,5' from dual union all
select 'd' v1,'1,3,5,6' from dual union all
select 'e' v1,'1,5,6,7' from dual
)
,temp2 as(
select rownum rn from dual
connect by rownum<=10
)
,temp3 as(
select a.v1,a.v2,regexp_substr(a.v2,'[0-9]+',1,b.rn) v3,rn v4
from temp1 a,temp2 b
)
select v1,v2,v4 from (
select v1,v2,v4,row_number() over(partition by v1,v2 order by v4) rn
from temp3
where nvl(v3,0)<>v4)
where rn=1 |