创建物化视图ON COMMIT时出错

时间:2015-08-07 07:32:48

标签: sql oracle oracle-sqldeveloper

我正在尝试像这样创建一个MATERIALIZED VIEW:

name:

下表:

CREATE MATERIALIZED VIEW MVProductStock 
BUILD IMMEDIATE
REFRESH FAST
ON COMMIT
AS
SELECT 
    IMP.PRODUCTID ID, 
    IMP.TOSTOCKID STOREID, 
    (IMP.TOTAL-COALESCE(EXP.TOTAL,0)) QUANTITY,
    SP.NAME,
    SP.COLOR,
    SP.WIDTH,
    SP.HEIGHT,
    SP.WEIGHT,
    SP.TYPE,
    SP.CATEGORY,
    SP.INTERNALREFERENCE,
    SP.EAN13BARCODE,
    SP.SALEPRICE,
    SP.WHOLESALEPRICE,
    SP.COSTPRICE,
    SP.COSTOUTSOURCE,
    SP.SALEBONUS,
    SP.MANUFACTUREBONUS,
    SP.UOM,
    SP.UOMPURCHASE,
    SP.PROCUREMENTMETHOD,
    SP.SUPPLYMETHOD,
    SP.MFACTLEADTIME,
    SP.STATUS,
    SP.PHOTO,
    SP.DESCRIPTION,
    SP.PARENTID,
    SP.TAXVATIN,
    SP.TAXVATOUT,
    SP.DEBIT,
    SP.CREDIT
FROM 
    (SELECT P1.PRODUCTID,
            SUM(P1.quantity) TOTAL,
            S1.TOSTOCKID
    FROM STOCKTRANSFERPRODUCT P1
    INNER JOIN STOCKTRANSFER S1 ON S1.ID = P1.STOCKTRANSFER
    GROUP BY P1.PRODUCTID, S1.TOSTOCKID) IMP
LEFT JOIN
    (SELECT P1.PRODUCTID,
            SUM(P1.quantity) TOTAL,
            S1.FROMSTOCKID
    FROM STOCKTRANSFERPRODUCT P1
    INNER JOIN STOCKTRANSFER S1
    ON S1.ID = P1.STOCKTRANSFER
    GROUP BY P1.PRODUCTID,S1.FROMSTOCKID) EXP 
ON IMP.TOSTOCKID = EXP.FROMSTOCKID AND IMP.PRODUCTID = EXP.PRODUCTID  
INNER JOIN PRODUCT SP ON SP.ID = IMP.PRODUCTID 
ORDER BY IMP.TOSTOCKID;

错误内容:

Table STOCKTRANSFER 
    ID  VARCHAR2(50 BYTE)
    TYPEID  NUMBER(10,0)
    STATUS  NUMBER(10,0)
    POSTDATE    DATE
    DUEDATE DATE
    NOTE    VARCHAR2(300 BYTE)
    SALEORDERID VARCHAR2(50 BYTE)
    PURCHASEORDERID VARCHAR2(50 BYTE)
    MANUFACTUREORDERID  VARCHAR2(50 BYTE)
    PARTNERID   VARCHAR2(20 BYTE)
    FROMSTOCKID VARCHAR2(20 BYTE)
    TOSTOCKID   VARCHAR2(20 BYTE)
    USERCREATED VARCHAR2(50 BYTE)
    DATECREATED TIMESTAMP(0)
    USERUPDATED VARCHAR2(50 BYTE)
    DATEUPDATED TIMESTAMP(0)
    COMPANYID   NUMBER(10,0)[/code]

 Table STOCKTRANSFERPRODUCT 
    ID  VARCHAR2(50 BYTE)
    STOCKTRANSFER   VARCHAR2(50 BYTE)
    PRODUCTID   VARCHAR2(20 BYTE)
    QUANTITY    NUMBER(38,2)

请告诉我如何修复此错误,以及执行我的MATERIALIZED VIEW的最佳方法,因为数据每秒都在更改。要快速刷新,我该如何创建MATERIALIZED VIEW LOG。

我是一个更新鲜的甲骨文,请帮助我。 非常感谢你。

1 个答案:

答案 0 :(得分:1)

快速刷新可能非常难以启用。快速刷新有many restrictions,而且并非所有文档都记录良好。

如果需要完全重写简单查询以启用快速刷新,请不要感到惊讶。对于此示例,FROM列表中所有表的Rowid必须出现在查询的SELECT列表中。

之后它可能仍然无法正常工作,您需要使用DBMS_MVIEW.EXPLAIN_MVIEW查看有关未启用快速刷新的原因的更多信息

创建MATERIALIZED VIEW LOG

的Oracle文档