ORA-12051 or ORA-12054 when Creating Local Materialized View

Doc ID: Note:101705.1 Type: PROBLEM
Last Revision Date: 24-APR-2006 Status: PUBLISHED


Problem Description
-------------------

You are trying to create a materialized view which refreshes automatically
when the underlying table is updated.
However, the create command fails with an ora-12051 or an ora-12054.
The select statement that you are using could be any of the following:

==============================================
create materialized view log on emp
with rowid(empno, ename, job, mgr, hiredate, sal, comm, deptno)
including new values
/
=============================================
create materialized view mv_emp_1
build immediate refresh fast on commit
as
select deptno, sum(sal), count(sal)
from emp
group by deptno
/

from emp
*
ERROR at line 5:
ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view

=============================================
or
=============================================
create materialized view mv_emp_1
build immediate refresh fast on commit
as
select deptno, sum(sal)
from emp
group by deptno
/
=============================================
from emp
*
ERROR at line 5:
ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view

=============================================
or
=============================================
The following will also give ora-12054:

create table t1 (col1 number, col2 number);
alter table t1 add primary key (col1);
create materialized view log on t1;

create table t2 (col1 number, col2 number);
alter table t2 add primary key (col1);
create materialized view log on t2;

drop materialized view mv1;
create materialized view mv1 build immediate refresh on commit as
select * from t1
union
select * from t2;


Solution Description
--------------------

The correct script for creation of this materialized view is as follows:
==============================================
create materialized view log on emp
with rowid(empno, ename, job, mgr, hiredate, sal, comm, deptno)
including new values
/
================================================
create materialized view mv_emp_1
build immediate refresh fast on commit
as
select count(*), deptno, sum(sal), count(sal)
from emp
group by deptno
/
================================================


Explanation
-----------

One of the mandatory requirements for creation of an on-commit materialized
view has not been satisfied.

ON-COMMIT :
Refresh occurs automatically when a transaction that modified one of the
materialized view's fact tables commits.
Can be used with materialized views on single table aggregates
and with materialized views containing joins only.


As can be seen from above, an ON-COMMIT can be used only under specific cases:
These are:

1. The M.V. should have a single table aggregate or
2. the M.V. should have a join only.
3. count(*) must be present for Single-Table Aggregates (see example above).
4. count() should be present.
Here, stands for the column which is being aggregated.
Note: the only time that count(col)is not required is when
the aggregate itself is a count(col).
5. It should be possible perform a fast refresh on the materialized view.

Fast refresh by itself has a few restrictions.
These are as follows:
a)The FROM list must contain base tables only (that is, no views).
b)It cannot contain references to non-repeating expressions like
SYSDATE and ROWNUM.
c)It cannot contain references to RAW or LONG RAW data types.
d)It cannot contain HAVING or CONNECT BY clauses.
e)The WHERE clause can contain only joins and they must be equi-joins
(inner or outer) and all join predicates must be connected with
ANDs. No selection predicates on individual tables are allowed
f)It cannot have subqueries, inline views, or set functions like
UNION or MINUS.


In addition for M.V.'s with Single-Table Aggregates and Materialized Views
with Joins and Aggregates, there are some more conditions on refresh
to the ones mentioned above:

Single Table Aggregates:
=======================
i) They can only have a single table.
ii) The SELECT list must contain all GROUP BY columns.
iii) Expressions are allowed in the GROUP BY and SELECT
clauses provided they are the same.
iv) They cannot have a WHERE clause.
v) They cannot have a MIN or MAX function.
vi) A materialized view log must exist on the table and must contain all
columns referenced in the materialized view. The log must have been
created with the INCLUDING NEW VALUES clause.
vii) If AVG(expr) or SUM(expr) is specified, you must have COUNT(expr).
viii) If VARIANCE(expr) or STDDEV(expr) is specified,
you must have COUNT(expr) and SUM(expr).

Joins and Aggregates :
=====================

i)The WHERE clause can contain inner equi-joins only
(that is, no outer joins)
ii)Materialized views from this category are FAST refreshable after
Direct Load to the base tables; they are not FAST refreshable after
conventional DML to the base tables.
iii)Materialized views from this category can have only the
ON DEMAND option (so, the on-commit cannot be used for this category).

References
----------

Oracle8i Data Warehousing Guide : A76994-01
Bug 888784

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

转载于:http://blog.itpub.net/193161/viewspace-50264/

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值