仅在Oracle 12.2中发现此问题。 Oracle 12.1似乎还可以。 我提供了所有要复制的内容,但是您还需要创建一个Oracle目录。我将其命名为DUMP_DIRECTORY。
我们有2个SQL过程:
首先,我们创建一个简单的表:
create table MY_TABLE as select 1 as my_column from dual;
第二,我们调用导出过程:
call EXPORT_TABLE('MY_EXPORT_JOB', 'DUMP_DIRECTORY', 'file.dat', 'MY_TABLE', 'export.log');
第三,我们放下桌子:
drop table MY_TABLE;
最后我们调用导入过程:
call IMPORT_TABLE('MY_IMPORT_JOB', 'DUMP_DIRECTORY', 'file.dat', 'import.log');
几乎一切都很好:
但是导入作业主表中存在错误:
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
如何解决或避免这些错误?
这是EXPORT_TABLE过程:
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;
这是IMPORT_TABLE过程:
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;