溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

IMP同庫Type對象導(dǎo)入報錯ORA-02304怎么辦

發(fā)布時間:2021-11-09 16:51:52 來源:億速云 閱讀:114 作者:柒染 欄目:建站服務(wù)器

這篇文章將為大家詳細(xì)講解有關(guān)IMP同庫Type對象導(dǎo)入報錯ORA-02304怎么辦,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

當(dāng)我們使用exp/imp的時候,報錯ORA-02304實際上是沒有什么特別好的解決方法的。Type導(dǎo)入相同庫報錯的本質(zhì)在于在導(dǎo)出的時候,Oracle會將typeoid連帶導(dǎo)出。而導(dǎo)入的時候,又希望將其還原為相同的oid從而引發(fā)沖突。

 

那么,是不是我們就沒有辦法了呢?我們借助Oracle 10g提出的數(shù)據(jù)泵(Data Dump)工具,是可以避免這個問題的。

 

1、環(huán)境準(zhǔn)備

 

我們同樣適用Oracle 11gR2進(jìn)行試驗。

 

 

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用戶下,我們創(chuàng)建一些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

 

 

之后,我們創(chuàng)建用戶scottback。使用數(shù)據(jù)泵expdpscott中將數(shù)據(jù)導(dǎo)出。

 

 

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

 

 

2expdp數(shù)據(jù)導(dǎo)出

 

數(shù)據(jù)泵DataDump作為10g中推出的新一代數(shù)據(jù)備份還原工具,具有很多好的特點。DataDump服務(wù)器端使用工具,需要在服務(wù)器上執(zhí)行。

 

首先,我們需要創(chuàng)建directory對象,對應(yīng)服務(wù)器上的一個目錄位置。

 

 

[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

 

 

創(chuàng)建directory對象,并且將read write權(quán)限授予給scottscottback。

 

 

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命令行進(jìn)行導(dǎo)出。

 

 

[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

 

 

3impdp導(dǎo)入數(shù)據(jù)

 

在默認(rèn)的impdp方式下,type也是不能導(dǎo)入到相同的數(shù)據(jù)庫中去的。

 

 

[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

 

 

注意,在默認(rèn)情況下,我們導(dǎo)入數(shù)據(jù)依然會遇到oid的問題。顯示的依然是type創(chuàng)建SQL中包括有oid信息,引起oid沖突。進(jìn)而是連帶的數(shù)據(jù)表my_tabletype不能創(chuàng)建。

 

有一個片段可以關(guān)注:

 

 

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

 

 

關(guān)聯(lián)oid相同,說明typeoidOracle內(nèi)部是作為關(guān)聯(lián)的重要信息使用的。

 

impdp中,我們可以使用transform參數(shù)設(shè)置,要求將原有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信息不進(jìn)行加載,重新進(jìn)行生成。數(shù)據(jù)表取值正確。

 

 

 

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、結(jié)論

 

隨著Oracle功能不斷完善,很多新特性在exp/imp工具上已經(jīng)不能支持。Oracle 10g下推出的Data Dump有很多功能,是我們可以進(jìn)行借鑒使用的。

 

關(guān)于IMP同庫Type對象導(dǎo)入報錯ORA-02304怎么辦就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI