View

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

VIEW

 View is a logical/virtual table that does not exist in the database


and stored in oracle data dictionary.
 View stores SQL statement/queries in the database.
 It will not hold any data of its own instead it will retrieves/fetches the data from the
base table/view whenever it is required.
 A view will looks and acts like a table.
 No data is stored in the view.
ADVANTAGES;
 To makes complex query to look simple.
 View used to increase the security.
TYPES OF VIEW
1. SIMPLE VIEW
2. COMPLEX VIEW.
3. FORCE VIEW
--SIMPLE VIEW—
o If a view created based on single table.
o It should not have any group functions, aggregate functions,etc..
o It should not contain distinct keyword or any Pseudo columns
expression on the based columns.
o DML operators are allowed.
SYNTAX;
Create [or replace]view view_name as select select_query;
Example;
create view view1 as select first_name,salary from emp;
Output;

select*from view1; DML Operations allowed.


update view1 set salary=25000 where
first_name='Steven';
COMPLEX VIEW
If the select clause has any Distinct keywords,aggregate functions
Or analytic functions.
If the select clause use set operators.
If the select clause use subqueries,joins,functions.
Use the group by,having,orderby start with clause.
contain pseudo columns or expressions.
If the querry use the Data Dictionary table.
Example;
create view view2 as
select department_id,max(salary) max_salary from emp
group by department_id;
Output ;
Select*from view2; DML operations not allowed.
delete from view2 where
department_id=100;
View with read only;
• Used to restrict insert and update performed through the view.
• Only select statement is allowed against the view.

Syntax;
create or replace view view_name as select select_query
With read only;
Example:
create view view1 as select first_name,salary
from emp with read only;

update view1 set salary=25000 where first_name='Steven';


View with check option

• Where clause is mandatory for check option.


• Used to allow DML operation based on the check condition through
the view.

SYNTAX;
Create or replace view view_name as select select_query
With check option;
Example
create view view1 as select first_name,salary from emp where salary
between 5000 and 12000 with check option;

update view1 set salary=13000 where first_name='Bruce';

update view1 set salary=11000 where first_name='Bruce';


FORCE VIEW
• Creating a view without having base table.

• Syntax:
create or replace Force view view_name as select select_querry;
example:
create force view view2 as select movies,movies_name from movie;

You might also like