Você está na página 1de 1

how to query multiple row data in single column in oracle?

i have a table in which the values are

id value
----------------
1 10
1 20
1 30
2 33
2 34
I want the output given below using sql:

id value
-------------------
1 10
20
30
--------------------
2 33
34
--------------------

Query:

SELECT id, ListAgg(to_char(value), chr(10) || chr(13)) WITHIN GROUP (ORDER BY value) "Values"
FROM t1 GROUP BY id;

Output:

ID Values
-- ----------
1 10
20
30

2 33
34

Setup:

DROP TABLE T1;


CREATE TABLE t1 AS (SELECT 1 id, level * 10 value FROM dual CONNECT BY level <=3);
INSERT INTO t1 VALUES (2,33);
INSERT INTO t1 VALUES (2,34);