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 6557345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:03:44+00:00 2026-05-25T13:03:44+00:00

I am selecting records from a table and returning the results as a single

  • 0

I am selecting records from a table and returning the results as a single row CSV list.
I am using Oracle 10 release 2. here is my query:

SELECT column1,rtrim
           (replace
                (replace
                     (xmlagg(xmlelement("x", column2)).getclobval(), 
                      '<x>',
                      NULL),
                 '</x>',
                 ','),
            ',')
FROM table1
group by column1;

My problem is that when the string is greater than 4000 chars it fails because of the replace function. I can get around this by removing the replace function and using a function in my programming language.
I would like to amend the query so that I can specify how many elements in the CSV list are returned per row. So for example using the above query would return a row containing 10000 elements in the CSV list (excluding the replace function).
The amended query would return 10 rows of 1000 elements (the 10 rows can be amendable).
for example the original query would return:

1234,1234,1234,1234,1234,5678,3456,12344,654677,

The amended query would be something like

1234,1234,1234,1234,  
1234,5678,3456,12344,  
654677

I cannot use the collect function, but anything else should be good, Just SQL if possible

  • 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. Editorial Team
    Editorial Team
    2026-05-25T13:03:45+00:00Added an answer on May 25, 2026 at 1:03 pm

    You can use an analytic function to assign the rows to arbitrary buckets, and group by that.

    SELECT column1,rtrim
               (replace
                    (replace
                         (xmlagg(xmlelement("x", column2)).getclobval(), 
                          '<x>',
                          NULL),
                     '</x>',
                     ','),
                ',')
    FROM (SELECT column1, column2, NTILE(10) OVER (PARTITION BY column1 ORDER BY column2) bucket)
    group by column1,bucket;
    

    The argument to NTILE sets the number of buckets, so you can vary it as needed.

    To set a fixed number of values per bucket instead of a fixed number of buckets, I think you could replace the NTILE expression with TRUNC( ((ROW_NUMBER() OVER (PARTITION BY column1 ORDER BY column2)) - 1) /1000 ), where 1000 is the number of values per bucket.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am selecting from a table that has an XML column using T-SQL. I
I'm selecting a set of account records from a large table (millions of rows)
I am selecting records from my table that have been posted within the past
Hi guy i am selecting my active record from my table estates and all
Whats the most efficient way of selecting total number of records from a large
I am selecting rows from a table, but some of the columns are a
I'm selecting 1 field from 1 table and storing it into a temp table.
I want to use ADO via ODBC to pull records from a database table
When I open my table in phpMyAdmin and click Export (selecting .zip from the
To randomly select records from one table; do I have to always set a

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.