Skip to Main Content
  • Questions
  • Getting Dump of specific rows from all tables in database

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Rahul.

Asked: December 05, 2004 - 8:48 pm UTC

Last updated: December 07, 2004 - 10:02 am UTC

Version: 9.2

Viewed 10K+ times! This question is

You Asked

Dear Tom,

I have a huge database of some terabytes. I am using oracle version 9.2 I need to export the data of this DB and make a dmp file out of it so that I can move the data from one machine to another.

In the table design, each and every table in the database has two
columns "updatedate" and "updatetime". I would like to get the dump file for all the tables and the records in the table should be selected as per the update date. For eg I want the dump of data which was updated since last one month.

How can I do this with the exp command? Or is there any other way out for this?

Thanks in advance.

Regards

Rahul

and Tom said...

Well, I don't get the "updatedate" and 'updatetime" concept. I hope you didn't create your own brand new "datatype" using two number fields (given that the oracle date holds both date and time)

I'll demonstrate using a single column -- but since 8i, export has supported a "query=" parameter. consider:


ops$tkyte@ORA10GR1> create table t1 ( x int, updatedate date );

Table created.

ops$tkyte@ORA10GR1> create table t2 ( x int, updatedate date );

Table created.

ops$tkyte@ORA10GR1> create table t3 ( x int, updatedate date );

Table created.

ops$tkyte@ORA10GR1>
ops$tkyte@ORA10GR1> insert into t1 select rownum, sysdate-rownum from all_objects where rownum < 1000;

999 rows created.

ops$tkyte@ORA10GR1> insert into t2 select rownum, sysdate-rownum from all_objects where rownum < 1000;

999 rows created.

ops$tkyte@ORA10GR1> insert into t3 select rownum, sysdate-rownum from all_objects where rownum < 1000;

999 rows created.

ops$tkyte@ORA10GR1> commit;

Commit complete.

ops$tkyte@ORA10GR1>
ops$tkyte@ORA10GR1> host echo 'query="where updatedate >= add_months(sysdate,-1)"' > exp.par

ops$tkyte@ORA10GR1>
ops$tkyte@ORA10GR1>
ops$tkyte@ORA10GR1> select count(*), count(case when updatedate >= add_months(sysdate,-1) then 1 end) cnt2
2 from t1;

COUNT(*) CNT2
---------- ----------
999 29

so, of the 999 records in there, 29 are "interesting", running export:


ops$tkyte@ORA10GR1>
ops$tkyte@ORA10GR1> host exp userid=/ 'tables=(t1,t2,t3)' parfile=exp.par

Export: Release 10.1.0.3.0 - Production on Mon Dec 6 10:24:02 2004

Copyright (c) 1982, 2004, Oracle. All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set

About to export specified tables via Conventional Path ...
. . exporting table T1 29 rows exported
. . exporting table T2 29 rows exported
. . exporting table T3 29 rows exported
Export terminated successfully without warnings.


we get just those rows..


Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Further clarification

Rahul Kulkarni, December 06, 2004 - 7:28 pm UTC

I have about 181 tables in the database. Does this mean that when I give the command
host exp userid=/ 'tables=(t1,t2,t3)' parfile=exp.par
I must specify all the 181 table names here? Isnt it possible to export all the required rows from all tables at one time without specifying the table name.



Tom Kyte
December 07, 2004 - 9:54 am UTC

list the tables in the parfile itself

write a query to select out table_name ||','

put that in the parfile. then just keep using that parfile.

incremental export

A reader, December 06, 2004 - 10:20 pm UTC

probably you need incremental export policy. for that you [ DBA ] dont need to maintain "last updated" information. it is going to export only those blocks which are modified after last export. but this is not going to address your question to export data which are updated after a specific date.

Tom Kyte
December 07, 2004 - 10:02 am UTC

and what is an "incremental export policy"?

export with "incremental" exports the entire contents of any table modified since the last incremental/full export. THE ENTIRE TABLE.


rman can incrementally backup a database getting just changed blocks, export gets entire tables. backups cannot be used to satisfy their goal in this case.

More to Explore

VLDB

If you are new to partitioning, check out Connor McDonald's introduction series here.

VLDB

Documentation set on VLDB and Partitioning.