【问题标题】:Oracle data pump import into existing tableOracle 数据泵导入现有表
【发布时间】:2023-03-05 16:27:01
【问题描述】:

我需要一种有效的方式将数据从一个数据库复制到另一个数据库。 两者均基于 Oracle 11g。

  1. 步骤:(重新)创建新表
  2. 步骤:安装 pl sql 包
  3. 步骤:使用 expdp 从数据库 1 中导出表 tab_old1 和 tab_old2
  4. 步骤:使用 impdp 导入 tab_new1 和 tab_new2 数据库 2
  5. +x 步骤:使用已安装的pl sql程序

挑战: pl sql 过程已经使用了 tab_new1 和 tab_new2。因此,我在第 1 步和第 2 步中创建了两个表。 在第 3 步和第 4 步中,我只导入和导出数据。 但是 tab_new1 和 tab_new2 有额外的列 -> 导入失败。 我试图创建没有新列的视图。

导入失败并显示以下错误消息:

ORA-31693: Table data object "Schema"."tab_old1" failed to load/unload and is being skipped due to error:
ORA-31603: object “tab_old1” of type TABLE not found in schema “Schema” 

ORA-31693: Table data object "Schema"."tab_old2" failed to load/unload and is being skipped due to error:
ORA-31603: object “tab_old2” of type TABLE not found in schema “Schema” 

视图称为 tab_old1 和 tab_old2,但它们当然不是 TABLE 类型。

有什么想法吗?

如何将来自 tab_old1 的数据导入现有表中的其他列?

我不想在第一步中导出/导入表,重命名它们,然后安装 pl sqls 程序。

你能帮帮我吗?

编辑:

感谢您的回答。我尝试了您的示例两次,但 remap_table 函数对我不起作用。导入:发布 11.1.0.6.0 - 64 位生产。

编辑 2: 是的。这似乎是我的oracle版本的问题。 remap_table 函数被忽略。我可以写像 remap_table=not.existing/table 这样的废话,而 impdp 对此毫不在意。 好吧,我没有时间解决这个问题。我必须努力工作。无论如何,谢谢你的帮助。

【问题讨论】:

    标签: sql oracle datapump impdp


    【解决方案1】:

    好的,所以您使用 content=data_only 进行导入,并且您已将 tab_old1 重命名为 tab_new1 并添加了几列?

    指定导入时放 remap_table=tab_old1:tab_new1

    只要新列可以为空,这将起作用。

    例如:

    SQL> create table foo(id number);
    
    Table created.
    
    SQL> insert into foo select rownum from dual connect by level <= 5;
    
    5 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> host expdp test/test tables=foo directory=data_pump_dir
    
    Export: Release 11.2.0.2.0 - Production on Thu Nov 8 15:40:18 2012
    
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Starting "TEST"."SYS_EXPORT_TABLE_01":  test/******** tables=foo directory=data_pump_dir 
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 64 KB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    . . exported "TEST"."FOO"                                5.031 KB       5 rows
    Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
    ******************************************************************************
    Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
      /u01/app/oracle/admin/dtd64bit1/dpdump/expdat.dmp
    Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 15:40:30
    
    SQL> delete from foo;
    
    5 rows deleted.
    
    SQL> alter table foo add (a varchar2(200));
    
    Table altered.
    
    SQL> alter table foo rename to foo2;
    
    Table altered.
    

    你原来的错误是什么?

    SQL> host impdp test/test tables=foo directory=data_pump_dir content=data_only
    
    Import: Release 11.2.0.2.0 - Production on Thu Nov 8 15:42:17 2012
    
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Master table "TEST"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
    Starting "TEST"."SYS_IMPORT_TABLE_01":  test/******** tables=foo directory=data_pump_dir content=data_only 
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    ORA-39034: Table TABLE_DATA:"TEST"."FOO" does not exist.
    ORA-39126: Worker unexpected fatal error in KUPW$WORKER.UPATE_TD_ROW_IMP [15] 
    TABLE_DATA:"TEST"."FOO"
    ORA-31603: object "FOO" of type TABLE not found in schema "TEST"
    
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.KUPW$WORKER", line 8641
    

    所以重新映射..

    SQL> host impdp test/test tables=foo remap_table=foo:foo2 directory=data_pump_dir content=data_only
    
    Import: Release 11.2.0.2.0 - Production on Thu Nov 8 15:42:33 2012
    
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Master table "TEST"."SYS_IMPORT_TABLE_02" successfully loaded/unloaded
    Starting "TEST"."SYS_IMPORT_TABLE_02":  test/******** tables=foo remap_table=foo:foo2 directory=data_pump_dir content=data_only 
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "TEST"."FOO2"                               5.031 KB       5 rows
    Job "TEST"."SYS_IMPORT_TABLE_02" successfully completed at 15:42:37
    
    
    SQL> select * from foo2;
    
    ID     A
    ---------- ----------
         1
         2
         3
         4
         5
    

    【讨论】:

    • 在您的编辑中,您输入了 foo:foo2 而不是您的真实表名等。您是否正确替换了它们。请把你的真实命令输出
    • 我刚刚创建了一个新用户和新表。这些是我真正的命令和输出。见编辑2
    • 我猜这在 11.1 中可能是不可能的(我没有要测试的 11.1 实例)。我看到 11.1 上的文档:Only objects created by the Import will be remapped. In particular, preexisting tables will not be remapped if TABLE_EXISTS_ACTION is set to TRUNCATE or APPEND. 11.2 中没有此注释 11.1 docs.oracle.com/cd/B28359_01/server.111/b28319/… 11.2 docs.oracle.com/cd/E11882_01/server.112/e22490/…
    猜你喜欢
    • 2017-08-24
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 2020-07-04
    • 2010-10-06
    • 1970-01-01
    • 2018-06-19
    相关资源
    最近更新 更多