当前位置:网站首页>oracle 多行数据合并成一行数据

oracle 多行数据合并成一行数据

2022-07-05 09:29:00 相思子~

前言

划水的时候看到有人问了这个问题,顺手写个sql记录一下。

原sql数据(多行)

select null as v1_name, 1 as v1, '名称2' as v2_name, 2 as v2
  from dual
union all
select '名称3' as v1_name, 3 as v1, '名称4' as v2_name, 4 as v2
  from dual

在这里插入图片描述

合并后

select (wm_concat(a.v1_name)) as v1_name,
       (wm_concat(a.v1)) as v1,
       (wm_concat(a.v2_name)) as v2_name,
       (wm_concat(a.v2)) as v2
  from (select null as v1_name, 1 as v1, '名称2' as v2_name, 2 as v2
          from dual
        union all
        select '名称3' as v1_name, 3 as v1, '名称4' as v2_name, 4 as v2
          from dual) a

在这里插入图片描述

原网站

版权声明
本文为[相思子~]所创,转载请带上原文链接,感谢
https://blog.csdn.net/iloki/article/details/125423423