Monday, March 04, 2013

Exporting Multiple Tables on a Common Filter


To be frank, I consider myself novice when it comes to advanced export/import requirements. This is because I don’t deal with these utilities on a day-to-day basis.

A simple requirement came across my desk to export selected tables from a schema based on a common filter.

Requirement:
Say, you have 5 tables T1, T2, T3, T4, and T5. All have “ID” as the primary key column and you have to export data from these tables only if it is found in COMMON_TABLE. The COMMON_TABLE stores “ID” to be exported.

Solution:
The first place that I look for solution is “Oracle Documentation”. I knew we can filter a table using “QUERY” parameter of Data Pump Export but did not know how to apply it on multiple tables.

The syntax of the QUERY parameter is:

QUERY = [schema.][table_name:] query_clause

If you omit [schema.][table_name:] then the query is applied to all the tables in the export job.

So, here’s my export command:

expdp test/test DIRECTORY=data_pump_dir TABLES=t1,t2,t3,t4,t5 DUMPFILE=test.dmp QUERY=\"WHERE id IN \(SELECT common_table.id FROM common_table\)\"

You may click here to read more about the QUERY parameter of Data Pump Export.

Thanks for reading!!!

No comments:

Post a Comment