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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:09:12+00:00 2026-05-14T06:09:12+00:00

I have a query that returns a lot of data into a CSV file.

  • 0

I have a query that returns a lot of data into a CSV file. So much, in fact, that Excel can’t open it – there are too many rows. Is there a way to control spool to spool to a new file everytime 65000 rows have been processed? Ideally, I’d like to have my output in files named in sequence, such as large_data_1.csv, large_data_2.csv, large_data_3.csv, etc…

I could use dbms_output in a PL/SQL block to control how many rows are output, but then how would I switch files, as spool does not seem to be accessible from PL/SQL blocks?

(Oracle 10g)

UPDATE:

I don’t have access to the server, so writing files to the server would probably not work.

UPDATE 2:

Some of the fields contain free-form text, including linebreaks, so counting line breaks AFTER the file is written is not as easy as counting records WHILE the data is being returned…

  • 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-14T06:09:12+00:00Added an answer on May 14, 2026 at 6:09 am

    Got a solution, don’t know why I didn’t think of this sooner…

    The basic idea is that the master sqplplus script generates an intermediate script that will split the output to multiple files. Executing the intermediate script will execute multiple queries with different ranges imposed on rownum, and spool to a different file for each query.

    set termout off
    set serveroutput on
    set echo off
    set feedback off
    variable v_rowCount number;
    spool intermediate_file.sql
    declare
         i number := 0;
         v_fileNum number := 1;
         v_range_start number := 1;
         v_range_end number := 1;
         k_max_rows constant number := 65536;
    begin
        dbms_output.enable(10000);
        select count(*) 
        into :v_err_count
        from ...
        /* You don't need to see the details of the query... */
    
        while i <= :v_err_count loop
    
              v_range_start := i+1;
              if v_range_start <= :v_err_count then
                i := i+k_max_rows;
                v_range_end := i;
    
                dbms_output.put_line('set colsep ,  
    set pagesize 0
    set trimspool on 
    set headsep off
    set feedback off
    set echo off
    set termout off
    set linesize 4000
    spool large_data_file_'||v_fileNum||'.csv
    select data_string
    from (select rownum rn, data_object
          from 
          /* Details of query omitted */
         )
    where rn >= '||v_range_start||' and rn <= '||v_range_end||';
    spool off');
              v_fileNum := v_fileNum +1;
             end if;
        end loop;
    end;
    /
    spool off
    prompt     executing intermediate file
    @intermediate_file.sql;
    set serveroutput off
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a stored procedure that returns data from a SELECT query. I
I have a MySQL query that returns a result with a single column of
I have a dynamic query that returns around 590,000 records. It runs successfully the
I have a MySQL (v 5, MyISAM) query that returns different rows depending on
I have SQL SELECT query which returns a lot of rows, and I have
I have a query that is currently using a correlated subquery to return the
If I have a query to return all matching entries in a DB that
I have a query that is dynamically built after looking up a field list
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)

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.