zoukankan      html  css  js  c++  java
  • Oracle随笔之用拆分后的列数据关联表查询



    -----------------------建表-------------------------
    create table test(id int, plist varchar2(30)) ;

    create table p(pid int ,pname varchar2(10));

    -----------------------插入测试数据----------------------------
    insert into test values(1,'28345|39262|56214');
    insert into test values(2,'28345|56214');
    insert into test values(3,'56214');


    insert into p values(28345,'产品A');
    insert into p values(39262,'产品B');
    insert into p values(56214,'产品C');

    -----------------------------拆分语句及结果------------------------------------

     
    select id, plist,level p_level, regexp_substr(plist , '[^|]+', 1, level) pid
    from test
    connect by level <= regexp_count(plist , '[^|]+')
    and prior id = id
    and prior dbms_random.value is not null

    查询结果


     

    -------------------拆分后关联并拼接字符后的处理语句-------------------

    with m as (

    --拆分列数据
    select id, plist,level p_level, regexp_substr(plist , '[^|]+', 1, level) pid
    from test
    connect by level <= regexp_count(plist , '[^|]+')
    and prior id = id
    and prior dbms_random.value is not null  
    )
    select m.id , m.plist, listagg(p.pname,',') within group(order by p_level) rrr
    from m inner join p on m.pid = p.pid
    group by m.id, m.plist ;




    DROP TABLE test;
    DROP TABLE P;

  • 相关阅读:
    pom.xml配置文件内容记录
    如何做出一个博客网站
    PHP中cookie和session的区别
    PHP链接mysql 出现:由于目标计算机积极拒绝,无法连接
    DOM增删操作(创建删除表格)
    DOM增删操作(select动态增加和删除以及清空)
    DOM增删改操作
    DOM操作表格
    SSD性能测试
    我的配置单
  • 原文地址:https://www.cnblogs.com/Bokeyan/p/11504921.html
Copyright © 2011-2022 走看看