一、错误描述
执行下面的语句删除表空间
drop tablespace COLA including contents and datafiles cascade constraint;
出现下面的错误信息
ERROR at line 1:
ORA-23515: materialized views and/or their indices exist in the tablespace
二、问题分析
ORA-23515: materialized views and/or their indices exist in the tablespace
错误解释:
ORA-23515错误表示在尝试删除一个表空间时,该表空间中存在物化视图或它们的索引。Oracle不允许在包含物化视图或相关索引的表空间被删除。
解决方法:
-
确定表空间中所有物化视图和索引的名称。
-
删除或者移动这些物化视图和索引。
-
如果物化视图和索引不再需要,可以选择删除它们。
-
在确保所有物化视图和索引被清除后,重新尝试删除原始表空间
三、解决办法
通过下面SQL查询表空间中所有物化视图和索引的名称
select table_name, tablespace_name from dba_tables where tablespace_name='COLA' and table_name in (select mview_name from dba_mviews);
通过下面SQL生成删除物化视图的SQL语句
select 'drop materialized view '||owner||'.'||segment_name||' ;' from dba_segments where segment_name in (select mview_name from dba_mviews) and tablespace_name = 'COLA';
去执行删除再查询表空间中所有物化视图和索引情况
最后执行删除表空间操作
SQL> drop tablespace COLA including contents and datafiles cascade constraint;
Tablespace dropped.
SQL>