All Products
Search
Document Center

CREATE VIEW

Last Updated: Jun 18, 2021

Description

The CREATE VIEW statement creates a view. If you specify an OR REPLACE clause, you can execute the statement to replace an existing view.

Views actually do not exist in the form of tables in databases and are derived each time the views are used. A view is generated from the result of the SELECT statement that is specified in the CREATE VIEW statement.

Updatable views are supported.

Syntax

create_view_stmt:
  CREATE [OR REPLACE] VIEW view_name [(column_name_list)] AS select_stmt;

column_name_list:
    column_name [, column_name ...]

Parameter description

Parameter

Description

OR REPLACE

Specifies that if the name of the view to be created already exists, the view is recreated based on the new definition.

view_name

The name of the view.

select_stmt

A type of SELECT statements. It defines a view. This statement can select data from base tables or other views.

column_name_list

The view must have unique column names and do not have duplicate column names. This rule is the same as that for base tables. By default, the column names that are retrieved by the SELECT statement are used as the column names for the view.

To specify the column names of the view, you can use the optional column_name_list clause and list comma-separated IDs. The number of the column names in the column_name_list clause must be equal to the number of columns that are retrieved by the SELECT statement.

The columns that are retrieved by the SELECT statement can be simple references to table columns. They can also be expressions that use functions, constant values, and operators.

Examples

  • Select columns c1 and c2 from table t to create a view named v.

create or replace view v(vc1, vc2) as select c1, c2 from t;