A view is like a virtual table. It takes the output of a query and treats it like a table. We can
create, update, and drop a VIEW.
A view can be based on one or more tables or other views. These tables/views are called
base tables.
A view contains no data. All the data it shows comes from the base tables.
A view can provide an additional level of table security by restricting access to a set of
rows or columns of a table.
A view lets you change the data you can access, applying operators, aggregation
functions, filters etc. on the base table.
Syntax
SELECT column_name
FROM table_name
[WHERE conditions];
EXPLANATION:
view_name
The name of the Oracle VIEW that you wish to create.
WHERE conditions
This is Optional. The conditions that must be met for the records to be included in the
VIEW.
Example
SELECT s_name
FROM student
Output:
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
SELECT *
FROM student_view;
Syntax:
SELECT *
FROM table_name;
Example:
SELECT *
FROM student;
Note: We can do all DML commands like INSERT, UPDATE and DELETE in a view table,
All the changes that is made in a view table will affect the base table.
Query:
VALUES (6,'GEETHA','ETE','24-JAN-1991','THIRUNELVELI','D103');
OUTPUT:
TO DISPLAY THE DATA IN VIEW TABLE: VIEW TABLE IS ‘ student_view’
Query:
You can modify the definition of an Oracle VIEW without dropping it by using the Oracle
CREATE OR REPLACE VIEW Statement.
Syntax
SELECT columns
FROM table
WHERE conditions;
Example:
AS SELECT *
FROM student
WHERE s_address='COIMBATORE';
Output:
DROP VIEW
The DROP VIEW statement is used to remove or delete the VIEW completely.
Syntax:
Example:
Note: After dropping the view table data inside the base table remains same.