ITPub博客

首页 > 数据库 > Oracle > drop物化视图log表导致insert、delete、update报ORA-00942

drop物化视图log表导致insert、delete、update报ORA-00942

原创 Oracle 作者:jx_yu 时间:2015-01-13 11:41:50 0 删除 编辑
之前基于emp表测试物化视图创建了 物化视图log表,测试完成后清理不用的表 直接drop table 物化视图log表,过段时间再用emp表的时候发现:
    select emp正常,但是insert、delete、update就报 ORA-00942: table or view does not exist

下面重现这个问题:
#创建物化视图log表在emp上
SQL> create materialized view log on emp  with rowid;
Materialized view log created.

SQL> select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
BONUS                          TABLE
DEPT                           TABLE
EMP                            TABLE
MLOG$_EMP                      TABLE
SALGRADE                       TABLE

#直接删除log表
SQL> drop table MLOG$_EMP purge;
Table dropped.
SQL> select * from tab;
TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
BONUS                          TABLE
DEPT                           TABLE
EMP                            TABLE
SALGRADE                       TABLE

#进行select、insert、update、delete操作:
SQL> select count(*) from emp;


  COUNT(*)
----------
        14

#发现insert、delete、update报ORA-00942
SQL> update emp set empno=empno+1;
update emp set empno=empno+1
       *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> delete emp where empno=7379;
delete emp where empno=7379
       *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> insert into emp(empno) values(1);
insert into emp(empno) values(1)
            *
ERROR at line 1:
ORA-00942: table or view does not exist

解决方法:
#查出dba_mview_logs中存在,而的log表不存在的对象
 select 'drop materialized view log on '||mvl.log_owner||'.'||mvl.master||';'  cmd  from dba_mview_logs mvl  where not exists  ( select table_name from dba_tables tab  where tab.owner = mvl.log_owner and tab.table_name = mvl.log_table  ) ;
CMD
--------------------------------------------------------------------------------
drop materialized view log on SCOTT.EMP;
#执行正确的删除 materialized view log  语句
SQL> drop materialized view log on SCOTT.EMP;
Materialized view log dropped.

#问题解决
SQL> delete emp where empno=7379;

1 row deleted.

SQL> rollback;

Rollback complete.


参考mos文章:
单击此项可添加到收藏夹 ORA-00942 when deleting from an existing Table after dropping materialized view log table (文档 ID 1912363.1) 转到底部转到底部

修改时间:2014-8-4类型:PROBLEM
为此文档评级 通过电子邮件发送此文档的链接 在新窗口中打开文档 可打印页

In this Document

Symptoms
Cause
Solution
References


APPLIES TO:

Oracle Database - Enterprise Edition - Version 11.2.0.3 and later
Information in this document applies to any platform.

SYMPTOMS

Delete from an existing table fails with ORA-942. The table exists in dba_objects view with valid status.

CAUSE

If a materialized view log table is dropped by a different method than "DROP MATERIALIZED VIEW LOG" it can cause DMLs over the source table to raise ORA-942 errors. 

 The call stack show the following functions :

kxtrcpy kntkca kntkcai kntclc

SOLUTION

Please use the below query to identify the Materialised view log:

 
SQL> select 'drop materialized view log on '||mvl.log_owner||'.'||mvl.master||';'  cmd  from dba_mview_logs mvl  where not exists  ( select table_name from dba_tables tab  where tab.owner = mvl.log_owner and tab.table_name = mvl.log_table  )  / 
  Sample output:
CMD -------------------------------------------------------------------------------- drop materialized view log on EDA_STD_REPORT_ADM.STATICREPORTS;
   

Drop the related materialized view log and then perform the other DML operation.

 

REFERENCES











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

上一篇: MongoDB安装
请登录后发表评论 登录
全部评论

注册时间:2012-05-23

  • 博文量
    80
  • 访问量
    876947