当前位置:网站首页>Oracle combines multiple rows of data into one row of data

Oracle combines multiple rows of data into one row of data

2022-07-05 09:41:00 Acacia seed~

Preface

When I was paddling, I saw someone ask this question , Write a handy sql Make a note of .

primary sql data ( Multiple lines )

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

 Insert picture description here

After the merger

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, ' name 2' as v2_name, 2 as v2
          from dual
        union all
        select ' name 3' as v1_name, 3 as v1, ' name 4' as v2_name, 4 as v2
          from dual) a

 Insert picture description here

原网站

版权声明
本文为[Acacia seed~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050929139894.html