Skip Headers
Oracle® TimesTen In-Memory Database SQL Reference
Release 11.2.1

Part Number E13070-03
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

CREATE MATERIALIZED VIEW

The CREATE MATERIALIZED VIEW statement creates a view of the table specified in the SelectQuery clause. The original tables used to create a view are referred to as "detail" tables. The view can be refreshed synchronously or asynchronously with regard to changes in the detail tables. If you create an asynchronous materialized view, you must first create a materialized view log on the detail table. See "CREATE MATERIALIZED VIEW LOG".

Required privilege

SQL syntax

CREATE MATERIALIZED VIEW ViewName
      [REFRESH 
        [FAST | COMPLETE]
        [NEXT SYSDATE[+NUMTODSINTERVAL(IntegerLiteral),IntervalUnit]]
      AS SelectQuery
      [PRIMARY KEY (ColumnName [,…])] 
      [UNIQUE HASH ON (HashColumnName [,…]) 
      PAGES = PrimaryPages]

Parameters

The CREATE MATERIALIZED VIEW statement has the parameters:

Parameter Description
ViewName Name assigned to the new view.
REFRESH Specifies an asynchronous materialized view.
[FAST | COMPLETE] Refresh methods. FAST specifies incremental refresh. COMPLETE specifies full refresh. If the method is omitted, COMPLETE is the default refresh method.
NEXT SYSDATE If NEXT SYSDATE is specified without NUMTODSINTERVAL, the materialized view will be refreshed incrementally every time a detail table is modified. The refresh occurs in a separate transaction immediately after the transaction that modifies the detail table has been committed. You cannot specify a full refresh (COMPLETE) every time a detail table is modified.

If NEXT SYSDATE is omitted, then the materialized view will not be refreshed automatically. It must be refreshed manually.

[+NUMTODSINTERVAL(IntegerLiteral),IntervalUnit] If this is specified, the materialized view will be refreshed at the specified interval. IntegerLiteral must be an integer. IntervalUnit must be one of the following values: 'DAY', 'HOUR', 'MINUTE', 'SECOND'.

If [NEXT SYSDATE[+NUMTODSINTERVAL(IntegerLiteral),IntervalUnit] is not specified, the materialized view will not be refreshed automatically. You can manually refresh the view by using the REFRESH MATERIALIZED VIEW statement.

SelectQuery Selects column from the detail tables to be used in the view. Can also create indexes on the view.
ColumnName Name of the column(s) that forms the primary key for the view to be created. Up to 16 columns can be specified for the primary key. Each result column name of a viewed table must be unique. The column name definition cannot contain the table or owner component.
HashColumnName Column defined in the view that is to participate in the hash key of this table. The columns specified in the hash index must be identical to the columns in the primary key.
PrimaryPages Specifies the expected number of pages in the table. This number determines the number of hash buckets created for the hash index. The minimum is 1. If your estimate is too small, performance is degraded. See "CREATE TABLE" section for more information.

Description

Restrictions on synchronous materialized view and detail tables:

There are several restrictions on the query that is used to define the materialized view:

There are no additional restrictions on asynchronous materialized views with full (COMPLETE) refresh.

In addition to the restrictions in a SELECT statement that is creating a materialized view, the following restrictions apply when creating asynchronous materialized views with incremental (FAST) refresh:

Examples

Create a materialized view of columns from the customer and bookorder tables.

CREATE MATERIALIZED VIEW custorder AS
  SELECT custno, custname, ordno, book
    FROM customer, bookorder
    WHERE customer.custno=bookorder.custno;

Create a materialized view of columns x1 and y1 from the t1 table.

CREATE MATERIALIZED VIEW v1 AS SELECT x1, y1 FROM t1
  PRIMARY KEY (x1) UNIQUE HASH (x1) PAGES=100;

Create a materialized view from an outer join of columns x1 and y1 from the t1 and t2 tables.

CREATE MATERIALIZED VIEW v2 AS SELECT x1, y1 FROM t1, t2
  WHERE x1=x2(+);

Create an asynchronous materialized view called mv1 with incremental refresh. The materialized view will be refreshed immediately after updates to employees have been committed. The columns in mv1 are employee_id and email. (You must create a materialized view log before you create an asynchronous materialized view.)

CREATE MATERALIZED VIEW mv1 
  REFRESH FAST NEXT SYSDATE 
  AS SELECT employee_id, email FROM employees;
107 rows materialized.

See also


CREATE MATERIALIZED VIEW LOG
CREATE TABLE
CREATE VIEW
DROP [MATERIALIZED] VIEW
REFRESH MATERIALIZED VIEW