IMP同庫Type對象導入報錯ORA-02304 ORA-02304: invalid object identifier literal


在上篇《IMP同庫Type對象導入報錯ORA-02304》(http://space.itpub.net/17203031/viewspace-732089)中,我們討論了由於type使用特性的原因,
如果我們使用exp/imp工具導入到相同數據庫中,是會發生報錯現象。 當我們使用exp/imp的時候,報錯ORA-02304實際上是沒有什么特別好的解決方法的。Type導入相同庫報錯的本質在於在導出的時候,Oracle會將type的oid連帶導出。
而導入的時候,又希望將其還原為相同的oid從而引發沖突。 那么,是不是我們就沒有辦法了呢?我們借助Oracle 10g提出的數據泵(Data
Dump)工具,是可以避免這個問題的。 1、環境准備 我們同樣適用Oracle 11gR2進行試驗。 SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production 在scott用戶下,我們創建一些type類型對象。 SQL> grant imp_full_database to scott; Grant succeeded SQL> grant exp_full_database to scott; Grant succeeded SQL> conn scott/tiger@wilson; Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 Connected as scott SQL> create type mt_type as object (xm number, tchar varchar2(10)); 2 / Type created SQL> select type_name, type_oid from user_types; TYPE_NAME TYPE_OID ------------------------------ -------------------------------- MT_TYPE C230A55B1FC34E1DE040A8C0580017C6 SQL> create table my_tabletype of mt_type; Table created SQL> insert into my_tabletype values (1,'df'); 1 row inserted SQL> commit; Commit complete 之后,我們創建用戶scottback。使用數據泵expdp從scott中將數據導出。 SQL> create user scottback identified by scottback; User created SQL> grant resource to scottback; Grant succeeded SQL> grant connect to scottback; Grant succeeded SQL> grant exp_full_database to scottback; Grant succeeded SQL> grant imp_full_database to scottback; Grant succeeded 2、expdp數據導出 數據泵DataDump作為10g中推出的新一代數據備份還原工具,具有很多好的特點。DataDump是服務器端使用工具,需要在服務器上執行。 首先,我們需要創建directory對象,對應服務器上的一個目錄位置。 [root@oracle11g /]# pwd [root@oracle11g /]# mkdir export [root@oracle11g /]# ls -l | grep export drwxr-xr-x 2 root root 4096 Jun 11 19:29 export [root@oracle11g /]# chown oracle:oinstall export [root@oracle11g /]# ls -l | grep export drwxr-xr-x 2 oracle oinstall 4096 Jun 11 19:39 export 創建directory對象,並且將read write權限授予給scott和scottback。 SQL> create or replace directory MY_DIR 2 as '/export'; Directory created SQL> grant write, read on directory my_dir to scott; Grant succeeded SQL> grant write, read on directory my_dir to scottback; Grant succeeded’ 再使用expdp命令行進行導出。 [oracle@oracle11g ~]$ cd /export/ [oracle@oracle11g export]$ pwd /export [oracle@oracle11g export]$ expdp scott/tiger@wilson directory=my_dir dumpfile=scott.dmp logfile=resexp.log schemas=scott Export: Release 11.2.0.1.0 - Production on Mon Jun 11 19:35:08 2012 [oracle@oracle11g export]$ expdp scott/tiger@wilson directory=my_dir dumpfile=scott.dmp logfile=resexp.log schemas=scott Export: Release 11.2.0.1.0 - Production on Mon Jun 11 19:35:08 2012 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/********@wilson directory=my_dir dumpfile=scott.dmp logfile=resexp.log schemas=scott Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA (篇幅原因,部分省略…..) . . exported "SCOTT"."T" 0 KB 0 rows . . exported "SCOTT"."T1" 0 KB 0 rows . . exported "SCOTT"."T2" 0 KB 0 rows Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is: /export/scott.dmp Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 19:36:00 [oracle@oracle11g export]$ ls -l total 420 -rw-r--r-- 1 oracle oinstall 2467 Jun 11 19:36 resexp.log -rw-r----- 1 oracle oinstall 421888 Jun 11 19:36 scott.dmp 3、impdp導入數據 在默認的impdp方式下,type也是不能導入到相同的數據庫中去的。 [oracle@oracle11g export]$ impdp scottback/scottback@wilson directory=my_dir dumpfile=scott.dmp logfile=resimp.log remap_schema=scott:scottback Import: Release 11.2.0.1.0 - Production on Mon Jun 11 19:37:37 2012 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Master table "SCOTTBACK"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SCOTTBACK"."SYS_IMPORT_FULL_01": scottback/********@wilson directory=my_dir dumpfile=scott.dmp logfile=resimp.log remap_schema=scott:scottback Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTTBACK" already exists Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC ORA-39083: Object type TYPE failed to create with error: ORA-02304: invalid object identifier literal Failing sql is: CREATE TYPE "SCOTTBACK"."MT_TYPE" OID 'C230A55B1FC34E1DE040A8C0580017C6' as object (xm number, tchar varchar2(10)); Processing object type SCHEMA_EXPORT/TABLE/TABLE ORA-39117: Type needed to create table is not included in this operation. Failing sql is: CREATE TABLE "SCOTTBACK"."MY_TABLETYPE" OF "SCOTTBACK"."MT_TYPE" OID 'C230B8AA21E527C9E040A8C058001816' OIDINDEX ( PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "SYSTEM" ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "SCOTTBACK"."BASELINE_TEST" 22.90 KB 1 rows (篇幅原因,省略部分 …..) Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Job "SCOTTBACK"."SYS_IMPORT_FULL_01" completed with 4 error(s) at 19:37:47 注意,在默認情況下,我們導入數據依然會遇到oid的問題。顯示的依然是type創建SQL中包括有oid信息,引起oid沖突。進而是連帶的數據表my_tabletype不能創建。 有一個片段可以關注: CREATE TYPE "SCOTTBACK"."MT_TYPE" OID 'C230A55B1FC34E1DE040A8C0580017C6' as object (xm number, tchar varchar2(10)); Processing object type SCHEMA_EXPORT/TABLE/TABLE ORA-39117: Type needed to create table is not included in this operation. Failing sql is: CREATE TABLE "SCOTTBACK"."MY_TABLETYPE" OF "SCOTTBACK"."MT_TYPE" OID 'C230B8AA21E527C9E040A8C058001816' OIDINDEX ( PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 關聯oid相同,說明type的oid在Oracle內部是作為關聯的重要信息使用的。 在impdp中,我們可以使用transform參數設置,要求將原有dmp文件中oid映射重新生成。 [oracle@oracle11g export]$

impdp scottback/scottback@wilson directory=my_dir dumpfile=scott.dmp logfile=resimp2.log
remap_schema=scott:scottback transform=oid:n Import: Release 11.2.0.1.0 - Production on Mon Jun 11 19:39:07 2012 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Master table "SCOTTBACK"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SCOTTBACK"."SYS_IMPORT_FULL_01": scottback/********@wilson directory=my_dir dumpfile=scott.dmp logfile=resimp2.log
remap_schema=scott:scottback transform=oid:n
Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTTBACK" already exists Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "SCOTTBACK"."BASELINE_TEST" 22.90 KB 1 rows . . imported "SCOTTBACK"."DEPT" 5.937 KB 4 rows . . imported "SCOTTBACK"."EMP" 8.992 KB 14 rows . . imported "SCOTTBACK"."MY_TABLETYPE" 6.507 KB 1 rows . . imported "SCOTTBACK"."SALES_QUAL" 6.007 KB 6 rows . . imported "SCOTTBACK"."SALGRADE" 5.867 KB 5 rows . . imported "SCOTTBACK"."BONUS" 0 KB 0 rows . . imported "SCOTTBACK"."T" 0 KB 0 rows . . imported "SCOTTBACK"."T1" 0 KB 0 rows . . imported "SCOTTBACK"."T2" 0 KB 0 rows Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/TABLE/COMMENT Processing object type SCHEMA_EXPORT/VIEW/VIEW ORA-31684: Object type VIEW:"SCOTTBACK"."V_T1" already exists Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Job "SCOTTBACK"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 19:39:20 其中,transform取值oid:n的含義就是對oid信息不進行加載,重新進行生成。數據表取值正確。 SQL> conn scottback/scottback@wilson; Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 Connected as scottback SQL> select * from my_tabletype; XM TCHAR ---------- ---------- 1 df 4、結論 隨着Oracle功能不斷完善,很多新特性在exp/imp工具上已經不能支持。Oracle 10g下推出的Data Dump有很多功能,是我們可以進行借鑒使用的。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM