Export/import DataPump parameter query-how to specify a query

Source: Internet
Author: User

The examples below are based on the following demo schema's:

    • User Scott created with Script: $ ORACLE_HOME/rdbms/admin/Scott. SQL
    • User HR created with Script: $ ORACLE_HOME/demo/Schema/human_resources/hr_main. SQL

The export data pump and import data pump examples that are mentioned below are based on the directory my_dir. this directory object needs to refer to an existing directory on the server where the Oracle RDBMS is installed. example:

-- For Windows platforms:

Connect system/Manager
Create or replace directory my_dir as 'd: \ export ';
Grant read, write on directory my_dir to public;

-- For UNIX platforms:

Connect system/Manager
Create or replace directory my_dir as '/home/users/export ';
Grant read, write on directory my_dir to public;

1. query in parameter file.

UsingQueryParameter in a parameter file is the preferred method. Put double quotes around the text of the WHERE clause.

Example to export the following data with the export data pump client:

    • From table Scott. EMP all employees whose job is analyst or whose salary is 3000 or more; and
    • From table HR. Departments all deparments of the employees whose job is analyst or whose salary is 3000 or more.
file: expdp_q.par
---------------
directory = my_dir
dumpfile = exp_query.dmp
logfile = exp_query.log
schemas = HR, scott
include = table: "In ('emp', 'hangzhous')"
query = Scott. EMP: "Where job = 'analyst' or Sal >= 3000"
# place following 3 lines on one single line:
query = HR. parameters: "Where department_id in (select distinct
department_id from HR. employees E, hr.jobs J Where E. job_id = J. job_id
and upper (J. job_title) = 'analyst' or E. salary >=3000) "

-- run export DataPump job:

% Expdp system/manager parfile = expdp_q.par

Note that in this example the tables parameter cannot be used, because all table names that are specified at the tables parameter shocould reside in the same schema.

2. query on command line.

TheQueryParameter can also be used on the command line. Again, put double quotes around the text of the WHERE clause.

Example to export the following data withExport Data PumpClient:

    • Table Scott. Dept; and
    • From table Scott. EMP all employees whose name starts with an 'A'
-- Example Windows platforms:
-- note that the double quote character needs to be 'elastic'
-- place following statement on one single line:

D: \> expdp Scott/tiger directory = my_dir dumpfile = expdp_q.dmp
logfile = expdp_q.log tables = EMP, DEPT query = EMP: \ "where ename like 'a % '\"

-- Example UNIX platforms:
-- note that all special characters need to be 'elastic'

% expdp Scott/tiger directory = my_dir \
dumpfile = expdp_q.dmp logfile = expdp_q.log tables = EMP, dept \
query = EMP: \ "where ename like \ 'a \ % \ '\"

-- Example VMS platform:
-- using three double-quote characters

$ Expdp Scott/tiger directory = my_dir-
Dumpfile = exp_cmd.dmp logfile = exp_cmd.log tables = EMP, DEPT-
Query = EMP: "" where ename like 'a % '"""

Note that withOriginal exportClient two jobs were required:

-- Example Windows platforms:
-- place following statement on one single line:

D: \> exp Scott/tiger file = exp_q1.dmp log = exp_q1.log tables = EMP
query = \ "where ename like 'a % '\"

D: \> exp Scott/tiger file = exp_q2.dmp log = exp_q2.log tables = dept

-- Example UNIX platforms:

exp Scott/tiger file = exp_q1.dmp log = exp_q1.log tables = EMP \
query = \ "where ename like \ 'a \ % \'\ "

exp Scott/tiger file = exp_q2.dmp log = exp_q2.log tables = dept

-- Example VMS platform:

$ exp Scott/tiger file = exp_q1.dmp log = exp_q1.log tables = emp-
query = "" where ename like 'a % '"""

$ Exp Scott/tiger file = exp_q2.dmp log = exp_q2.log tables = Dept

Note that with original export client in Oracle8i on VMS, the syntax was different (also note the extra space that is needed between two single quotes ):
... Query = "'where ename like \ 'a % \''"
That is: [double_quote] [single_quote] Where ename like [backslash] [single_quote] A % [backslash] [single_quote] [space] [single_quote] [double_quote]

3. query in Oracle Enterprise Manager Database Console.

TheQueryCan also be specified in the Oracle Enterprise Manager Database Console. E. g .:

    • Login to the Oracle Enterprise Manager 10g Database Console, e.g.: http: // my_node_name: 5500/em
    • Click on link 'Maintenance'
    • Under 'utilities ', click on link 'export to files'
    • Answer questions on the following pages.
    • At 'step 2 of 5' (the page with the options), click on link 'show advanced options'
    • At the end of the page, under the query option, click on button 'add'
    • At the next page, choose the table name (Scott. EMP)
    • And specify the SELECT statement predicate clause to be applied to tables being exported, e.g.: Where ename like 'a %'
    • Continue with the remaining options, and submit the job.
4. Import Data Pump Parameter query.

Similar to previous examples with export data pump,QueryParameter can also be used during the import. An example of how to useQueryParameter with import data pump:

-- In source database:
-- Export the schema SCOTT:

% Expdp Scott/tiger directory = my_dir dumpfile = expdp_s.dmp \
Logfile = expdp_s.log schemas = Scott

-- In target database:
-- Import all employees of Department 10:

% Impdp Scott/tiger directory = my_dir dumpfile = expdp_s.dmp \
Logfile = impdp_s.log tables = EMP table_exists_action = append \
Query = \ "where deptno = 10 \" content = data_only

Note that this feature was not available with the original import client (IMP ). also note that the parameter table_exists_action = append is used to allow the import into an existing table and that content = data_only is used to skip importing statistics, indexes, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.