Skip to main content

Views and Types of View in Oracle #Diksha Oracle Training Centre

                              Views and Types of View in Oracle.

 

Hello Everyone,

In this blog I will discuss about Views and types of Views in Oracle Database .Views plays very important role in database as  Views are Virtual table that can be created from existing or base table. A view can be known as a ‘Stored Query’ or a “Virtual Table”. Views mainly used for security purpose and view used in most places where a table can be used. The table from which view is created are called based table. We can query view just like a table , but views doesn’t required disk space. A view representing a subset of the data present in a table, and performing functions such as joining and simplification of multiple tables into a single table, data aggregation, handling data complexity, providing security etc.

A view can be created by SQL DDL create command i.e Create view statement

View can be created from single base table or can be created from multiple tables by using joins, aggregate function etc. So we divide view into Different Parts.

 

1. Simple View : We can create simple view from one base table :

Syntax is as below

Create view sec_view as select ID, Name from student

Where ID between 1 and 5;

insert into sec_view values(2,'Dheeraj Jha');

update sec_view set name ='Diksha Jha' where ID=2;

Note :  Here we selected only 2 columns that is ID and name , In Simple View we can able to do DML operation i.e. Insert , Update and delete but for the same record only not new one. Important thing in this view is that we can’t manipulate data if that ID or record is not in view or base table. In complex view we can’t to any DML operation .

We can see the view by using simple select statement as below :

Select * from sec_view;

Below is the output of above Syntax:

 


Note : Here sec_view doesn’t required disk space in database.

We can drop the view by using below Syntax:

Drop view sec_view;

 

2 .  Complex View : In Complex view  we can take multiple tables by using joins/subquery and can use several conditions , functions etc. In complex view we cannot do any DML i.e. Insert , update and delete operation so basically used for security purpose .

Note : You will also not able to select  ROWID in complex view .

Let Assume we have 2 tables which we created in my previous  Join blog i.e Student and Student_details table . Now we can create 1 view from both the tables by using joins :

Syntax is as below :

Create view student_sec as Select a.name , a. Id , b.address from student a , student_details b where a.id =b.id ;

// insertion of complex view throw the error

insert into student_sec values('Diksha Jha',2,'DBG');

//Deletion of Complex view throw the error.

delete from student_sec;

To see the data we simply use below select statement.

Select * from student_sec;

Output of above query is as below :

 


Here in one View we have data from two tables and three columns i.e name , id and address with matching records from both the tables so if we want to see the matching records from both tables we simply select this view student_sec and get the data  , no need to make joins from 2 tables also as per our requirement we can create view with multiple base tables. Also the view doesn’t required disk space in database so it’s good for performance as well as it’s not hitting the table while selecting the view.

Note : We cannot  do DML operations in view with commands like insert, update and delete .

Please create some complex view and try to put more condition as per your requirement and play with one view . Since it’s not take disk space so you can do so many experiment with joins from multiple table filter data by using where condition .Since we can’t do any DML operation so it’s good for security purpose as well. Similarly we can remove the view if we don’t need then we use below command to remove the view.

Drop view student_sec;

Advantages of View :

 View is mainly used for security so If we need to maintain any sensitive/important information by providing limited access to the users, views are used. Views mainly used to display the required data, to the users, to keep important/sensitive data safe.

·        Database view is associated with many tables upon which the view is created, it simplifies the complexity of the query.

·        View  used to hide the complexity of the underlying tables used in a database  from the end-users.

·        It’s useful in re-designing the database as it does not affect any application using the same database.

·        The data of the columns from several tables can be calculated very easily when we query the data from the view, as views is enable computed columns.

 

 

Disadvantages

Only Disadvantage I can say for View is when we use changes the table structure frequently on which view is created , so whenever the table structure changed we need to change the view as well also usage of view can cause performance issue in the queries .

Despite the many advantages that the views offer, it still has some disadvantages stated as below:

One of the major disadvantages of using view comes into the picture when we change the table structures frequently upon which the view is created. So when the table structures are changed, the view also needs to be changed.

Also, the usage of view slows down the performance of the queries.

 

There is one another View which is Materialized view which i don’t want to explain in this blog because it’s bit complex but in coming blog when I am going to cover  Materialized view as I will define Materialized view in proper way. But for now I will just give you the overview of Materialized view:

 

Materialized View : It’s not Virtual table , Materialized View is a database object that contains the result of the query . Materialized view are local copies of data located remotely, or are used to create summaries tables based on aggregation of a table’s data . Materialized view also known as snapshot as its stores data based on remote tables.

Uses of Materialized view and creation of Materialized view I will include in next blog .

Main difference between Views and Materialized view . Views are Virtual table and not used any disk space or we can say views are not stored physically. Whereas Materialized view is a Physical copy , database object , picture or snapshot of the base tables.

View is very important in Database specially  for candidate who is preparing for interview. So please go ahead and read this blog and try to create some views then you will see the advantages of View. In this blog I just gave the overview of Materialized view so in coming blogs I will put more information on Materialized View.

Please read this blog carefully and if you have any doubts in this topic, please share your comment in blog.

Thanks

Comments

  1. Simply wish to say your article is as astonishing. The clarity in your post is simply great, and I could assume you are an expert on this subject. Same as your blog i found another one Oracle Service-Oriented Architectures .Actually I was looking for the same information on internet for Oracle SOA Suite and came across your blog. I am impressed by the information that you have on this blog. Thanks a million and please keep up the gratifying work.

    ReplyDelete
  2. Simply wish to say your article is as astonishing. The clarity in your post is simply great, and I could assume you are an expert on this subject. Same as your blog i found another one Oracle Service-Oriented Architectures .Actually I was looking for the same information on internet for Oracle SOA Suite and came across your blog. I am impressed by the information that you have on this blog. Thanks a million and please keep up the gratifying work.

    ReplyDelete
  3. I am thankful to this blog for giving unique and helpful knowledge about this topic.
    Best Coding classes in Rajasthan

    ReplyDelete

Post a Comment

Popular posts from this blog

SQL and Classification of SQL in Oracle Database #Diksha Oracle Training Centre

  SQL and Classification of SQL in Oracle Database.   SQL is Structured Query Language , which is used for storing, manipulating and retrieving data stored in a relational database .SQL is the standard language for RDBMS. All the Relational Database Management Systems (RDMS) like Oracle, MySQL, Sybase, Informix, IBM DB2 and Microsoft SQL Server use SQL as their standard database language. Oracle is one of the more secured database as compared to other databases. Importance of   SQL : SQL and PL/SQL is a backend process where all data is stored and retrieved in GUI which created either by any programming languages like Java, C++, PHP etc. so we need to have very secure database so that there will be no impact for users. SQL allows users to access data in the relational database management systems. SQL is used to communicate with a database.SQL and PL/SQL allows users to create and drop databases tables , views , stored procedures , functions , packages , trigger etc. SQL allows

Materialized View uses and Benefits in Database #DOTC_Mdb

Materialized View uses and Benefits in Database. Hello Everyone, Today we will discuss about Materialized view as it’s play important role in database. We already discussed about Simple Views and complex views in my previous blog. Before Materialized view go through my previous blog which related to simple view. https://dheeraj60.blogspot.com/2020/05/benefits-of-creating-and-using-view-in.html As we know View is not a database object and not like table which is stored in database, but view can be created from base table a view is an SQL statement that’s stored in the database. This statement, or view, has a name.A view looks and acts a lot like a table. It has columns and rows, and can be included in SELECT queries just like a table. In other word we can say View is a virtual/logical table which is basically used for security purpose. Let’s understand   about   Materialized view : A materialized view is a view that stores the results of the view’s query. Whenever you query the ma

Top 50 Interview Questions On SQL and PL/SQL #DOTC_Mdb

                    Top 50 Interview Questions On SQL and PL/SQL. Today we will Discuss Top 50 interview questions and answers of SQL and PL/SQL which is frequently asked in interview.     Question 1: What is SQL and Classification of SQL? Answer SQL is a Structure Query Language which is vastly used in RDBMS database like Oracle, Sybase, DB2 , Microsoft SQL server etc.   Classification of SQL is as below: DDL (Data Definition Language):  Commands are  create , alter , drop , truncate etc DML (Data Manipulation Language) : Commands are  insert,update and delete . TCL (Transaction Control Language ) : Commands are  Commit , Rollback and Save point. DCL (Data Control Language) : Commands are Grant , Revoke Question 2:    What is meant by Joins? What are the types of join? Answer Joins are basically used to extract/get data from multiple tables using some common columns or conditions and also by using alias to fulfill the condition.   There are various types of Joins as li