Guest User

Untitled

a guest
Dec 14th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. with src as(
  2. select 'rtyew' str from dual
  3. union all
  4. select 'trwye' from dual
  5. union all
  6. select 'trwye' from dual
  7. union all
  8. select 'rtgbfdsa' from dual
  9. union all
  10. select 'tgrbafsd' from dual
  11. ),
  12. srcrn as(
  13. select str, rownum rn from src
  14. ),
  15. rec(st, c,rn,k) as(
  16. select str, substr(str,1,1), rn, 1 from srcrn
  17. union all
  18. select st, substr(st,k+1,1), rn, k+1 from rec
  19. where k<length(st)
  20. ),
  21. res1 as (
  22. select * from rec order by rn,c
  23. ),
  24. res2 as(
  25. select st,c,rn, rownum rn1 from res1
  26. ),
  27. res as(
  28. select distinct st,rn, substr(sys_connect_by_path(c,','),2) str from res2
  29. where connect_by_isleaf = 1
  30. connect by prior rn1=rn1-1 and prior rn=rn
  31. ),
  32.  
  33. maxs as(
  34. select rn, max(length(str)) mx from res
  35. group by rn
  36. ),
  37. chars as(
  38. select rs.st,rs.rn, rs.str from res rs
  39. inner join maxs mxs on mxs.rn = rs.rn and length(str)=mxs.mx
  40. ),
  41.  
  42. preres as(
  43. select str, min(rn) rn from chars
  44. group by str)
  45.  
  46. select s.str from srcrn s
  47. inner join preres p on p.rn = s.rn;
Add Comment
Please, Sign In to add comment