SlideShare une entreprise Scribd logo
1  sur  32
Views in Oracle 10g
Version 1.0
Rushdi Shams, Dept of CSE, KUET 1
What is a View
 View is a virtual table.
 It does not contain any data.
 Views, however, are saved in the
database just like tables.
 So, views are database objects.
 A view is simply a window to a database
and represents a particular perspective
to the user.
Rushdi Shams, Dept of CSE, KUET 2
What is a View
 Views are similar to queries in that
respect that they too derive a result table
– which is virtual from the actual base
table.
 The difference between views and
queries is – views can be queried as well!
Rushdi Shams, Dept of CSE, KUET 3
Advantage of View
 I said – Views are windows to the
database tables.
 Windows are used to see the outside
world.
 So, is view used to only see the outside
world?
Not at all!
Rushdi Shams, Dept of CSE, KUET 4
Advantage of View
 The main point of view is to restrict what
you can see in the underlying database
table by selective columns.
 They can be used to make complex queries
easy. A user can use a simple query on a
view to display data from multiple tables,
without having the knowledge of how to
join tables in queries.
 Different views can be created from the
same data as per the requirements of
different types of use groups.
Rushdi Shams, Dept of CSE, KUET 5
Our Table
Rushdi Shams, Dept of CSE, KUET 6
 This is our table. We will play with this table
to understand views.
Creating a View
Rushdi Shams, Dept of CSE, KUET 7
 We are now creating a view named test_view
that selects all records of CSD students
Querying the View
Rushdi Shams, Dept of CSE, KUET 8
 As we said earlier, we can query a view, we
have selected everything test_view provides.
Querying the View
Rushdi Shams, Dept of CSE, KUET 9
 In this case, we have filtered the result found
from the view with WHERE clause.
View makes Complex Query Simple
Rushdi Shams, Dept of CSE, KUET 10
 In SQL, the query we have made in the
previous slide should look like this.
 Which one is simpler?
Creating another View
Rushdi Shams, Dept of CSE, KUET 11
 This time we are creating another view
named test_view_2 which will contain the
records of BSD students.
Querying the Second View
Rushdi Shams, Dept of CSE, KUET 12
 Again we have queried the second view and
found appropriate records.
Simplicity
 This property is called simplicity
 The student data are for the whole
university
 We have simplified the data so that BSD
people won’t have to bother about CSD
people and vice versa.
Rushdi Shams, Dept of CSE, KUET 13
Creating the Third View
Rushdi Shams, Dept of CSE, KUET 14
 test_view_3 is created.
 The third line takes the months between the
current date (sysdate) and the date on birthday
column. Then divides it by 12 to get the year.
Then the whole number is passed as argument
of FLOOR function. That is the age of every
entry in the table.
Querying the View
Rushdi Shams, Dept of CSE, KUET 15
Functionality
 Another property of views.
 It means that we can provide the user
AGE and the user may never ever be
able to know that there is actually no
column such as AGE. AGE is actually
derived from other columns of the table.
Rushdi Shams, Dept of CSE, KUET 16
Security
 It is the third property of views.
 It is an extension of SIMPLICITY
property.
 BSD student records are safe now from
CSD students (As CSD students are
technologically smart )
 Do you think teachers will allow you to
see their salaries?
Rushdi Shams, Dept of CSE, KUET 17
Updating through Views
 Now we will take a look into issues we
need to know while updating tables
through views.
Rushdi Shams, Dept of CSE, KUET 18
Creating Fourth View
Rushdi Shams, Dept of CSE, KUET 19
 We have created test_view_4 which does not
have all the columns of the table.
Querying the View
Rushdi Shams, Dept of CSE, KUET 20
Our View 1 and View 4
Rushdi Shams, Dept of CSE, KUET 21
What We can do View 1?
Rushdi Shams, Dept of CSE, KUET 22
 we can insert a new row into the view
 delete an existing record from a view
 update an existing field in the view.
Problem updating through View 4
 suppose we wished to insert a record for a new
student, F, M, BSD. We would have to insert the
record null, F, M, null, null, BSD into the
underlying students table.
 This attempt will fail since studentNo (the table’s
primary key) must not be null.
23Rushdi Shams, Dept of CSE, KUET
To make a View Updatable
Rushdi Shams, Dept of CSE, KUET 24
Updating through an Updatable
View
Rushdi Shams, Dept of CSE, KUET 25
Querying the Updated View
Rushdi Shams, Dept of CSE, KUET 26
Inserting through a Wrong
View
Rushdi Shams, Dept of CSE, KUET 27
 Now, we are trying to enter a student of BSD
through a view (view 1) created for CSD
students.
The Result!
Rushdi Shams, Dept of CSE, KUET 28
 The view inserted it into the table but it cannot
be queried with view 1
 You can query it through view 2 (created for
BSD students)
The Solution
Rushdi Shams, Dept of CSE, KUET 29
 We have changed the CREATE VIEW statement
for our view 1 by adding WITH CHECK OPTION
 Now we are attempting to insert records for BSD
students through a view created for CSD
students.
The Result
Rushdi Shams, Dept of CSE, KUET 30
 Oracle got you!
 You cannot violate that when you have
created the view with a WITH CHECK
OPTION
Dropping the Views
Rushdi Shams, Dept of CSE, KUET 31
 Finally, we are dropping all the four views
with DROP VIEW option.
References
 Database Systems (Third Edition) by Paul
Beynon-Davies
 Structured Query Language (SQL): A
Practical Introduction by Akil I. Din
 Oracle forums at
http://forums.oracle.com/forums/thread.j
spa?threadID=378783 [21 March 2008]
 Geek Interview at
http://www.geekinterview.com/question_
details/338 [21 March 2008]
Rushdi Shams, Dept of CSE, KUET 32

Contenu connexe

Plus de Rushdi Shams

Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
Rushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
Rushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
Rushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
Rushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
Rushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
Rushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
Rushdi Shams
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
Rushdi Shams
 
L1 overview of software engineering
L1  overview of software engineeringL1  overview of software engineering
L1 overview of software engineering
Rushdi Shams
 
L13 why software fails
L13  why software failsL13  why software fails
L13 why software fails
Rushdi Shams
 
Lecture 14,15 and 16 file systems
Lecture 14,15 and 16  file systemsLecture 14,15 and 16  file systems
Lecture 14,15 and 16 file systems
Rushdi Shams
 
Lecture 11,12 and 13 deadlocks
Lecture 11,12 and 13  deadlocksLecture 11,12 and 13  deadlocks
Lecture 11,12 and 13 deadlocks
Rushdi Shams
 
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
Lecture 7, 8, 9 and 10  Inter Process Communication (IPC) in Operating SystemsLecture 7, 8, 9 and 10  Inter Process Communication (IPC) in Operating Systems
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
Rushdi Shams
 
Lecture 5, 6 and 7 cpu scheduling
Lecture 5, 6 and 7  cpu schedulingLecture 5, 6 and 7  cpu scheduling
Lecture 5, 6 and 7 cpu scheduling
Rushdi Shams
 

Plus de Rushdi Shams (20)

Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
 
L1 overview of software engineering
L1  overview of software engineeringL1  overview of software engineering
L1 overview of software engineering
 
L13 why software fails
L13  why software failsL13  why software fails
L13 why software fails
 
Lecture 14,15 and 16 file systems
Lecture 14,15 and 16  file systemsLecture 14,15 and 16  file systems
Lecture 14,15 and 16 file systems
 
Lecture 11,12 and 13 deadlocks
Lecture 11,12 and 13  deadlocksLecture 11,12 and 13  deadlocks
Lecture 11,12 and 13 deadlocks
 
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
Lecture 7, 8, 9 and 10  Inter Process Communication (IPC) in Operating SystemsLecture 7, 8, 9 and 10  Inter Process Communication (IPC) in Operating Systems
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
 
Lecture 5, 6 and 7 cpu scheduling
Lecture 5, 6 and 7  cpu schedulingLecture 5, 6 and 7  cpu scheduling
Lecture 5, 6 and 7 cpu scheduling
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

L6 views

  • 1. Views in Oracle 10g Version 1.0 Rushdi Shams, Dept of CSE, KUET 1
  • 2. What is a View  View is a virtual table.  It does not contain any data.  Views, however, are saved in the database just like tables.  So, views are database objects.  A view is simply a window to a database and represents a particular perspective to the user. Rushdi Shams, Dept of CSE, KUET 2
  • 3. What is a View  Views are similar to queries in that respect that they too derive a result table – which is virtual from the actual base table.  The difference between views and queries is – views can be queried as well! Rushdi Shams, Dept of CSE, KUET 3
  • 4. Advantage of View  I said – Views are windows to the database tables.  Windows are used to see the outside world.  So, is view used to only see the outside world? Not at all! Rushdi Shams, Dept of CSE, KUET 4
  • 5. Advantage of View  The main point of view is to restrict what you can see in the underlying database table by selective columns.  They can be used to make complex queries easy. A user can use a simple query on a view to display data from multiple tables, without having the knowledge of how to join tables in queries.  Different views can be created from the same data as per the requirements of different types of use groups. Rushdi Shams, Dept of CSE, KUET 5
  • 6. Our Table Rushdi Shams, Dept of CSE, KUET 6  This is our table. We will play with this table to understand views.
  • 7. Creating a View Rushdi Shams, Dept of CSE, KUET 7  We are now creating a view named test_view that selects all records of CSD students
  • 8. Querying the View Rushdi Shams, Dept of CSE, KUET 8  As we said earlier, we can query a view, we have selected everything test_view provides.
  • 9. Querying the View Rushdi Shams, Dept of CSE, KUET 9  In this case, we have filtered the result found from the view with WHERE clause.
  • 10. View makes Complex Query Simple Rushdi Shams, Dept of CSE, KUET 10  In SQL, the query we have made in the previous slide should look like this.  Which one is simpler?
  • 11. Creating another View Rushdi Shams, Dept of CSE, KUET 11  This time we are creating another view named test_view_2 which will contain the records of BSD students.
  • 12. Querying the Second View Rushdi Shams, Dept of CSE, KUET 12  Again we have queried the second view and found appropriate records.
  • 13. Simplicity  This property is called simplicity  The student data are for the whole university  We have simplified the data so that BSD people won’t have to bother about CSD people and vice versa. Rushdi Shams, Dept of CSE, KUET 13
  • 14. Creating the Third View Rushdi Shams, Dept of CSE, KUET 14  test_view_3 is created.  The third line takes the months between the current date (sysdate) and the date on birthday column. Then divides it by 12 to get the year. Then the whole number is passed as argument of FLOOR function. That is the age of every entry in the table.
  • 15. Querying the View Rushdi Shams, Dept of CSE, KUET 15
  • 16. Functionality  Another property of views.  It means that we can provide the user AGE and the user may never ever be able to know that there is actually no column such as AGE. AGE is actually derived from other columns of the table. Rushdi Shams, Dept of CSE, KUET 16
  • 17. Security  It is the third property of views.  It is an extension of SIMPLICITY property.  BSD student records are safe now from CSD students (As CSD students are technologically smart )  Do you think teachers will allow you to see their salaries? Rushdi Shams, Dept of CSE, KUET 17
  • 18. Updating through Views  Now we will take a look into issues we need to know while updating tables through views. Rushdi Shams, Dept of CSE, KUET 18
  • 19. Creating Fourth View Rushdi Shams, Dept of CSE, KUET 19  We have created test_view_4 which does not have all the columns of the table.
  • 20. Querying the View Rushdi Shams, Dept of CSE, KUET 20
  • 21. Our View 1 and View 4 Rushdi Shams, Dept of CSE, KUET 21
  • 22. What We can do View 1? Rushdi Shams, Dept of CSE, KUET 22  we can insert a new row into the view  delete an existing record from a view  update an existing field in the view.
  • 23. Problem updating through View 4  suppose we wished to insert a record for a new student, F, M, BSD. We would have to insert the record null, F, M, null, null, BSD into the underlying students table.  This attempt will fail since studentNo (the table’s primary key) must not be null. 23Rushdi Shams, Dept of CSE, KUET
  • 24. To make a View Updatable Rushdi Shams, Dept of CSE, KUET 24
  • 25. Updating through an Updatable View Rushdi Shams, Dept of CSE, KUET 25
  • 26. Querying the Updated View Rushdi Shams, Dept of CSE, KUET 26
  • 27. Inserting through a Wrong View Rushdi Shams, Dept of CSE, KUET 27  Now, we are trying to enter a student of BSD through a view (view 1) created for CSD students.
  • 28. The Result! Rushdi Shams, Dept of CSE, KUET 28  The view inserted it into the table but it cannot be queried with view 1  You can query it through view 2 (created for BSD students)
  • 29. The Solution Rushdi Shams, Dept of CSE, KUET 29  We have changed the CREATE VIEW statement for our view 1 by adding WITH CHECK OPTION  Now we are attempting to insert records for BSD students through a view created for CSD students.
  • 30. The Result Rushdi Shams, Dept of CSE, KUET 30  Oracle got you!  You cannot violate that when you have created the view with a WITH CHECK OPTION
  • 31. Dropping the Views Rushdi Shams, Dept of CSE, KUET 31  Finally, we are dropping all the four views with DROP VIEW option.
  • 32. References  Database Systems (Third Edition) by Paul Beynon-Davies  Structured Query Language (SQL): A Practical Introduction by Akil I. Din  Oracle forums at http://forums.oracle.com/forums/thread.j spa?threadID=378783 [21 March 2008]  Geek Interview at http://www.geekinterview.com/question_ details/338 [21 March 2008] Rushdi Shams, Dept of CSE, KUET 32