SQL> with t as

2 (select 13714430798 num

3 from dual

4 union all

5 select 13714432105

6 from dual

7 union all

8 select 13714412345

9 from dual

10 union all

11 select 13714456784

12 from dual

13 union all

14 select 13714498769

15 from dual

16 union all

17 select 13712341234 from dual),

18 tmp as

19 (select a.num, b.rn, to_number(substr(a.num, b.rn, 1)) i

20 from t a, (select rownum rn from dual connect by rownum <= 11) b)

21 select x.num, to_char(y.str) as str

22 from t x,

23 (select num, wm_concat(replace(str, ',')) str

24 from (select num, max(sys_connect_by_path(i, ',')) str

25 from tmp x

26 where level >= 4

27 start with not exists (select 1

28 from tmp

29 where num = x.num

30 and rn = x.rn - 1

31 and i = x.i - 1)

32 connect by prior num = num

33 and prior rn = rn - 1

34 and prior i = i - 1

35 group by num, connect_by_root rn

36 union all

37 select num, max(sys_connect_by_path(i, ',')) str

38 from tmp x

39 where level >= 4

40 start with not exists (select 1

41 from tmp

42 where num = x.num

43 and rn = x.rn - 1

44 and i = x.i + 1)

45 connect by prior num = num

46 and prior rn = rn - 1

47 and prior i = i + 1

48 group by num, connect_by_root rn)

49 group by num) y

50 where x.num = y.num(+);

NUM STR

---------- --------------------------------------------------------------------------------

1371234123 1234,1234

1371441234 12345

1371443210 43210

1371445678 45678

1371449876 9876

1371443079

6 rows selected

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐