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

前言

划水的时候看到有人问了这个问题,顺手写个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

oracle 多行数据合并成一行数据_第1张图片

合并后

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

oracle 多行数据合并成一行数据_第2张图片

你可能感兴趣的:(数据库,oracle,数据库,database)