This Oracle tutorial explains how to create, update, and drop Oracle VIEWS with syntax and examples.
An Oracle VIEW, in essence, is a virtual table that does not physically exist. Rather, it is created by a query joining one or more tables.
The syntax for the CREATE VIEW Statement in Oracle/PLSQL is:
The name of the Oracle VIEW that you wish to create.
Optional. The conditions that must be met for the records to be included in the VIEW.
Here is an example of how to use the Oracle CREATE VIEW:
This Oracle CREATE VIEW example would create a virtual table based on the result set of the SELECT statement. You can now query the Oracle VIEW as follows:
You can modify the definition of an Oracle VIEW without dropping it by using the Oracle CREATE OR REPLACE VIEW Statement.
The syntax for the CREATE OR REPLACE VIEW Statement in Oracle/PLSQL is:
The name of the Oracle VIEW that you wish to create or replace.
Here is an example of how you would use the Oracle CREATE OR REPLACE VIEW Statement:
This Oracle CREATE OR REPLACE VIEW example would update the definition of the Oracle VIEW called sup_orders without dropping it. If the Oracle VIEW did not yet exist, the VIEW would merely be created for the first time.
Once an Oracle VIEW has been created, you can drop it with the Oracle DROP VIEW Statement.
The syntax for the DROP VIEW Statement in Oracle/PLSQL is:
The name of the view that you wish to drop.
Here is an example of how to use the Oracle DROP VIEW Statement:
This Oracle DROP VIEW example would drop/delete the Oracle VIEW called sup_orders.
Question: Can you update the data in an Oracle VIEW?
Answer: A VIEW in Oracle is created by joining one or more tables. When you update record(s) in a VIEW, it updates the records in the underlying tables that make up the View.
So, yes, you can update the data in an Oracle VIEW providing you have the proper privileges to the underlying Oracle tables.
Question: Does the Oracle View exist if the table is dropped from the database?
Answer: Yes, in Oracle, the VIEW continues to exist even after one of the tables (that the Oracle VIEW is based on) is dropped from the database. However, if you try to query the Oracle VIEW after the table has been dropped, you will receive a message indicating that the Oracle VIEW has errors.
If you recreate the table (the table that you had dropped), the Oracle VIEW will again be fine.