oracle between clause cause ORA-12015: cannot create a fast refresh materialized view 从一个复杂的查询

oracle between clause cause ORA-12015: cannot create a fast refresh materialized view from a complex query

我使用脚本成功创建了物化视图:

CREATE MATERIALIZED VIEW orderitem_mvmt
BUILD IMMEDIATE
REFRESH FAST
ON DEMAND
AS
select * from order_item;

为了提高性能我改成了这样

CREATE MATERIALIZED VIEW orderitem_mvmt
BUILD IMMEDIATE
REFRESH FAST
ON DEMAND
AS
select * from order_item
where to_char(last_upd,'yyyy') between to_char(sysdate,'yyyy')-3 and  to_char(sysdate,'yyyy')+3;

运行 脚本引发错误 ORA-12015: 无法从复杂查询创建快速刷新实体化视图

我不明白它是如何匹配快速刷新的Restrictions

谢谢。

看看General Restrictions on Fast Refresh

The defining query of the materialized view is restricted as follows:

  • The materialized view must not contain references to non-repeating expressions like SYSDATE and ROWNUM.

  • The materialized view must not contain references to RAW or LONG RAW data types.

  • It cannot contain a SELECT list subquery.

  • It cannot contain analytic functions (for example, RANK) in the SELECT clause.

  • It cannot contain a MODEL clause.

  • It cannot contain a HAVING clause with a subquery.

  • It cannot contain nested queries that have ANY, ALL, or NOT EXISTS.

  • It cannot contain a [START WITH …] CONNECT BY clause.

  • It cannot contain multiple detail tables at different sites.

  • ON COMMIT materialized views cannot have remote detail tables.

  • Nested materialized views must have a join or aggregate.

  • Materialized join views and materialized aggregate views with a GROUP BY clause cannot select from an index-organized table.

您的查询包含 SYSDATE 因此您不能将其用于 FAST REFRESH