This post is in response to Metalized view by MAhmad
A view is a logical entity. It is a SQL statement stored in the database in the system tablespace. It can used in much the same way as database table. When ever query is fired against it database taked the stored SQL statement and creates a table in memory and the temporary table.
As per my understanding and experience I have seen the use of VIEWS in two situtations:
- Hide complexity of a SQL statement
Example: I need to design 10 report based on 3 tables. All reports are based on same set of data which drive from union between the 3 tables but different WHERE clause. Instead of writing the Union SQL in all 10 reports, I will simply create a view based on that SQL, and then use that view to create report with different WHERE clause.
- Security Purpose
Example: I have table with different company data in it. I need to restrict access of user to his company data only. For this I can create a package with company variable in it (Set at the time of user choose the company) and then create view with WHERE clause as company equal to package company variable.
One of the defination that I found:
Materialized Views(also known as snapshots in prior releases) is a pre-computed table comprising aggregated or joined data from fact and possibly dimension tables. Also known as a summary or aggregate table.
It improves query performance by precalculating expensive join and aggregation operations on the database prior to execution and storing the results in the database. The query optimizer automatically recognizes when an existing materialized view can and should be used to satisfy a request. It then transparently rewrites the request to use the materialized view. Queries go directly to the materialized view and not to the underlying detail tables. In general, rewriting queries to use materialized views rather than detail tables improves response.
While views are stored in the database as a SQL statement and are created as needed, a materialized view is created as a table, and physically stored in the database.