Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 126735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:21:54+00:00 2026-05-11T05:21:54+00:00

I have a simple query: select * from countries with the following results: country_name

  • 0

I have a simple query:

select * from countries 

with the following results:

country_name ------------ Albania Andorra Antigua ..... 

I would like to return the results in one row, so like this:

Albania, Andorra, Antigua, ... 

Of course, I can write a PL/SQL function to do the job (I already did in Oracle 10g), but is there a nicer, preferably non-Oracle-specific solution (or may be a built-in function) for this task?

I would generally use it to avoid multiple rows in a sub-query, so if a person has more then one citizenship, I do not want her/him to be a duplicate in the list.

My question is based on the similar question on SQL server 2005.

UPDATE: My function looks like this:

CREATE OR REPLACE FUNCTION APPEND_FIELD (sqlstr in varchar2, sep in varchar2 ) return varchar2 is ret varchar2(4000) := ''; TYPE cur_typ IS REF CURSOR; rec cur_typ; field varchar2(4000); begin      OPEN rec FOR sqlstr;      LOOP          FETCH rec INTO field;          EXIT WHEN rec%NOTFOUND;          ret := ret || field || sep;      END LOOP;      if length(ret) = 0 then           RETURN '';      else           RETURN substr(ret,1,length(ret)-length(sep));      end if; end; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:21:54+00:00Added an answer on May 11, 2026 at 5:21 am

    Here is a simple way without stragg or creating a function.

    create table countries ( country_name varchar2 (100));  insert into countries values ('Albania');  insert into countries values ('Andorra');  insert into countries values ('Antigua');   SELECT SUBSTR (SYS_CONNECT_BY_PATH (country_name , ','), 2) csv       FROM (SELECT country_name , ROW_NUMBER () OVER (ORDER BY country_name ) rn,                    COUNT (*) OVER () cnt               FROM countries)      WHERE rn = cnt START WITH rn = 1 CONNECT BY rn = PRIOR rn + 1;  CSV                                                                              -------------------------- Albania,Andorra,Antigua                                                           1 row selected. 

    As others have mentioned, if you are on 11g R2 or greater, you can now use listagg which is much simpler.

    select listagg(country_name,', ') within group(order by country_name) csv   from countries;  CSV                                                                              -------------------------- Albania, Andorra, Antigua  1 row selected. 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following rather simple query select count(*) from tbl t1, tbl t2 For
I have very simple query like this: SELECT * FROM `all_conversations` WHERE `deleted_1` !=
I have a simple MySQL query like: SELECT * FROM `content_category` CC , `content_item`
I have a simple query like this SELECT * FROM MY_TABLE; When I run
Suppose we have a simple query like this: SELECT x FROM t WHERE t.y
I have a simple query: SELECT id FROM logo WHERE (`description` LIKE %google% AND
I have a simple query like this: select * from mytable where id >
Say I have a simple query like this: SELECT * FROM topics ORDER BY
I have a simple query like: select count(*) from table Can I speed up
I have a simple query like so: SELECT * FROM orders that returns all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.