Skip to Main Content

APEX

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 concate with listagg with new line feed

SmithJohn45Dec 15 2021 — edited Dec 15 2021

hi all,
i am in a situation, want all rows data in single column but after every row it should start from next line as:
desired output:
1st Name
2nd Name
3rd Name
what i tried is as below but its not working:

create table templistagg (v_name varchar2(10));

insert into templistagg values('1st Name');
insert into templistagg values('2nd Name');
insert into templistagg values('3rd Name');

select listagg(v_name, '\n ') within group (order by v_name) as all_names
from templistagg;

-- also tried following: -- 
select listagg(v_name||chr(13), ', ') within group (order by v_name) as all_names
from templistagg;

select listagg(v_name, '\r ') within group (order by v_name) as all_names
from templistagg;

please help.
regards

Comments
Post Details
Added on Dec 15 2021
7 comments
13,283 views