Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with src as(
- select 'rtyew' str from dual
- union all
- select 'trwye' from dual
- union all
- select 'trwye' from dual
- union all
- select 'rtgbfdsa' from dual
- union all
- select 'tgrbafsd' from dual
- ),
- srcrn as(
- select str, rownum rn from src
- ),
- rec(st, c,rn,k) as(
- select str, substr(str,1,1), rn, 1 from srcrn
- union all
- select st, substr(st,k+1,1), rn, k+1 from rec
- where k<length(st)
- ),
- res1 as (
- select * from rec order by rn,c
- ),
- res2 as(
- select st,c,rn, rownum rn1 from res1
- ),
- res as(
- select distinct st,rn, substr(sys_connect_by_path(c,','),2) str from res2
- where connect_by_isleaf = 1
- connect by prior rn1=rn1-1 and prior rn=rn
- ),
- maxs as(
- select rn, max(length(str)) mx from res
- group by rn
- ),
- chars as(
- select rs.st,rs.rn, rs.str from res rs
- inner join maxs mxs on mxs.rn = rs.rn and length(str)=mxs.mx
- ),
- preres as(
- select str, min(rn) rn from chars
- group by str)
- select s.str from srcrn s
- inner join preres p on p.rn = s.rn;
Add Comment
Please, Sign In to add comment