Professional Documents
Culture Documents
2-Benefits of view?
3-Can we alter a view?
4-Where view is stored & why query fired on a view will run slower than a query fired on a base table?
5-When view is updateable?
6-Inline view & materialized view.
1- View –
The concept of view is very simple: Define a query that is going to be used frequently, store
it in the oracle database, and allow users to call it by name, as would a table.
.
A query fired on a view will run slower than a query fired on a base table. This is because
the view definition has to be retrieved from oracle’s system catalog, the base table has to be
identified and opened in memory and then the view has to be constructed on top of the
base table, suitably masking table columns. Only then will query actually execute and return
the active data set.
5-Some views are used only for looking at table data. Other views can be used to Insert
Update and Delete table data as well as view data.
If a view is used to only look at table data and nothing else the view is call a Read-only
view.
A view that is used to look at table data as well as Insert, Update and delete table data is
called an updateable view.
For a view to be updateable (DML operations), it should meet the following criteria:
If a view is created from multiple tables, which were not created using a Reference clause
(Logical linkage exists between the tables), even though the PRIMARY KEY column(s) as
well as the NOT NULL columns are included in the view definition the view’s behaviour will
be as follows:
The INSERT, UPDATE or DELETE operation is not allowed.
In an inline view construct, instead of specifying table name(s) after the FROM keyword, the source of the
data actually comes from the inline view.
In the FROM clause, you can specify a table from which you want to query data. Besides a table, you
can use a subquery as shown in the following example:
1 SELECT
2 category_name,
3 max_list_price
4 FROM
5 product_categories a,
6 (
7 SELECT
8 category_id,
9 MAX( list_price ) max_list_price
10 FROM
11 products
12 GROUP BY
13 category_id
14 ) b
15 WHERE
16 a.category_id = b.category_id
17 ORDER BY
18 category_name;
In this example, the inline view returns the category id list and the highest list
price of product in each category. The outer query joins the inline view with
the product_categories table to get the category name.
What is a Materialized View?
When a materialized view is fast refreshed, Oracle must examine all of the changes to the master
table or master materialized view since the last refresh to see if any apply to the materialized
view.
Therefore, if any changes where made to the master since the last refresh, then a materialized view
refresh takes some time to apply the changes to the materialized view. If, however, no changes at all
were made to the master since the last refresh of a materialized view, then the materialized view
refresh should be very quick.
You can make a materialized view read-only during creation by omitting the FOR UPDATE clause
In addition, using read-only materialized views eliminates the possibility of a materialized view
introducing data conflicts at the master site or master materialized view site, although this
convenience means that updates cannot be made at the remote materialized view site. The
following is an example of a read-only materialized view:
You can make a materialized view updatable during creation by including the FOR UPDATE clause.
For changes made to an updatable materialized view to be pushed back to the master during
refresh, the updatable materialized view must belong to a materialized view group.
Updatable materialized views enable you to decrease the load on master sites because users can
make changes to the data at the materialized view site. The following is an example of an updatable
materialized view:
Materialized views are objects that are reduced sets of information that have been
summarized, grouped, or aggregated from base tables. They are typically used in data
warehouse or decision support systems.