Problem solve Get help with specific problems with your technologies, process and projects.

Building a text file of a database

How can I build a .txt file of a database?

How can I build a .txt file of a database?
You cannot build a text file of the entire database in one operation.

Rather, you can dump the contents of all your database tables to seperate files. Tom Kyte has a great stored procedure on his Web site that will dump a table's contents to a Comma Seperated Values (CSV) file, or a text file. Using his code, create the stored procedure "dump_table_to_csv." Once you have the stored procedure, you just need to automate the execution of this procedure for all of your database tables. Sample code to automate execution in this manner might be as follows:

  • Spool the SQL statements to a file
    spool t.sql
  • Generate the call to the stored proc for all non-SYS/SYSTEM tables
    SELECT 'exec dump_table_to_csv('''||owner||'.'||table_name||''','||
    FROM dba_tables
    WHERE owner NOT IN ('SYS','SYSTEM');
    spool off
  • Execute the proc repeatedly

The result should be many text files in your /tmp directory with the contents of each table. You may have to adjust the above script for your specific platform.

Dig Deeper on Oracle database backup and recovery

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.