SoFunction
Updated on 2025-03-05

Export and import specific tables

expdp and impdp export to import specific tables

Importing and exporting specific tables in oracle was originally 10g or before, it was very simple:

1. 10g or before

1、Export the specified table
exp 'sys/pwd@server1 as sysdba' file=c:\temp\ tables=(schema1.table1,schema1.table2)

2、Import the specified table
imp 'sys/pwd@server2 as sysdba' file=c:\temp\ fromuser=schema1 touser=schema1 tables=(table1,table2) ignore=Y

2. 11g or 12c

But after 12C, this writing method seems to be not supported.

You can write this way:

1、Export the specified table
expdp 'sys/pwd@server1 as sysdba' directory=dbbak dumpfile= logfile= tables=schema1.table1,schema1.table2

2、Import the specified table
--If the tablespace name corresponding to the source library and the target library is the same as the tablespace name:
impdp 'sys/pwd@server2 as sysdba' directory=dbbak dumpfile= tables=schema1.table1,schema1.table2  REMAP_SCHEMA=schema1:schema1
--REMAP_SCHEMA=schema1:schema1,Source libraryshema:Target libraryschema

--如果Source library和Target library对应的表空间名称不一样:
impdp 'sys/pwd@server2 as sysdba' directory=dbbak dumpfile= tables=schema1.table1,schema1.table2  remap_schema=schema1:schema2 remap_tablespace=tablespace1:tablespace2 
--remap_schema=schema1:schema2,Source libraryshema:Target libraryschema
--remap_tablespace=tablespace1:tablespace2,Source tablespace:Target tablespace

Pay attention to the account corresponding to the schema of the target library, because it may involve various elements such as creating tables, and you must have sufficient permissions to import them.

If dbbak does not have it, you must first create:

Under sqlplus:

create directory dbbak as 'c:\temp';--(WilldbbakMounted to the operating systemc:/tempFolders)
grant read,write on directory dbbak to public;

What is this dbbak (the name is just your own name)? It is where we store data export files, which are mounted to a folder in the operating system, for examplec:\temp. It is said that a database is similar to an operating system to a certain extent. It has its own disk management mechanism and generally does not directly use the operating system file system. Even, it wants to use "general disks" directly, that is, unformatted disks. Therefore, dbbak is a disk path map, and the path under the operating system must be mapped into oracle before it can be used.

The above expdp, impdp export and import specific tables. After searching online, I found that there are few examples that can be used directly. I still combined these two and passed after some tests.

3. Pay attention

Note that 10g can be directly executed on the client side; while 11g or 12c can be executed on the server side.

In addition, if the operating system is a WIN2012 or above, it is not possible to run the above code in the power shell. You must be in the DOS command line window. It seems that this power shell is still in the oracle 10g era and is not power at all.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.