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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM