如果我的物化日志是在视图的基表上创建的,是否可以基于快速刷新获得实时物化视图?

时间:2020-01-28 21:40:15

标签: oracle oracle12c materialized-views

我想基于一个查询来创建一个具有每日快速刷新的实时实例化视图,该查询从3个表(PS_JOB,PS_DEPT_TBL,PSOPRDEFN)和1个视图(PS_NPS_LICCERT_VW)中获取字段。查询/过程看起来像这样。


CREATE MATERIALIZED VIEW LOG ON PS_JOB;

CREATE MATERIALIZED VIEW LOG ON PS_NPS_LICCERT_VW

CREATE MATERIALIZED VIEW LOG ON PSOPRDEFN

CREATE MATERIALIZED VIEW LOG ON PS_DEPT_TBL


CREATE MATERIALIZED VIEW ALL_EMP_CERTS
BUILD IMMEDIATE
REFRESH FAST
START WITH to_date   ('28-JAN-20','DD-MON-RR') --start on this date
NEXT sysdate +1               --next refresh every 1 days 
 AS 
 SELECT DISTINCT(A.EMPLID),E.OPRID,E.OPRDEFNDESC,B.JPM_DESCR90,B.JPM_DATE_3,B.JPM_DATE_6,H.DESCR,H.LOCATION FROM PS_JOB@PEOPLESOFT A
LEFT OUTER JOIN PS_NPS_LICCERT_VW@PEOPLESOFT B ON A.EMPLID=B.EMPLID 
LEFT OUTER JOIN PSOPRDEFN@PEOPLESOFT E ON A.EMPLID=E.EMPLID
LEFT OUTER JOIN PS_DEPT_TBL@PEOPLESOFT H ON A.DEPTID=H.DEPTID
  WHERE  a.EFFDT = (SELECT MAX(e.EFFDT) FROM PS_JOB@PEOPLESOFT e
        WHERE E.EFFDT <= sysdate
        and e.emplid = a.emplid
        and e.empl_rcd = A.EMPL_RCD)
        AND a.EFFseq = (SELECT MAX(f.EFFseq) FROM PS_JOB@PEOPLESOFT f
        WHERE f.EFFDT = a.effdt
        and f.emplid = a.emplid
        and f.empl_rcd = A.EMPL_RCD)
        AND A.PER_ORG = 'EMP'
        AND a.paygroup not in ('SUM','CWR')
        AND A.EMPL_STATUS in ('A', 'L', 'P', 'S');

但是,由于其视图,我无法在PS_NPS_LICCERT_VW上创建物化日志,并且尝试时出现以下错误


CREATE MATERIALIZED VIEW LOG ON PS_NPS_LICCERT_VW
Error report -
ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action

我希望问是否还有另一种方法可以基于相同的源表/视图创建快速的物化视图。我可以在视图的基表上创建实例化日志吗?即PS_NPS_LICCERT_VW,在这种情况下,它将包括表PS_JPM_PROFILE,PS_JPM_JP_ITEMS,PS_JPM_CAT_TYPES和PS_JPM_CAT_ITEMS,然后创建具有快速刷新的快照,以希望基表上的日志将记录所有更改。如果我尝试这样做,我的查询将如下所示

--Creating the materialized logs for PS_NPS_LICCERT_VW base tables
CREATE MATERIALIZED VIEW LOG ON PS_JPM_PROFILE ; 
CREATE MATERIALIZED VIEW LOG ON PS_JPM_JP_ITEMS ; 
CREATE MATERIALIZED VIEW LOG ON PS_JPM_CAT_TYPES ;
CREATE MATERIALIZED VIEW LOG ON PS_JPM_CAT_ITEMS ;

--Creating materialized views on the other 3 original tables

CREATE MATERIALIZED VIEW LOG ON PS_JOB;

CREATE MATERIALIZED VIEW LOG ON PS_PSOPRDEFN;

CREATE MATERIALIZED VIEW LOG ON PS_DEPT_TBL;

--- Creating my materialized view
CREATE MATERIALIZED VIEW ALL_EMP_CERTS
BUILD IMMEDIATE
REFRESH FAST
START WITH to_date   ('28-JAN-20','DD-MON-RR') --start on this date
NEXT sysdate +1               --next refresh every 1 days 
 AS 
 SELECT DISTINCT(A.EMPLID),E.OPRID,E.OPRDEFNDESC,B.JPM_DESCR90,B.JPM_DATE_3,B.JPM_DATE_6,H.DESCR,H.LOCATION FROM PS_JOB@PEOPLESOFT A
LEFT OUTER JOIN PS_NPS_LICCERT_VW@PEOPLESOFT B ON A.EMPLID=B.EMPLID 
LEFT OUTER JOIN PSOPRDEFN@PEOPLESOFT E ON A.EMPLID=E.EMPLID
LEFT OUTER JOIN PS_DEPT_TBL@PEOPLESOFT H ON A.DEPTID=H.DEPTID
  WHERE  a.EFFDT = (SELECT MAX(e.EFFDT) FROM PS_JOB@PEOPLESOFT e
        WHERE E.EFFDT <= sysdate
        and e.emplid = a.emplid
        and e.empl_rcd = A.EMPL_RCD)
        AND a.EFFseq = (SELECT MAX(f.EFFseq) FROM PS_JOB@PEOPLESOFT f
        WHERE f.EFFDT = a.effdt
        and f.emplid = a.emplid
        and f.empl_rcd = A.EMPL_RCD)
        AND A.PER_ORG = 'EMP'
        AND a.paygroup not in ('SUM','CWR')
        AND A.EMPL_STATUS in ('A', 'L', 'P', 'S');


或者在这种情况下我是否必须依靠按需完成刷新?在这种情况下,以下查询足以每天刷新一次



create materialized view ALL_EMP_CERTS_Refresh_Daily
refresh on demand 
start with sysdate next sysdate + 1
as SELECT DISTINCT(A.EMPLID),E.OPRID,E.OPRDEFNDESC,B.JPM_DESCR90,B.JPM_DATE_3,B.JPM_DATE_6,H.DESCR,H.LOCATION FROM PS_JOB@PEOPLESOFT A
LEFT OUTER JOIN PS_NPS_LICCERT_VW@PEOPLESOFT B ON A.EMPLID=B.EMPLID 
LEFT OUTER JOIN PSOPRDEFN@PEOPLESOFT E ON A.EMPLID=E.EMPLID
LEFT OUTER JOIN PS_DEPT_TBL@PEOPLESOFT H ON A.DEPTID=H.DEPTID
  WHERE  a.EFFDT = (SELECT MAX(e.EFFDT) FROM PS_JOB@PEOPLESOFT e
        WHERE E.EFFDT <= sysdate
        and e.emplid = a.emplid
        and e.empl_rcd = A.EMPL_RCD)
        AND a.EFFseq = (SELECT MAX(f.EFFseq) FROM PS_JOB@PEOPLESOFT f
        WHERE f.EFFDT = a.effdt
        and f.emplid = a.emplid
        and f.empl_rcd = A.EMPL_RCD)
        AND A.PER_ORG = 'EMP'
        AND a.paygroup not in ('SUM','CWR')
        AND A.EMPL_STATUS in ('A', 'L', 'P', 'S');




0 个答案:

没有答案