Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to display the values in a column one after other using Listagg in Oracle SQL

27513549-0fa6-4dfb-9c09-13debe668a63Dec 1 2014 — edited Dec 2 2014

I have a query to display some values. I used LISTAGG statement. But the output I expect is little different. Please help me out.

Select EMP_NAME, EMP_SKILL, LISTAGG(SUBJECT_NAME, ', ')

WITHIN GROUP (ORDER BY EMP_SKILL) as EMP_SUBJECT_SKILL fromEMPLOYEE group by  EMP_NAME, EMP_SKILL;

Actual Output:

EMP_NAMEEMP_SKILLSUBJECT_NAME
Abhilash KP1Maths
Anand PP1Physics
Anand PP2Maths, Zoology
Arun KumarP1Geography
Arun KumarP2Maths, History, Civics
Arun KumarP3Hindi

Expected Output:

   

EMP_NAMEEMP_SKILLSUBJECT_NAME
Abilash KP1

Maths

Anand PP1

Physics

Anand PP2Maths,

Zoology

Arun KumarP1

Geography

Arun KumarP2Maths, 
History,

Civics

Arun KumarP3Hindi

I already read a post but I could not achieve it. Could anyone please suggest how to do it.

Thanks in advance.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 30 2014
Added on Dec 1 2014
2 comments
1,199 views