Query Clause In Expdp(DATAPUMP):
================================
QUERY clause can be used in expdp or impdp to export/import subset of the data or data with specific conditions.
Export dump of a table from emp_tab WHERE created > sysdate -40 . The filter can be added on any column depending upon the requirement.
SQL> select count(*) from “DBAADMIN”."EMP” WHERE created > sysdate -40;
COUNT(*)
———-
1600
Create a parfile with query clause:
cat expdp_query.par
dumpfile=test.dmp
logfile=test1.log
directory=TEST
tables=dbaadmin.EMP
QUERY=dbaadmin.EMP:"WHERE created > sysdate -40"
Now run the expdp command with parfile. We can see, 1600 rows will be exported.
expdp parfile=expdp_query.par
Export: Release 12.1.0.2.0 - Production on Mon Jan 23 14:52:07 2017
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Username: / as sysdba
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLE_01": /******** AS SYSDBA parfile=expdp_query.par
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 29 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
. . exported "dbaadmin"."EMP" 199.4 KB 1600 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
/export/home/oracle/test.dmp
Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at Mon Jan 27 14:53:02 2018 elapsed 0 00:00:23