This issue has been found in Oracle 12.2 only. Oracle 12.1 seems OK. I provide everything to reproduce, but you also need to create an Oracle directory. I named it DUMP_DIRECTORY.
We have 2 SQL procedures:
- EXPORT_TABLE: Export a table.
- IMPORT_TABLE: Import a table.
First we create a simple table:
create table MY_TABLE as select 1 as my_column from dual;
Secondly we call the export procedure:
call EXPORT_TABLE('MY_EXPORT_JOB', 'DUMP_DIRECTORY', 'file.dat', 'MY_TABLE', 'export.log');
Thirdly we drop the table:
drop table MY_TABLE;
Finally we call the import procedure:
call IMPORT_TABLE('MY_IMPORT_JOB', 'DUMP_DIRECTORY', 'file.dat', 'import.log');
Almost everything seems fine:
- The procedures are successfully executed.
- There are no errors in export.log and import.log.
- The table is correctly imported back.
But there are errors in the import job master table:
select ERROR_COUNT, OBJECT_TYPE_PATH from MY_IMPORT_JOB where ERROR_COUNT > 0;
ERROR_COUNT OBJECT_TYPE_PATH
----------- -------------------------------------------------------------------
1 SCHEMA_EXPORT/TABLE/TABLE
1 SCHEMA_EXPORT/TABLE/TABLE
How to fix or avoid these errors?
Here is EXPORT_TABLE procedure:
create or replace procedure EXPORT_TABLE
(
JOB_NAME varchar2,
DIRECTORY_NAME varchar2,
DMP_FILE_NAME varchar2,
TABLE_NAME varchar2,
LOG_FILE_NAME varchar2
)
as
begin
declare
handle number(24);
begin
-- Open the handle
handle := DBMS_DATAPUMP.open('EXPORT', 'SCHEMA', NULL, JOB_NAME);
-- Keep master table to be able to use get_status
DBMS_DATAPUMP.set_parameter(handle, 'KEEP_MASTER', 1);
-- Configure files
DBMS_DATAPUMP.add_file(handle, DMP_FILE_NAME, DIRECTORY_NAME);
DBMS_DATAPUMP.add_file(handle, LOG_FILE_NAME, DIRECTORY_NAME, null, DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
-- Filter on given table names
DBMS_DATAPUMP.metadata_filter(handle, 'NAME_LIST', ''''||TABLE_NAME||'''', 'TABLE');
DBMS_DATAPUMP.metadata_filter(handle, 'INCLUDE_PATH_EXPR', '= ''TABLE''');
DBMS_DATAPUMP.start_job(handle);
-- Disconnects a user session from a job.
DBMS_DATAPUMP.detach(handle);
end;
end;
Here is IMPORT_TABLE procedure:
create or replace procedure IMPORT_TABLE
(
JOB_NAME varchar2,
DIRECTORY_NAME varchar2,
DMP_FILE_NAME varchar2,
LOG_FILE_NAME varchar2
)
as
begin
declare
handle number(24);
begin
handle := DBMS_DATAPUMP.open('IMPORT', 'FULL', NULL, JOB_NAME);
-- Keep master table to be able to use get_status
DBMS_DATAPUMP.set_parameter(handle, 'KEEP_MASTER', 1);
DBMS_DATAPUMP.set_parameter(handle, 'METRICS', 1);
-- Configure files
DBMS_DATAPUMP.add_file(handle, DMP_FILE_NAME, DIRECTORY_NAME);
DBMS_DATAPUMP.add_file(handle, LOG_FILE_NAME, DIRECTORY_NAME, null, DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
-- Change default behavior
DBMS_DATAPUMP.set_parameter(handle, 'TABLE_EXISTS_ACTION', 'REPLACE');
-- Start the job
DBMS_DATAPUMP.start_job(handle);
-- Disconnects a user session from a job.
DBMS_DATAPUMP.detach(handle);
end;
end;