drop table 报错ora- 全分析

本文详细介绍了在Oracle数据库中删除表空间时可能遇到的四种常见错误及其解决方案,包括处理物化视图、索引约束、分区表及外键约束等问题。

 

001.gif今天中午删除了 500G的表空间,很有成就感啊 001.gif

Drop tablespace 有下面两种方式:

drop tablespace crm_data including contents and datafiles;
drop tablespace crm_data including contents cascade constraints;

报错有下面几种:

一. ORA-23515


--- ORA-23515: materialized views and/or their indices exist in the tablespace

drop tablespace crm_data including contents and datafiles
*
ERROR at line 1:
ORA-23515: materialized views and/or their indices exist in the tablespace

意思是:该表空间 CRM_DATA含有物化视图,或者含有物化视图的索引

解决办法:

-- 首先删掉该表空间下的的物化视图
select 'drop  materialized view '||owner||'.'||segment_name||' ;'
  from dba_segments
 where segment_name in (select mview_name from dba_mviews)
   and tablespace_name = 'CRM_DATA'


-- 然后删除该表空间下的其他表空间下物化视图在本表空间下创建的索引
select *
  from dba_segments
 where tablespace_name = 'CRM_DATA'
   and segment_name in
       (select index_name
          from dba_indexes
         where table_name in (select mview_name from dba_mviews));

二. ORA-02429

 

---ORA-02429: cannot drop index used for enforcement of unique/primary key

drop tablespace crm_idx including contents cascade constraints
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-02429: cannot drop index used for enforcement of unique/primary key

ORA-02429的意思是: 让你删除该表空间下面的 primary key 和 unique key

处理办法:
select 'alter table '||owner||'.'||table_name||' drop constraint '||constraint_name||' ;'
  from dba_constraints
 where constraint_type in ('U', 'P')
   and (index_owner, index_name) in
       (select owner, segment_name
          from dba_segments
         where tablespace_name = 'CRM_IDX');

 

三. ORA-14404

 

--ORA-14404: partitioned table contains partitions in a different tablespace


drop tablespace crm_arc_data including contents and datafiles
*
ERROR at line 1:
ORA-14404: partitioned table contains partitions in a different tablespace

意思是: 本表空间下面有这么样一个或一些分区表的分区: this partition OR partitions的table所包含的全部 partitions不在一个表空间下面:

处理办法:
select 'alter table '||owner||'.'||segment_name||' drop partition '||partition_name||' ;'
  from dba_segments
 where segment_name in (select distinct segment_name
                          from dba_segments
                         where tablespace_name = 'CRM_ARC_DATA'
                           and segment_type like '%PART%')
   and tablespace_name <> 'CRM_ARC_DATA';

杀手锏: 直接drop 这个分区表(如果允许的话)

 

四. ORA-02449

 

--- ORA-02449: unique/primary keys in table referenced by foreign keys


drop tablespace crm_data including contents and datafiles
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys

意思是: 这个要删除的表空间 里面含有这么样的一些主键: 其他表空间的表在这些主键上建有外键

处理办法: 去掉这些垃圾外键

select 'alter table '||owner||'.'||table_name||' drop constraint '||constraint_name||' ;'
  from dba_constraints
 where constraint_type = 'R'
   and table_name in (select segment_name
                        from dba_segments
                       where tablespace_name = 'CRM_DATA'
                         and segment_type like '%TABLE%');
                        

如果还是不行的话,就用这个语句来删表空间吧:

drop tablespace crm_data including contents cascade constraints

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9719235/viewspace-571451/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9719235/viewspace-571451/

<think>我们正在解决的是ORA-39151错误,但用户提供的引用中并没有直接关于ORA-39151的信息。不过,根据Oracle错误文档,ORA-39151通常与表空间相关,具体错误信息可能为: ORA-39151: Table "string"."string" exists in the schema, but cannot be replaced/truncated because of IOT type or cluster. 或者 ORA-39151: Table "string"."string" exists. All dependent ancillary objects will be skipped but table statistics will be imported. 根据Oracle官方文档,ORA-39151错误通常发生在以下情况: 1. 导入过程中试图替换或截断一个索引组织表(IOT)或簇表,但操作不被允许。 2. 使用`TABLE_EXISTS_ACTION=REPLACE`或`TRUNCATE`时,对于IOT表或簇表,这些操作是不允许的。 解决方案: 1. 如果表是IOT或簇表,不能使用`REPLACE`或`TRUNCATE`选项,应该使用`APPEND`或`SKIP`。 2. 在导入前手动删除或截断这些表(如果允许)。 步骤: 1. 确定哪些表是IOT或簇表: ```sql SELECT table_name, iot_type, cluster_name FROM all_tables WHERE owner = 'YOUR_SCHEMA' AND (iot_type IS NOT NULL OR cluster_name IS NOT NULL); ``` 2. 修改impdp命令,对于这些表使用`TABLE_EXISTS_ACTION=APPEND`或`SKIP`,或者避免导入这些表(使用EXCLUDE参数)。 3. 如果选择手动处理,可以在导入前删除这些表,然后重新导入。 示例命令: ```bash impdp system/password directory=dpump_dir dumpfile=expdp.dmp remap_schema=source_schema:target_schema TABLE_EXISTS_ACTION=APPEND # 对于IOT和簇表,使用APPEND而不是REPLACE/TRUNCATE EXCLUDE=TABLE:"IN ('IOT_TABLE1','CLUSTER_TABLE1')" # 如果需要排除这些表,然后手动处理 ``` 4. 如果错误是由于导入统计信息时表已存在,可以尝试忽略统计信息: ```bash impdp ... EXCLUDE=TABLE_STATISTICS ``` 5. 如果表是簇表,可能需要先删除簇,然后重新导入。 注意:在删除表或簇之前,请确保有备份。 根据用户提供的引用,虽然没有直接关于ORA-39151的内容,但引用[3]提到了表空间扩展问题(ORA-01691),这与LOB段扩展有关,但与我们当前的问题无关。 因此,针对ORA-39151,我们主要处理IOT表和簇表的问题。 如果用户需要更详细的信息,建议参考Oracle官方文档关于ORA-39151的说明。 §§相关问题§§ 1. 如何判断一个表是索引组织表(IOT)或簇表? 2. 使用impdp导入时,TABLE_EXISTS_ACTION参数有哪些选项?分别适用于什么场景? 3. 如何排除导入特定表或表类型的对象?</think>### Oracle impdp报错 ORA-39151 解决方案 **错误说明** ORA-39151错误通常发生在impdp导入过程中,具体表现为: `ORA-39151: Table "string"."string" exists. All dependent ancillary objects will be skipped but table statistics will be imported.` 这表示目标库中已存在同名表,但impdp无法自动替换或处理依赖对象[^1]。 --- ### 错误原因分析 1. **表已存在冲突** - 目标库中已存在同名表 - 未正确处理`TABLE_EXISTS_ACTION`参数 - 索引组织表(IOT)或簇表特殊结构导致无法自动替换 2. **权限问题** - 用户缺少`DROP ANY TABLE`权限(替换表需要) - SYSDBA权限调用导致异常(如引用[1]警告) 3. **对象依赖关系** - 存在未清理的依赖对象(触发器、约束等) - LOB段扩展失败(如引用[3]的ORA-01691) --- ### 解决方案(逐步操作) #### 步骤1:验证表存在性 ```sql -- 查询冲突表 SELECT owner, table_name FROM all_tables WHERE table_name = '冲突表名'; ``` #### 步骤2:修改impdp命令参数 ```bash impdp system/password DIRECTORY=dpump_dir \ DUMPFILE=export.dmp \ REMAP_SCHEMA=source_schema:target_schema \ TABLE_EXISTS_ACTION=TRUNCATE \ # 或 REPLACE/APPEND TRANSFORM=SEGMENT_ATTRIBUTES:n \ LOGFILE=impdp_fix.log ``` **关键参数说明**: - `TABLE_EXISTS_ACTION`选项: - `TRUNCATE`:清空表数据(保留结构) - `REPLACE`:删除重建表(需DROP权限) - `APPEND`:追加数据(不修改结构) - `TRANSFORM=SEGMENT_ATTRIBUTES:n`:跳过存储属性导入 #### 步骤3:手动处理特殊对象 对于索引组织表(IOT)或簇表: 1. 手动删除冲突表: ```sql DROP TABLE target_schema.table_name FORCE PURGE; ``` 2. 重新执行impdp(使用`TABLE_EXISTS_ACTION=REPLACE`) #### 步骤4:处理LOB扩展问题 若伴随ORA-01691错误(如引用[3]): ```sql -- 扩大表空间 ALTER TABLESPACE users ADD DATAFILE '/path/newfile.dbf' SIZE 2G AUTOEXTEND ON; ``` #### 步骤5:权限修正 ```sql GRANT DROP ANY TABLE TO import_user; GRANT UNLIMITED TABLESPACE TO import_user; ``` --- ### 预防措施 1. **预清理环境**: ```sql BEGIN FOR t IN (SELECT table_name FROM all_tables WHERE owner='TARGET_SCHEMA') LOOP EXECUTE IMMEDIATE 'DROP TABLE ' || t.table_name || ' CASCADE CONSTRAINTS PURGE'; END LOOP; END; ``` 2. **使用元数据过滤器**: ```bash impdp ... TRANSFORM=OID:n,STORAGE:n # 跳过对象ID和存储属性 ``` 3. **导出时添加排除项**: ```bash expdp ... EXCLUDE=STATISTICS # 避免统计信息冲突 ``` > **重要提示**:避免使用SYSDBA执行导入(如引用[1]强调),普通用户更安[^1]。 --- ### 典型成功案例 ```bash # 修复簇表冲突 impdp mig_user/pwd DIRECTORY=dpump \ DUMPFILE=cluster.dmp \ REMAP_SCHEMA=src:dest \ TABLE_EXISTS_ACTION=REPLACE \ TRANSFORM=SEGMENT_ATTRIBUTES:n \ EXCLUDE=INDEX_STATISTICS,TABLE_STATISTICS ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值