我想创建 m-view 来保存交易历史中的现金汇总。
查询如下。
CREATE MATERIALIZED VIEW MV_CASH_STATS
BUILD IMMEDIATE REFRESH FAST ON DEMAND
AS
( -- Total aggregates
SELECT
'total' AS CODE
, COUNT(T.CASH_IN) AS DEPOSITS
, COUNT(T.CASH_OUT) AS WITHDRAWS
, SUM(T.CASH_IN) AS DEPOSIT
, SUM(T.CASH_OUT) AS WITHDRAW
FROM
TB_CASH_LOG T
)
UNION ALL
( -- Aggregates by account grades
SELECT
'grade-' || T1.GRADE AS CODE
, COUNT(T.CASH_IN) AS DEPOSITS
, COUNT(T.CASH_OUT) AS WITHDRAWS
, SUM(T.CASH_IN) AS DEPOSIT
, SUM(T.CASH_OUT) AS WITHDRAW
FROM
TB_CASH_LOG T
INNER JOIN TB_ACCOUNT T1 ON
T.ACCOUNT_ID = T1.ID
GROUP BY T1.GRADE
)
当我执行此操作时,会发生以下错误。
> ORA-12015: cannot create a fast refresh materialized view from a complex query
TB_CASH_LOG
(我为和都创建了 m-view 日志表TB_ACCOUNT
)
Total aggregates
部分没问题,但后面的部分 - -Aggregates by account grades
出错了。
我已阅读Oracle basic materialized view docs,并认为INNER JOIN
orGROUP BY
是错误点。
如果是真的,用and快速刷新m-view是不可能的?
我的 m-view 声明 sql 有什么问题?inner join
group by
ps我正在使用oracle 18c