Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼


Databases and Refreshing Test Data

3. Import Prod Dump File

This procedure SCHEMA_REFRESH.IMPORT_PROD imports the Production database export dump file into the Test database. Listing 3 lists the API that shows how the prod dump file is imported in the Test database using data pump technology.

procedure import_prod
  ind NUMBER;              -- Loop index
  h1 NUMBER;               -- Data Pump job handle
  percent_done NUMBER;     -- Percentage of job complete
  job_state VARCHAR2(30);  -- To keep track of job state
  le ku$_LogEntry;         -- For WIP and error messages
  js ku$_JobStatus;        -- The job status from get_status
 -- jd ku$_JobDesc;          -- The job description from get_status
  sts ku$_Status;          -- The status object returned by get_status
-- Create a (user-named) Data Pump job to do a "full" import (everything
-- in the dump file without filtering).

 h1 := dbms_datapump.open (operation => 'IMPORT',  job_mode => 'FULL',  version => 'COMPATIBLE');

dbms_datapump.add_file(handle => h1, filename => 'IMPDAT.LOG',  filetype => 3);
dbms_datapump.add_file(handle => h1, filename => 'refresh.dmp', filetype => 1);
-- If a table already exists in the destination schema, skip it (leave
-- the preexisting table alone). This is the default, but it does not hurt
-- to specify it explicitly.
-- Start the job. An exception is returned if something is not set up properly.
-- The import job should now be running. In the following loop, the job is 
-- monitored until it completes. In the meantime, progress information is 
-- displayed. Note: this is identical to the export example.
 percent_done := 0;
  job_state := 'UNDEFINED';
  while (job_state != 'COMPLETED') and (job_state != 'STOPPED') loop
           dbms_datapump.ku$_status_job_error +
           dbms_datapump.ku$_status_job_status +
    js := sts.job_status;
-- If the percentage done changed, display the new value.
     if js.percent_done != percent_done
      dbms_output.put_line('*** Job percent done = ' ||
      percent_done := js.percent_done;
    end if;
-- If any work-in-progress (WIP) or Error messages were received for the job,
-- display them.
       if (bitand(sts.mask,dbms_datapump.ku$_status_wip) != 0)
      le := sts.wip;
      if (bitand(sts.mask,dbms_datapump.ku$_status_job_error) != 0)
        le := sts.error;
        le := null;
      end if;
    end if;
    if le is not null
      ind := le.FIRST;
      while ind is not null loop
        ind := le.NEXT(ind);
      end loop;
    end if;
  end loop;
-- Indicate that the job finished and gracefully detach from it. 
 -- dbms_output.put_line('Job has completed');
  --dbms_output.put_line('Final job state = ' || job_state);
     when others then
         Raise_Application_Error ( -40000, 'Import Data Pump Error ');
END import_prod;

Listing 3: Import Prod Dump File

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.