Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export empty tables in oracle

I have a big problem When i take a dump of database the empty tables are truncated

How i can export the all tables in oracle 10g

exp SYSTEM/password FILE=expdat.dmp
like image 699
M.SH Avatar asked Sep 20 '13 19:09

M.SH


People also ask

How do you empty an Oracle database?

To delete a database using DBCA: Start DBCA as described in "Starting DBCA". In the Database Operation window, select Delete Database and click Next. Select the database to delete and click Next.

What is export dump in Oracle?

The export dump file includes the metadata for objects contained within the user-defined tablespaces and both the metadata and data for user-defined objects contained within the administrative tablespaces, such as SYSTEM and SYSAUX .


3 Answers

This might be because of these tables may not be extent allocated. Before taking backup you need to identify all the tables that do not have data. Then alter these tables to allocate extent.

ALTER TABLE <table_name> ALLOCATE EXTENT;

Use the below script to alter all tables they do not have extent allocated.

SELECT 'ALTER TABLE '||table_name||' ALLOCATE EXTENT;' FROM user_tables WHERE segment_created = 'NO';

Copy the output and execute it.

like image 74
Dba Avatar answered Nov 05 '22 13:11

Dba


You might consider expdp (data pump) instead. There's a parameter CONTENT=METADATA_ONLY that might get you what you want.

like image 25
DCookie Avatar answered Nov 05 '22 13:11

DCookie


I found another solution here.
Oracle has an option called DEFERRED_SEGMENT_CREATION, default true.

from the docs:

If set to true, then segments for tables and their dependent objects (LOBs, indexes) will not be created until the first row is inserted into the table.

I'll sum up the solution from the above link:

SQL> alter system set DEFERRED_SEGMENT_CREATION=FALSE scope=both;

Run the output of the following statement:

SQL> select 'alter table ' || table_name || ' move;' from user_tables where num_rows=0;

This made my exp export empty tables as well.

like image 27
Jakob Avatar answered Nov 05 '22 13:11

Jakob