Datapump; Import using query

June 1st, 2011 | Posted in 10g, 11gR2, Blog, datapump | No Comments


Introduction:
Most of time, you need to import just some rows from your logical backup for test purpose and from production to test environment.
Many options can be used;

1- CTAS using database link.
2- Materialized view using a database link.
3- Using the query option of data pump utility.

In this post, we will see how to use the query option when importing data via Data pump utility;


Example:


[oracle@wissem ~]$ rlsqlplus 

SQL*Plus: Release 11.2.0.1.0 Production on Wed Jun 1 12:22:44 2011

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

Enter user-name: sys as sysdba
Enter password: 

SQL> create table wissem.test_imp (ID number);

Table created.

SQL> begin
  2  for i in 1..100 loop
  3  insert into wissem.test_imp values (i);
  4  end loop;
  5  commit;
  6  end;
  7  / 

PL/SQL procedure successfully completed.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@wissem ~]$ expdp wissem tables=test_imp directory=DATA_PUMP_DIR dumpfile=test_imp.dmp logfile=test_imp.log

Export: Release 11.2.0.1.0 - Production on Wed Jun 1 12:29:53 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Password: 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "WISSEM"."SYS_EXPORT_TABLE_01":  wissem/******** tables=test_imp directory=DATA_PUMP_DIR dumpfile=test_imp.dmp logfile=test_imp.log
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "WISSEM"."TEST_IMP"                         5.695 KB     100 rows
Master table "WISSEM"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for WISSEM.SYS_EXPORT_TABLE_01 is:
  /home/oracle/app/oracle/admin/ORAWISS/dpdump/test_imp.dmp
Job "WISSEM"."SYS_EXPORT_TABLE_01" successfully completed at 12:30:20

[oracle@wissem ~]$ rlsqlplus 

SQL*Plus: Release 11.2.0.1.0 Production on Wed Jun 1 12:31:12 2011

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

Enter user-name: sys as sysdba
Enter password: 

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> drop table wissem.test_imp;

Table dropped.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@wissem ~]$ impdp wissem query=TEST_IMP:\"where ROWNUM\<10\"   directory=DATA_PUMP_DIR dumpfile=test_imp.dmp logfile=test_imp.log

Import: Release 11.2.0.1.0 - Production on Wed Jun 1 12:37:59 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Password: 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "WISSEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "WISSEM"."SYS_IMPORT_FULL_01":  wissem/******** query=TEST_IMP:"where ROWNUM<10" directory=DATA_PUMP_DIR dumpfile=test_imp.dmp logfile=test_imp.log
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "WISSEM"."TEST_IMP"                         5.695 KB       9 out of 100 rows
Job "WISSEM"."SYS_IMPORT_FULL_01" successfully completed at 12:38:06

[oracle@wissem ~]$ 

[oracle@wissem ~]$ rlsqlplus 

SQL*Plus: Release 11.2.0.1.0 Production on Wed Jun 1 12:40:06 2011

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

Enter user-name: sys as sysdba
Enter password: 

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select count(*) from wissem.test_imp;

  COUNT(*)
----------
	 9

SQL>

Hope it helps,
Wissem

Scridb filter


No Comments to “Datapump; Import using query”

There are no comments yet, add one below.


Leave a Comment





Subscribe


Polls

which oracle topic interests you most?

View Results

Loading ... Loading ...


Oracle Class Tweets


Recent Posts


Recent Comments

  • Jaspreet: Brilliant explanation.
  • Yousuf: Very Nice… Just wanted to check you have done all patching at Node 1 only.. is there any thing need to...
  • Yousuf: Very Nice.. Thanks for sharing.. Once question.. You have executed all commands on Node 1 only.. Is there any...
  • Emir: Thanks… Great article
  • borse firmate: Thank you for another informative blog. The place else may just I am getting that kind of information...
  • leandro: why this parameter is systemwide? could you read from a asm instance from one failure group and from the...
  • Mohammad: paul, we create pfile from target database to source database and later we change database name, and...
  • Muhammad Ikram: Thanks Brother for sharing pearls of knowledge. May ALLAH reward you for this both here and...
  • rgrover: Thanks for the POST. I recently encounter similar issue. Your POST helped.
  • gopalredy: really its very use full to dbas
  • Vivian: This is awesome! Thank you so much!
  • henry zhong: CDB=DB, and PDB=SCHEMA but in a sub dictionary?
  • Dehbashee: Salam Brother, Thanx for sharing, however, i would be interested in chaging the password for the grid user...
  • wissem: No we don’t need that :) Just the scripts I posted above
  • Md. Tanweer: Thanks for posting the material. I really appreciate if you can send me, if you have tutorial for 11g...
  • christiaan: Thanks!! This has been bugging the hell out of me for so long.
  • Rajasekhar: Thank you
  • Samarjit Panigrahy: Very Nice and Simple Demo… Cool :)
  • cq: Any reason not to use auto patch for both CRS and RAC homes with one command? Or use opatch auto for RAC home as...
  • Hitesh: Hi, Can we use this RACcheck tool on oracle SE version ? Thanks