Views and Base Tables (243)

tsinglee發表於2007-11-24

A view depends on the base tables or views referenced in its defining query. If the
defining query of a view is not explicit about which columns are referenced, for
example, SELECT * FROM table, then the defining query is expanded when stored
in the data dictionary to include all columns in the referenced base table at that time.

If a base table or view of a view is altered, renamed, or dropped, then the view is
invalidated, but its definition remains in the data dictionary along with the privileges,
synonyms, other objects, and other views that reference the invalid view.

Note: Whenever you create a table, index, and view, and then drop
the table, all objects dependent on that table are invalidated, including
views, packages, package bodies, functions, and procedures.

An attempt to use an invalid view automatically causes Oracle to recompile the view
dynamically. After replacing the view, the view might be valid or invalid, depending
on the following conditions:
■ All base tables referenced by the defining query of a view must exist. If a base
table of a view is renamed or dropped, the view is invalidated and cannot be used.
References to invalid views cause the referencing statement to fail. The view can
be compiled only if the base table is renamed to its original name or the base table
is re-created.

■ If a base table is altered or re-created with the same columns, but the datatype of
one or more columns in the base table is changed, then most dependent views can
be recompiled successfully.

■ If a base table of a view is altered or re-created with at least the same set of
columns, then the view can be validated. The view cannot be validated if the base
table is re-created with new columns and the view references columns no longer
contained in the re-created table. The latter point is especially relevant in the case
of views defined with a SELECT * FROM table query, because the defining
query is expanded at view creation time and permanently stored in the data
dictionary.

檢視和基表

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10599713/viewspace-983759/,如需轉載,請註明出處,否則將追究法律責任。

相關文章