Definition• A database view is a logical or virtualtable based on a query.• It is useful to think of a view as a storedquery.• Views are created through use of a CREATEVIEW command that incorporates use ofthe SELECT statement.• Views are queried just like tables.
Display ViewSELECT * FROM <view name>;• Only columns in the query are thosedefined as part of the view
• OR REPLACE option is used to create a view thatalready exists. This option is useful formodifying an existing view without having todrop or grant the privileges that system usershave acquired with respect to the view .• If you attempt to create a view that alreadyexists without using the OR REPLACEoption, Oracle will return the ORA-00955: nameis already used by an existing object errormessage and the CREATE VIEW command willfail.
• The FORCE option allows a view to becreated even if a base table that the viewreferences does not already exist• NO FORCE option allows a system user tocreate a view if they have the requiredpermissions to create a view, and if thetables from which the view is createdalready exist. (Default Option)
• WITH READ ONLY option allows creationof a view that is read-only• WITH CHECK OPTION clause allows rowsthat can be selected through the view tobe updated• CONSTRAINT clause is used in conjunctionwith the WITH CHECK OPTION clause toenable a database administrator to assigna unique name to the CHECK OPTION
View Stability• A view does not actually store any data.The result table is only stored temporarily.• If a table that underlies a view isdropped, then the view is no longer valid.Attempting to query an invalid view willproduce an ORA-04063: view"VIEW_NAME" has errors error message.
INSERTING, UPDATING,ANDDELETINGTABLEROWSTHROUGHVIEWS• You can insert a row if the view in use isone that is updateable (not read-only).• A view is updateable if the INSERTcommand does not violate any constraintson the underlying tables.• This rule concerning constraint violationsalso applies to UPDATE and DELETEcommands.
ExampleCREATE OR REPLACE VIEW std_view ASSELECT std_no, std_name FROM student;INSERT INTO std_view VALUES (01, ‘Student01);INSERT INTO std_view VALUES (02, ‘Student02);SELECT * FROM std_view;
ExampleUPDATE std_view SET std_name = ‘Student 13‘WHERE std_no = 13;SELECT * FROM student WHERE std_no >= 5;
ExampleDELETE std_viewWHERE std_no = 15 OR std_no = 17;SELECT * FROM student;
Dropping View•A DBA or view owner can drop a viewwith the DROP VIEW command. Thefollowing command drops a viewnamed std_view.DROP VIEW std_view;
Summary• A view does not store data, but a view doesdisplay data through a SELECT query as if thedata were stored in the view.• A view definition as provided by the CREATEVIEW statement is stored in the database.• A view can simplify data presentation as well asprovide a kind of data security by limiting accessto data based on a "need to know."
Summary• A view can display data from more than one table.• Views can be used to update the underlying tables.Views can also be limited to read-only access.• Views can change the appearance of data. Forexample, a view can be used to rename columnsfrom tables without affecting the base table.• A view that has columns from more than one tablecannot be modified by an INSERT, DELETE, orUPDATE command if a grouping function, GROUPBY clause is part of the view definition.