TooN DinDarkDevil TooN DinDarkDevil - 23 days ago 7
SQL Question

How to select multiple results into one row with pattern

I read Concatenate multiple results into one row and i don't understand about that.

My table:

-----------------
| P_TABLE |
-----------------
| P_ID | P_DATA |
| 12 | AAAA |
| 15 | BBBB |
| 19 | CCCC |
-----------------


Normally query is
SELECT P.P_ID FROM P_TABLE P
and the result is

--------
| P_ID |
--------
| 12 |
| 15 |
| 19 |
--------


but, I need result like this

---------------
| P_ID |
---------------
| (12,15,19) |


How ?

I think this solution may be solve by Oracle PIVOT, but I have no idea how to use.

Thank you for any help.

Answer

I think you can use LISTAGG

select listagg(p_id,',') within group (order by p_id) p_id from p_table;