Description
You can execute the CREATE VIEW statement to create a view. If you add the OR REPLACE clause to the statement, you can execute the statement to replace an existing view.
Views are not stored as physical tables in databases. Views are generated each time you send a request to access the views. Views are created based on the outputs of the SELECT statements that are specified in the CREATE VIEW statements.
ApsaraDB for OceanBase V2.2.50 supports updatable views.
Syntax
create_view_stmt:
CREATE [OR REPLACE] VIEW view_name [(column_name_list)] AS select_stmt;
column_name_list:
column_name [, column_name ...]
Parameters
| Parameter | Description |
|---|---|
| OR REPLACE | Create the view again if it exists. You can use this clause to change the definition of an existing view. |
| view_name | The name of the view. |
| select_stmt | The SELECT statement. This statement defines the view by selecting data from base tables or other views. |
| column_name_list | In views, column names must be unique. This rule for views is the same as that for base tables. By default, the column names that are returned by the SELECT statement are used as the column names for the view. To specify the column names of the view, use the optional column_name_list clause. You can use this clause to specify the column names. Separate column names with commas (,). The number of the column names in the column_name_list clause must be equal to the number of columns that are returned by the SELECT statement. The columns that are returned by the SELECT statement can be the specified table columns. The columns that are returned by the SELECT statement can also store the computing results of the expressions that use functions, constant values, or operators. |
Examples
Create view v by using columns c1 and c2 in table t.
create or replace view v(vc1, vc2) as select c1, c2 from t;