In the oracle docs I found that one can create materialized views with analytic functions:
If you use an analytic window function or the MODEL clause, the partition key column or the partition marker or ROWID or join dependent expression must be present in their respective PARTITION BY subclauses.
However, with the following example I always receive ORA-12052 "cannot fast refresh materialized view %s.%s".
I want to create a materialized view on a single table. I created a materialized view log on the underlying table, specified the rowid, and then created the materialized view containing the analytic function lead:
CREATE TABLE CUSTOMER_EVENT (
CUSTOMER_ID NUMBER NOT NULL,
EVENT_DATE DATE NOT NULL,
CUSTOMER_ATTR VARCHAR(30) NOT NULL,
PRIMARY KEY (CUSTOMER_ID, EVENT_DATE)
)
PARTITION BY HASH(CUSTOMER_ID)
PARTITIONS 4;
CREATE MATERIALIZED VIEW LOG ON CUSTOMER_EVENT
WITH ROWID (
CUSTOMER_ID,
EVENT_DATE
) INCLUDING NEW VALUES;
CREATE MATERIALIZED VIEW CUSTOMER_HISTORY
BUILD IMMEDIATE
REFRESH FAST ON COMMIT
ENABLE QUERY REWRITE
AS
SELECT
CUSTOMER_ID,
CUSTOMER_ATTR,
EVENT_DATE AS VALID_FROM,
NVL(LEAD(EVENT_DATE) OVER (
PARTITION BY
CUSTOMER_ID
ORDER BY
EVENT_DATE
), DATE'9999-12-31') AS VALID_TO
FROM
CUSTOMER_EVENT;
The last statement always fails with ORA-12052 "cannot fast refresh materialized view %s.%s".
Does anyone have a hint what I'm doing wrong?