Oracle11G删除物化视图,oracle11g rename user导致物化视图失效的处理

本文详细介绍了在Oracle 11g中遇到的物化视图因数据库改名导致失效的问题。当试图删除失效的物化视图时,由于其summary信息仍然存在,导致删除操作失败。通过查询DBA_SUMMARIES并删除对应的summary信息,最终成功删除物化视图并重建。这个问题的解决对于理解Oracle数据库中物化视图的管理和维护具有重要意义。
摘要由CSDN通过智能技术生成

在上一篇文章中,已经点到了数据库改名时,引起该schema下物化视图会失效的问题。从表面上看,该物化视图是删也删不掉,那当然就无法重建了。以下是实验过程:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SQL> conn yyf123/yyf123

SQL> select s.owner,s.object_name,s.object_type,status from dba_objects  s  where object_name=‘EMP‘ ;

OWNER       OBJECT_NAME     OBJECT_TYPE STATUS

------------------------------ -----------------------------------------------------------

SCOTT EMP  TABLE VALID

SCOTT       EMP     MATERIALIZED VIEW   VALID

YYF123 EMP  TABLE VALID

YYF123       EMP     MATERIALIZED VIEW   INVALID

SQL> drop table emp purge;

ERROR at line 1:

ORA-12083: must use DROP MATERIALIZED VIEW to drop "YYF123"."EMP"

SQL> drop materialized view emp;

Materialized view dropped.

既然提示已经删除了物化视图,那尝试着重建一下看看

SQL>CREATE MATERIALIZED VIEW  emp

ON PREBUILT TABLE

REFRESH FORCE ON DEMAND

START WITH sysdate  NEXT SYSDATE + 10/1442

as

SELECT * FROM [email protected]_to_scott;

*

ERROR at line 1:

ORA-00955: name is already used by an existing object

虽然上面删除物化视图的命令已经成功执行,但是请看dba_objects里面还有记录,也就是说并没有真正的删除。

select s.owner,s.object_name,s.object_type,status from dba_objects  s  where object_name=‘EMP‘ ;

OWNER       OBJECT_NAME     OBJECT_TYPE STATUS

------------------------------ ------------------------------ ------------------- ----------

YYF123       EMP     TABLE VALID

YYF123       EMP     MATERIALIZED VIEW   INVALID

问题来了,就是因为存在对该物化视图的summary信息

SQL> select t.owner,t.summary_name,t.container_owner,t.container_name from dba_summaries t where owner=‘YYF123‘ ;

OWNER       SUMMARY_NAME     CONTAINER_OWNER    CONTAINER_NAME

------------------------------ ------------------------------ ------------------------------ ------------------------------

YYF123       EMP     YYF123    EMP

SQL> conn / as sysdba

SQL> drop summary yyf123.emp;    

接下来验证下是否已经清楚

SQL> select t.owner,t.summary_name,t.container_owner,t.container_name from dba_summaries t where owner=‘YYF123‘ ;

no rows selected

SQL>CREATE MATERIALIZED VIEW  emp

ON PREBUILT TABLE

REFRESH FORCE ON DEMAND

START WITH sysdate  NEXT SYSDATE + 10/1442

as

SELECT * FROM [email protected]_to_scott;

Materialized view created.

SQL> select count(*) from emp;

COUNT(*)

----------

14

SQL> exec dbms_mview.refresh(‘emp‘,‘c

PL/SQL procedure successfully completed.

到此为止,已经顺利解决。

reference:

http://dba.stackexchange.com/questions/4235/why-in-oracle-11gr2-i-cant-drop-the-materialized-view-with-the-same-user-that-c

DBA_SUMMARIES is ‘Description of the summaries accessible to dba‘;

DBA_SUMMARIES.OWNER is ‘Owner of the summary‘;

DBA_SUMMARIES.SUMMARY_NAME is ‘Name of the summary‘;

DBA_SUMMARIES.CONTAINER_OWNER is ‘Owner of the container table‘;

DBA_SUMMARIES.CONTAINER_NAME is ‘Name of the container table for this summary‘;

DBA_SUMMARIES.LAST_REFRESH_SCN is ‘The SCN of the last transaction to refresh the summary‘;

DBA_SUMMARIES.LAST_REFRESH_DATE is ‘The date of the last refresh of the summary‘;

DBA_SUMMARIES.REFRESH_METHOD is ‘User declared method of refresh for the summary‘;

DBA_SUMMARIES.SUMMARY is ‘Indicates the presence of either aggregation or a GROUP BY‘;

DBA_SUMMARIES.FULLREFRESHTIM is ‘The time that it took to fully refresh the summary‘;

DBA_SUMMARIES.INCREFRESHTIM is ‘The time that it took to incrementally refresh the summary‘;

DBA_SUMMARIES.CONTAINS_VIEWS is ‘This summary contains views in the FROM clause‘;

DBA_SUMMARIES.UNUSABLE is ‘This summary is unusable, the build was deferred‘;

DBA_SUMMARIES.RESTRICTED_SYNTAX is ‘This summary contains restrictive syntax‘;

DBA_SUMMARIES.INC_REFRESHABLE is ‘This summary is not restricted from being incrementally refreshed‘;

原文:http://www.cnblogs.com/yiyuf/p/4103915.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值