ads

Sunday, September 4, 2016

What is View in PL SQL




A view is a oracle database object, it can be created from one or Multiple tables or combination of  multiple tables and views . These tables are called base tables.
View is also called as virtual table or Logical table.
View always displays the output of a query which written during create a view. We can say
Views display all the data from the base tables. 
View takes only the definition of view and query which is associate with view. That information stored in the data dictionary.
That is the main reason creating a view does not take much storage space in database.

Why we need to create a view.

Suppose you have a bank Customer table which have different branches of data like Mumbai, Delhi Indore, Hyderabad, Chennai.

In this one table you have all customers records like Customer name, account no, amount, city, branch etc .
 These all customer related data only branch manager can access and modify on customer table.
but here we store all data in one customer table so any Branch manager can see and modify  other branches of data. 

Now you have a requirement that manager can see and modify only respective branch of customers data not other then else.

Means branch of Mumbai manager can access and modify only Mumbai customer’s data not other then else.

For this kind of requirement you don’t need to create separate database tables for all branches.
You only need to create View for each Branches on customer table and give access to respective branches Managers.

It means
Using view you can provide an additional level of table security by restricting access to a set of rows and columns of a table.

I hope friends here get clear idea about views and why we need to create view.
Now how to create view.
Creating a view is very simple.
Let’s take a look on view syntax.
CREATE or REPLACE VIEW view_name AS
 SOURCE QUERY
Or
CREATE  VIEW view_name AS
SELECT column_name(s) FROM table_name
WHERE condition

What are Advantages of views?

1.  View does not take much space on database.
2. View provides additional level of table security by hide some of columns and rows in the tables.
3. View can also create to show Summarize data from various tables which can be used to generate reports.
4. Restrict the access of a table so that nobody can insert the rows into the table.
5. Simplify Complex Queries  

No comments:

Post a Comment