`
quningstudy
  • 浏览: 52847 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

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 TYPE in the FROMUSER schema prior to performing
    the import.

    This WILL succeed. Note that we cannot simply drop
    the type since this will result in an ORA-02303 error as follows:

    ORA-02303: cannot drop or replace a type with type or table dependents

    We must first drop all tables containing the target TYPE, then the TYPE
    itself as follows:

    SQL> drop table mytypetable;
    SQL> drop table mytypetable2;

    SQL> drop type mytype;    

D.) From import.log note down the object id (OID) for the erroring type.
    I.e., the OID '####' of the error. 

    Then run the following statement as dba:

    SQL> select OWNER, TYPE_NAME from dba_types where TYPE_OID='####';

    This statement would give you the owner and the typename for this OID.

    If not needed, drop this type as below:

    SQL>drop type XXX;

    Run the import again.

E.) Perform a cascading drop of the FROMUSER prior to performing the import.

    This WILL succeed since it is essentially the same as option C, only
    far less selective. The syntax is quite simple:

    SQL> drop user myfromuser cascade;


F.) Recreate the TYPE in an independent schema, grant all on the TYPE to PUBLIC,
    create a copy of the TABLE in the FROMUSER schema using this public TYPE,
    copy all the old TABLE into the new TABLE using PL/SQL, and redo the
    export. Subsequently, perform the TOUSER import.

    This WILL succeed since the owner of the TYPE is not involved in the
    export or import operations. As such, the CREATE TYPE statement is
    not issued as a part of the import operation.

    The trick part of this option is recreating the object in question using
    the public TYPE. This can accomplished by following this guide:

    -- create the public type
    SQL> connect system/manager@local
    SQL> create or replace type mytype as object (m1 number, m2 varchar2(20));
    SQL> grant all on mytype to public;

    -- rename the user-type table
    SQL> connect myuser/mypassword@local
    SQL> rename mytypetable to mytypetemp;

    -- create the new public-type table to be corrected
    SQL> create table mytypetable (id number primary key, person system.mytype);

    -- copy the data from the user-type table to the public-type table
    SQL> declare
           v_col1  number;
           v_col2  mytype;
           cursor c1 is
             select * from mytypetemp;
         begin
           open c1;
           loop
             fetch c1 into v_col1, v_col2;
             exit when c1%notfound;
             insert into mytypetable
               values (v_col1, system.mytype(v_col2.m1, v_col2.m2));
             commit;
           end loop;
           close c1;
         end;
         /

    -- drop the user-type and user-type table
    SQL> drop table mytypetable;
    SQL> drop type mytype;    


Summmary:
=========

In summary, if FROMUSER/TOUSER import is used to duplicate a schema in an
instance then object types should be isolated in a schema designated only for
object types. This is a design and maintenance issue that requires serious
consideration.  IGNORE=Y only ignores CREATE TYPE import errors if the import
schema is the export schema. 

Note: A table level export/import works exactly the same as a schema level in
      regards to object types since the object type is a component of the table


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/E_wsq/archive/2008/11/25/3363784.aspx
0
0
分享到:
评论

相关推荐

    oracle 文本导入工具

    Oracle文本导入工具是一种实用程序,专门设计用于将TXT和CSV格式的数据文件批量导入到Oracle数据库中。这个工具是由开发者自己编写的,旨在简化数据导入过程,提高效率,并可能解决传统方法(如SQL*Loader或SQL命令...

    oracle10g数据导入到oracle9i解决方案

    因此,如果需要将Oracle 10g中的数据导入到Oracle 9i中,尤其是该数据包含BLOB或CLOB字段时,就需要采取一定的策略来避免错误的发生。 #### 解决方案 本节将详细介绍如何解决Oracle 10g数据导入到Oracle 9i的问题,...

    oracle导入表导入数据实例

    在Oracle数据库管理中,数据导入是一项常见的操作,用于将外部数据加载到数据库中。本实例主要探讨如何使用Oracle的数据导入工具——SQL*Loader,通过控制文件(`.ctl`)来执行这一过程。以下是对"oracle导入表导入...

    excel导入数据到Oracle数据库

    ### Excel导入数据到Oracle数据库详解 #### 一、前言 在日常工作中,我们经常会遇到需要将Excel中的数据批量导入到Oracle数据库的情况。这一过程不仅可以提高工作效率,还能确保数据的一致性和准确性。本文将详细...

    Oracle安装与数据库导入

    - 选择安装类型(如标准安装或自定义安装)。 **第六步:配置产品组件** - 根据需求选择安装的产品组件,例如数据库服务器、客户端等。 **第七步:指定安装位置** - 指定Oracle产品的安装路径。 **第八步:配置...

    Oracle建库及导入mdb

    Oracle 建库及 mdb 导入 一、Oracle 建库 Oracle 建库是指创建一个新的 Oracle 数据库。这里提供了三种创建数据库的方法:通过运行 Oracle Database Configuration Assistant 创建配置或删除数据库;通过命令行法...

    Oracle 10g 操作手册 Oracle数据类型精解

    6. **对象型**:Oracle支持自定义数据类型,如CREATE TYPE语句定义的对象类型。 7. **集合型**:VARRAY和NESTED TABLE是两种集合类型,用于存储数组或表格形式的数据。 二、Oracle 10g数据库管理员(DBA)操作 1....

    window下Oracle 11g导出的EXPDP数据导入到linux

    Oracle 11g 是一种关系型数据库管理系统, EXPDP 是 Oracle 11g 中的一种数据导出工具,用于将数据库中的数据导出到一个 dump 文件中,而后可以将该文件导入到另一个数据库中。 在 Windows 下使用 EXPDP 工具导出 ...

    oracle9i导入导出

    ### Oracle9i中使用Oracle Manager Server实现数据的导入与导出 #### 一、Oracle Manager Server配置 在Oracle9i中实现数据的导入与导出功能之前,首先需要确保已经正确配置了Oracle Manager Server。Oracle ...

    Excel数据导入到Oracle数据库工具 XLSToOracle

    同时,用户还可以自定义数据导入的表名和字段映射,确保Excel中的数据能正确地对应到Oracle数据库的相应字段。 其次,XLSToOracle提供了强大的数据预览和验证功能。在导入前,用户可以查看Excel数据在导入后的样式...

    Oracle数据导入方法

    Oracle数据导入是数据库管理中的一项重要任务,它涉及到将外部数据高效地引入到Oracle数据库中。在本篇文章中,我们将详细探讨SQL*Loader这一强大的工具,以及如何在DOS环境下使用它,同时也会提及其他数据转移工具...

    oracle10g 导入导出工具

    用户还可以定义作业控制文件(即DMP文件),以自定义导入过程,比如忽略错误、转换数据等。 使用这些工具时,你需要了解一些基本参数和选项,例如用户名、口令、表空间、导出文件名、是否包含索引等。同时,理解...

    sqlserver导入oracle数据库的数据

    总之,从SQL Server导入数据到Oracle数据库涉及多个步骤,包括设置源和目标数据库连接、选择迁移的表、处理数据类型差异等。理解这些步骤并正确执行,将确保数据迁移的顺利进行。同时,保持对数据库管理和数据迁移...

    Ecxel数据导入Oracle 数据库中

    Excel作为常用的数据整理工具,有时需要与更强大的数据库系统如Oracle进行交互,实现数据的导入导出。本文将深入探讨如何将Excel数据导入到Oracle数据库中,以及涉及到的相关技术点。 首先,我们要理解Excel文件的...

    Java调用oracle存储过程输出自定义对象或二维表

    然后,你可以使用Oracle的`STRUCT`类型从输出参数获取自定义对象的实例: ```java OracleConnection oraConn = (OracleConnection) conn; Object[] array = (Object[]) result; Struct struct = (Struct) array[0];...

    利用工具将shp文件导入到oracle spatial中

    可以使用Oracle的SDO_GEOM_METADATA表来定义空间列的几何类型和坐标系统。 4. 执行ogr2ogr命令,指定输入的SHP文件路径、输出的Oracle连接信息(包括数据库名、用户名、密码和表名)以及空间参考系统。例如: ``` ...

    mysql数据导入到Oracle中

    - **触发器和存储过程**:如果原MySQL中有自定义的存储过程或触发器,可能需要在Oracle中重新创建。 - **性能优化**:根据目标Oracle数据库的特性,可能需要对导入后的表进行分区、索引优化等操作,以提高查询性能...

    Oracle 批量导入工具

    External Tables是Oracle数据库提供的一种虚拟表类型,它允许将数据文件视为数据库表进行查询,从而实现数据的导入。与SQL*Loader不同,External Tables无需预先定义控制文件,而是通过CREATE TABLE语句来创建。这种...

    Oracle存储过程、自定义函数、动态建表存储过程等例子

    2. **Oracle自定义函数**: 自定义函数与存储过程类似,但它们通常用于返回单个值。函数可以在查询中直接使用,比如在SELECT语句中,增强查询的灵活性。比如,你可以编写一个计算折扣的函数,根据客户等级返回不同...

Global site tag (gtag.js) - Google Analytics