如何 select 多个结果用模式排成一行

How to select multiple results into one row with pattern

我读了 Concatenate multiple results into one row 但我不明白。

我的table:

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

正常查询是SELECT P.P_ID FROM P_TABLE P,结果是

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

但是,我需要这样的结果

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

如何?

我觉得Oracle PIVOT可以解决这个问题,但是不知道怎么用

感谢您的帮助。

我想你可以使用 LISTAGG

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