1

我正在尝试在预建表的顶部构建一个物化视图。我可以使用以下不带修饰符的语法,并且效果很好。

CREATE MATERIALIZED VIEW TESTRESULT
ON PREBUILT TABLE
SELECT ...
FROM ...
WHERE ...

但是,当向物化视图添加额外的子句时,我收到错误“缺少关键字”。我不确定自己遗漏了什么,也无法在网上找到任何与在预建表之上构建添加额外子句相关的文档。

CREATE MATERIALIZED VIEW TESTRESULT
NOCACHE
LOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH FORCE ON DEMAND
WITH PRIMARY KEY
ON PREBUILT TABLE
AS 
SELECT ...
FROM ...
WHERE ...

甲骨文版本:10g

4

1 回答 1

4

The ON PREBUILT TABLE option is not compatible with some of your options, as described in the CREATE MATERIALIZED VIEW documentation:

  • The CACHE, LOGGING, PARALLEL and COMPRESS are table properties inherited from the already built table and are therefore incompatible with PREBUILT.
  • the BUILD option is there to specify when the table must be populated. However the table is already populated since you've used the PREBUILT option, and the two options are therefore incompatible.

Also make sure you have the arguments is the right order.

The following works:

SQL> CREATE TABLE TEST(ID NUMBER PRIMARY KEY);

Table created

SQL> CREATE TABLE testresult(ID NUMBER);

Table created

SQL> CREATE MATERIALIZED VIEW TESTRESULT
  2  ON PREBUILT TABLE
  3  REFRESH FORCE ON DEMAND
  4  WITH PRIMARY KEY
  5  AS
  6  SELECT ID
  7  FROM TEST;

Materialized view created
于 2011-06-09T15:32:43.323 回答