View is static SELECT query stored as database object.The tables or views used to create any view are termed as base tables or views. In other words, select statement are logical/virtual table which is accountable for collecting data from database tables and return as virtual table(virtual table because it can be used as database table- perform update and delete operation with some restriction).
Refer more details about syntax and semantics of view creation.
Materialized view is a database object that contains the results of a query not just query as contrast to view.The tables,views or materialized views used in FROM clause of the query are termed as master table and database where these objects exist are called materialized view.Refer following for general syntax of materialized view creation.
Comparison Views and materialized views :-
- View is just logical table-like structure (select query) populated on the fly, when the view query is executed. The results of a view query are not stored anywhere on disk and the view(logical table) is recreated every time the query is executed.
On the other hand materialized views are actual structures stored within the database and written to disk. It is populated based on clauses defined while creation.
- Views are non-indexed, since it is created from the underlying base table, however materialized views are indexed. so performance of views may be poor if join is not performed on non-indexed column of base table.Materialized views can be indexed because result set are actually stored in hard disk,so it can out perform views.
- Views are simple and less over head associated but less efficient. Materialized views are primarily used to increase application performance because of indexing support, a overhead associated with it is to keep it updated using trigger or some other method.
- Views always return updated result set from database tables or views, however materialized views gives result sets refreshed until last time.
- Join operation is a costly affair in database.In views all the joins are performed at the time view query is executed and it may degrade performance, if poorly join operation is performed. However, in materialized view join operation is carried out at refresh time.So, the cost of join operation is relatively less than views.(Order of number of times it is refreshed.)
- Incremental or fast refresh:- When DML statements are executed oracle database maintain materialized view log containing information about rows modified and if refresh operation is performed using materialized view log, it is termed as incremental or fast refresh.
- Complete refresh:- When without using materialized view logs refresh is performed, materialized query is executed again and this mechanism is termed as complete refresh.
- Force refresh:- When Force clause is used for refresh, it specify that, when a refresh occurs, Oracle Database will perform a fast refresh if possible(materialized log is existing) or a complete refresh if fast refresh is not possible.If we do not specify a refresh method (FAST, COMPLETE, or FORCE), then FORCE is the default.
1. Difference between View and Synonym in Oracle database.
2. Internals of PL/SQL execution in database server.