oracle一列中的数据有多个手机号码用逗号隔开,我如何分别取出来?

ID      NUMBER
1 137xxxx,138xxxx
取出来成
ID NUMBER
1 137xxxx
1 138xxxx

create  table  test
(id  int ,
phone varchar2(200));
insert  into  test  values  (1, '13811111111,13311111111,13900000000' );
insert into test values (2,'15811111111,15911111111,18800000000');

第一种方式
select  id,c  from
( with  as  ( select  id,phone c  from  test)
select  id,substr(t.ca,instr(t.ca,  ',' , 1, c.lv) + 1,instr(t.ca,  ',' , 1, c.lv + 1) - (instr(t.ca,  ',' , 1, c.lv) + 1))  AS  c
from  ( select  id, ','  || c ||  ','  AS  ca,length(c ||  ',' ) - nvl(length( REPLACE (c,  ',' )),0)  AS  cnt  FROM  t) t,
( select  LEVEL  lv  from  dual  CONNECT  BY  LEVEL  <= 100) c  where  c.lv <= t.cnt) 
order  by  id
 
第二种方式  由 li0924  提供非常感谢分享。
SELECT id,
        regexp_substr(phone, '[^,]+' , 1, LEVEL ) mobile
FROM   test
CONNECT BY PRIOR id = id
     AND    PRIOR dbms_random.VALUE IS NOT NULL
     AND    LEVEL <= length(phone) - length( REPLACE (phone, ',' )) + 1

转载于:https://www.cnblogs.com/myjoan/p/4139348.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值