日期:2014-05-16  浏览次数:20367 次

ORACLE 自定义类型该如何导入?
ORACLE 自定义类型该如何导入?
在某数据库中,用exp导出用户a下的所有数据,包括自定义的类型"MAIN_SZ_ZGY_TYPE".然后用imp将导出的数据导入同一数据库的用户b中,发现表和序列都可以导入,但是自定义的类型导入失败.  

经由直接路径导出由EXPORT:V09.02.00创建的导出文件
已经完成ZHS16GBK字符集和AL16UTF16 NCHAR 字符集中的导入
. 正在将TYXHL_DEV的对象导入到 ZTYXHL_DEV
IMP-00017: 由于 ORACLE 的 2304 错误,以下的语句失败
"CREATE TYPE "MAIN_SZ_ZGY_TYPE" TIMESTAMP '2008-03-07:15:25:13' OID '91234DA"
"113E2469C859AD34D984CB5E1'                                                 "
"                           as object"
"("
"total                        NUMBER,"
"  total_lj_je                  NUMBER,"
"  corresponding_period_je      NUMBER,"
"  corresponding_period_percent VARCHAR2(30)"
")"

IMP-00003: 遇到 ORACLE 错误 2304
ORA-02304: 无效的对象标识文字
IMP-00017: 由于 ORACLE 的 2304 错误,以下的语句失败

请问:ORACLE 自定义类型该如何导入????

出错原因:
往b用户imp表时,要创建type,使用的OID和用户a的一样,同一个实例的OID不能重复。

解决办法:
在system用户下定义 type MAIN_SZ_ZGY_TYPE,授权
grant all on MAIN_SZ_ZGY_TYPE to public;
用户a建表用system.MAIN_SZ_ZGY_TYPE 类型,这样导出用户表时就不会到type了,在用户b中就不会建type。

详细内容如下:
Introduction:
=============

If you are importing using the FROMUSER/TOUSER clause to duplicate a schema
within an instance, you may experience the following errors:

  imp system/manager fromuser=a touser=b file=demo.dmp log=import.log

  IMP-00017: following statement failed with ORACLE error 2304:
  IMP-00003: ORACLE error 2304 encountered
  ORA-02304: invalid object identifier literal
  IMP-00063: Warning: Skipping table "x"."x" because object
               type "x"."x" cannot be created or has different identifier

These errors will occur if the schema has a user defined object type(s)
(CREATE TYPE) and a relational table column of a user defined datatype.

The IMP-00017 error is of particular interest since it indicates te source
of the error:

  IMP-00017: following statement failed with ORACLE error 2304:
  "CREATE TYPE "xxxx" TIMESTAMP '1999-01-01:12:00:00' OID '####' as object ..."

In brief, if the FROMUSER's object types already exist on the target instance,
errors occur because the object identifiers (OIDs) of the TOUSER's object types
already exist. Within a single database instance, object identifiers (OIDs) must
be unique. As a result, the error causes Import will skip the creation of
relational tables with columns of the pre-existing user defined type.

So what are the options available to us for completing this import?


Possible Solution Scenarios:
============================

A.) Use the IGNORE=Y clause on the import

    This WILL NOT succeed since CREATE TYPE errors are only ignored if
    importing into the originating schema, not into a separate "to"
    schema!

B.) Pre-create the relational table in the TOUSER's schema

    This WILL NOT succeed since the CREATE TYPE statement is present in
    the export file.

C.) Drop the TABLE and TYP