我有2张桌子
主键 car_acc_idcar_acc
和
final_cost ,主键 car_acc_id 引用上一个。
我创建了2个日志:
CREATE MATERIALIZED VIEW LOG ON car_acc WITH PRIMARY KEY;
CREATE MATERIALIZED VIEW LOG ON final_cost WITH PRIMARY KEY ;
我选择PrimaryKey日志来解决ROW ID的导入/导出问题
然后我尝试在这些表上创建MATERIALIZED视图:
CREATE MATERIALIZED VIEW costs
BUILD IMMEDIATE
REFRESH FAST ON demand
AS SELECT ca.car_id, ca.acc_id,f.cost
FROM car_acc ca,final_cost f
WHERE ca.car_acc_id=f.car_acc_id;
但有例外:
"cannot fast refresh materialized view %s.%s"
*Cause: Either ROWIDs of certain tables were missing in the definition or
the inner table of an outer join did not have UNIQUE constraints on
join columns.
答案 0 :(得分:3)
你很近(并且例外确实记录了问题)。使用关于实例化视图的11g文档,在Materialized Views Containing Only Joins部分中没有聚合,您需要有一个包含rowid的物化视图日志。
因此,我将删除现有的物化视图日志并创建以下物化视图日志,如下所示:
CREATE MATERIALIZED VIEW LOG ON car_acc
WITH ROWID;
CREATE MATERIALIZED VIEW LOG ON final_cost
WITH ROWID;
另外(根据上面提到的链接),您需要在物化视图的select语句中添加rowid,如下所示:
CREATE MATERIALIZED VIEW costs
BUILD IMMEDIATE
REFRESH FAST ON demand
AS SELECT
ca.rowid car_rid, f.rowid f_rowid,
ca.car_id, ca.acc_id,f.cost
FROM car_acc ca,final_cost f
WHERE ca.car_acc_id=f.car_acc_id;