Skip to content
Advertisement

How to Convert multiple rows into one with comma as separator – Oracle db

I have an oracle table which has id and order_id columns. Table have same order_id with different id’s.

How can I write a select for group same order_ids, and show in one line which seperated with comma;

Example;

      ORDER_ID                ID
623cdc7ff2f3603b06a283ff    8112686  
623cdc7ff2f3603b06a283ff    8116869
623cdc7ff2f3603b06a28400    8117671
623ce4068c47be1532c4c53c    8118392

Select result should be like that;

ORDER_ID                    ID
623cdc7ff2f3603b06a283ff    8112686 , 8116869
623cdc7ff2f3603b06a28400    8117671
623ce4068c47be1532c4c53c    8118392

Advertisement

Answer

LISTAGG

Select ORDER_ID, LISTAGG(ID, ', ') WITHIN GROUP (ORDER BY ID)
From tbl
Group By ORDER_ID
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement