oracle正则提取,oracle正则表达式,提取连续4个及以上的数字。

这个博客展示了如何使用SQL进行复杂的数据聚合,通过WITH子句创建临时表,并结合SYS_CONNECT_BY_PATH函数,对一串数字进行路径连接和分析,找出特定模式。示例查询处理了多个电话号码,提取连续数字序列,适用于大数据分析和处理场景。
摘要由CSDN通过智能技术生成

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值