zoukankan      html  css  js  c++  java
  • 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
     
    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
  • 相关阅读:
    洛谷 P1443 马的遍历
    括号序列 (自出水题)
    19年清北学堂冬令营游记
    计数排列(模板)
    全排列
    unique去重
    链表 模板+详解
    输入输出优化
    关于广/宽度优先搜索
    第四周 6.7-6.13
  • 原文地址:https://www.cnblogs.com/myjoan/p/4139348.html
Copyright © 2011-2022 走看看