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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:33:29+00:00 2026-05-15T20:33:29+00:00

I am using a PL/SQL procedure to extract Oracle tables of a particular schema

  • 0

I am using a PL/SQL procedure to extract Oracle tables of a particular schema to csv format. I execute the procedure by the following command:

exec dump_table_to_csv ( 'schema.tablename',  'directory',  'tablename.csv');

The directory is created using the following command:

CREATE DIRECTORY <directory_name> AS '<operating_system_path>';

The PL?SQL procedure code is as follows:

create or replace procedure dump_table_to_csv( p_tname in varchar2,
                                                   p_dir   in varchar2,
                                                   p_filename in varchar2 )
    is
        l_output        utl_file.file_type;
        l_theCursor     integer default dbms_sql.open_cursor;
        l_columnValue   varchar2(4000);
        l_status        integer;
        l_query         varchar2(1000)
                       default 'select * from ' || p_tname;
       l_colCnt        number := 0;
       l_separator     varchar2(1);
       l_descTbl       dbms_sql.desc_tab;
   begin
       l_output := utl_file.fopen( p_dir, p_filename, 'w', 32760);
       execute immediate 'alter session set nls_date_format=''dd-mon-yyyy hh24:mi:ss'' ';

       dbms_sql.parse(  l_theCursor,  l_query, dbms_sql.native );
       dbms_sql.describe_columns( l_theCursor, l_colCnt, l_descTbl );

       for i in 1 .. l_colCnt loop
           utl_file.put( l_output, l_separator || '"' || l_descTbl(i).col_name || '"' );
           dbms_sql.define_column( l_theCursor, i, l_columnValue, 4000 );
           l_separator := ',';
       end loop;
       utl_file.new_line( l_output );

       l_status := dbms_sql.execute(l_theCursor);

       while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
           l_separator := '';
           for i in 1 .. l_colCnt loop
               dbms_sql.column_value( l_theCursor, i, l_columnValue );
               utl_file.put( l_output, l_separator || l_columnValue );
               l_separator := ',';
           end loop;
           utl_file.new_line( l_output );
       end loop;
       dbms_sql.close_cursor(l_theCursor);
       utl_file.fclose( l_output );

       execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
   exception
       when others then
           execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
           raise;
   end;
   /

However, when the tables increases , this process takes too long. My question is how can I modify the code so that I can process list the schema tables and put it in a file and then the procedure will process all the tables listed in a file? If that way is not fast or possible, what other way can I process the extraction in one run without having to execute the procedure for each table?

  • 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-15T20:33:29+00:00Added an answer on May 15, 2026 at 8:33 pm

    what other way can I process the extraction in one run without having to execute the procedure for each table?

    You could automate the running of the current procedure as follows:

    begin
       for r in (select table_name from all_tables where owner = 'SCHEMA') loop
          dump_table_to_csv 
             ('schema.'||r.table_name, 'directory', r.table_name||'.csv');
       end loop;
    end;
    

    Or you could re-write the procedure to be run as:

    exec dump_schema_to_csvs ('schema', 'directory')
    

    i.e. put the FOR loop from my first example inside the procedure.

    Neither of these can be expected to run any faster than the current method though.

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

Sidebar

Related Questions

The following query is given in a PL/SQL procedure . SELECT e.data FROM extra
I've CSV string 100.01,200.02,300.03 which I need to pass to a PL/SQL stored procedure
I'm using SQL Server 2005, and want a user defined function to implement the
Ok, using SQL Server 2008. On my web page I have a textbox with
I'm trying to delete a Maintenance Plan JOB using SQL Server 2008 but keep
I have some following set of data from where I want to select Top
I need to write a stored procedure that will search a table based on
I have a database field with data like the examples below: FEE 200 A
I have a powershell 2.0 script on an XP OS. The purpose of the
Is it possible to connect to a remote instance of mysql server from 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.