Home > front end >  how to merge multiple rows in a single row by oracle sql
how to merge multiple rows in a single row by oracle sql

Time:05-20

my data be like :

ROW    DATA
1       OK
1       OK
2       ERROR
2       ERROR

I want merge data group by row

ROW     DATA
1       OK,OK
2       ERROR,ERROR

WHICH function could work out ?

CodePudding user response:

In Oracle, you can use LISTAGG to query the same:

select ROW_, 
       listagg(DATA_, ',') within group (order by ROW_) as DATAS 
from MYTBL
group by ROW_

Test query in fiddle

CodePudding user response:

For oracle versions older then 11g Release 2 you can use WMSYS package, function WM_CONCAT()

Select ROW_, 
       WMSYS.WM_CONCAT(DATA_)  
From MYTBL
Group By ROW_
  • Related