Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Oracle Database View

758 views

Published on

Presentation about View in Oracle Database.
Advanced Database Lab - Informatics Engineering, Bakrie University

Published in: Technology, News & Politics
  • Be the first to comment

Oracle Database View

  1. 1. Oracle Database ViewEryk Budi Pratama – Dimas Aryo AnggoroAdvanced Database LabInformatics Engineering –Bakrie University
  2. 2. 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.
  3. 3. View SyntaxCREATE [OR REPLACE][FORCE|NOFORCE] VIEW <viewname> [(column alias name….)]AS <query> [WITH [CHECKOPTION] [READ ONLY][CONSTRAINT]];
  4. 4. ExampleCREATE VIEW student_list(id, last_name, first_name, email) ASSELECTstd_id, std_last_name, std_first_name, std_emailFROM studentORDER BY std_first_name;
  5. 5. Display ViewSELECT * FROM <view name>;• Only columns in the query are thosedefined as part of the view
  6. 6. • 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.
  7. 7. • 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)
  8. 8. • 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
  9. 9. 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.
  10. 10. 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.
  11. 11. 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;
  12. 12. ExampleUPDATE std_view SET std_name = ‘Student 13‘WHERE std_no = 13;SELECT * FROM student WHERE std_no >= 5;
  13. 13. ExampleDELETE std_viewWHERE std_no = 15 OR std_no = 17;SELECT * FROM student;
  14. 14. 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;
  15. 15. 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."
  16. 16. 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.
  17. 17. Q&A

×