SlideShare a Scribd company logo
1 of 24
Creating Views  http://ecomputernotes.com
Objectives  After completing this lesson, you should be able  to do the following:  "  Describe a view  "  Create, alter the definition of, and drop a view  "  Retrieve data through a view  "  Insert, update, and delete data through  a view  "  Create and use an inline view  "  Perform ³Top-N´ analysis  http://ecomputernotes.com
Database Objects  Object  Description  Basic unit of storage; composed of rows  Table  and columns  View  Logically represents subsets of data from  one or more tables  Sequence  Generates primary key values  Index  Improves the performance of some queries  Synonym  Alternative name for an object  http://ecomputernotes.com
What is a View?  EMPLOYEES   Table:  http://ecomputernotes.com
Why Use Views?  "  To restrict data access  "  To make complex queries easy  "  To provide data independence  "  To present different views of the same data  http://ecomputernotes.com
Simple Views  and Complex Views  Feature  Simple Views   Complex Views  Number of tables  One  One or more  Contain functions  No  Yes  Contain groups of data  No  Yes  DML operations  through  a view  Yes  Not always  http://ecomputernotes.com
Creating a View  "Y ou embed a subquery within the  C REATE VIEW s tatement.  CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW   view  [( alias [,  alias ]...) ]  AS   subquery  [WITH CHECK OPTION [CONSTRAINT   constraint ]] [WITH READ ONLY [CONSTRAINT   constraint ]];  "T he subquery can contain complex  S ELECT  syntax.  http://ecomputernotes.com
Creating a View  "  Create a view,   EMPVU80 , that contains details of employees in department 80.  CREATE VIEW   empvu80  AS SELECT  employee_id, last_name, salary FROM  employees  WHERE  department_id = 80;  View created.  "D escribe the structure of the view by using the  i SQL*Plus   DESCRIBE   command.  DESCRIBE empvu80  http://ecomputernotes.com
Creating a View  "C reate a view by using column aliases in the  subquery.  CREATE VIEW   salvu50  AS SELECT  employee_id ID_NUMBER, last_name NAME, salary*12 ANN_SALARY  FROM  employees  WHERE  department_id = 50;  View created.  "S elect the columns from this view by the given  alias names.  http://ecomputernotes.com
Retrieving Data from a View  SELECT *  FRO M  salvu50;  http://ecomputernotes.com
Querying a View  Oracle Server  i SQL*Plus  USER_VIEWS  SELECT  *  EMPVU80  FROM  empvu80;  SELECT employee_id,  last_name, salary  FROM  employees  WHERE  department_id=80;  EMPLOYEES  http://ecomputernotes.com
Modifying a View  "  Modify the   EMPVU80   view by using   CREATE OR  REPLACE VIEW   clause. Add an alias for each column name.  CREATE OR REPLACE VIEW empvu80  (id_number, name, sal, department_id)  AS SELECT  employee_id, first_name || ' ' || last_name,  salary, department_id  FROM  employees  WHERE  department_id = 80;  View created.  "C olumn aliases in the  C REATE VIEW  clause are  listed in the same order as the columns in the  subquery.  http://ecomputernotes.com
Creating a Complex View  Create a complex view that contains group functions  to display values from two tables.  CREATE VIEW dept_sum_vu  (name, minsal, maxsal, avgsal)  AS SELECT  d.department_name, MIN(e.salary), MAX(e.salary),AVG(e.salary)  FROM  employees e, departments d  WHERE  e.department_id = d.department_id  GROUP BY  d.department_name;  View created.  http://ecomputernotes.com
Rules for Performing  DML Operations on a View  "  You can perform DML operations on simple views.  "  You cannot remove a row if the view contains the  following:  Group functions A   GROUP BY   clause The   DISTINCT   keyword  The pseudocolumn   ROWNUM   keyword  http://ecomputernotes.com
Rules for Performing  DML Operations on a View  You cannot modify data in a view if it contains:  "  Group functions  "  A   GROUP BY   clause  "  The   DISTINCT   keyword  "  The pseudocolumn   ROWNUM   keyword  "  Columns defined by expressions  http://ecomputernotes.com
Rules for Performing  DML Operations on a View  You cannot add data through a view if the view  includes:  "  Group functions  "  A   GROUP BY   clause  "  The   DISTINCT   keyword  "  The pseudocolumn   ROWNUM   keyword  "  Columns defined by expressions  "  NOT NULL   columns in the base tables that are not selected by the view  http://ecomputernotes.com
Using the   WITH CHECK OPTION   Clause  "Y ou can ensure that DML operations performed on  the view stay within the domain of the view by using the   WITH CHECK OPTION   clause.  CREATE OR REPLACE VIEW empvu20  AS SELECT  *  FROM  employees  WHERE  department_id = 20  WITH CHECK OPTION CONSTRAINT empvu20_ck ;  View created.  "A ny attempt to change the department number for  any row in the view fails because it violates the  WITH CHECK OPTION   constraint.  http://ecomputernotes.com
Denying DML Operations  "Y ou can ensure that no DML operations occur by  adding the   WITH READ ONLY   option to your view definition.  "A ny attempt to perform a DML on any row in the  view results in an Oracle server error.  http://ecomputernotes.com
Denying DML Operations  CREATE OR REPLACE VIEW empvu10 (employee_number, employee_name, job_title) AS SELECT  employee_id, last_name, job_id  FROM  employees  WHERE  department_id = 10 WITH READ ONLY;  View created.  http://ecomputernotes.com
Removing a View  You can remove a view without losing data because a view is based on underlying tables in the database.  DROP VIEW   view ;;  DROP VIEW empvu80;  View dropped.  http://ecomputernotes.com
Inline Views  "  An inline view is a subquery with an alias (or  correlation name) that you can use within a SQL  statement.  "  A named subquery in the   FROM   clause of the main  query is an example of an inline view.  "  An inline view is not a schema object.  http://ecomputernotes.com
Top-N Analysis  "T op-N queries ask for the  n   l argest or smallest  values of a column. For example:  What are the ten best selling products?  "  What are the ten worst selling products?  Both largest values and smallest values sets are considered Top-N queries.  http://ecomputernotes.com
Performing Top-N Analysis  The high-level structure of a Top-N analysis query is:  SELECT [ column_list ], ROWNUM FROM  (SELECT [ column_list ] FROM table  ORDER  BY Top-N_column) WHERE  ROWNUM <=  N;  http://ecomputernotes.com
Example of Top-N Analysis  To display the top three earner names and salaries from thefrom the   EMPLOYEES   table:table:  1  2  3  SELECT ROWNUM as RANK, last_name, salary FROM  (SELECT last_name,salary FROM employees ORDER BY salary DESC)  WHERE ROWNUM <= 3;  1  2  3  http://ecomputernotes.com

More Related Content

What's hot

The EffiChange XPager Suite: Understanding XPages Scaffolding
The EffiChange XPager Suite: Understanding XPages ScaffoldingThe EffiChange XPager Suite: Understanding XPages Scaffolding
The EffiChange XPager Suite: Understanding XPages ScaffoldingEffiChange LLC
 
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...Richard Rabins
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with AngularAna Cidre
 
Best Practices for Magento Debugging
Best Practices for Magento Debugging Best Practices for Magento Debugging
Best Practices for Magento Debugging varien
 
Diversified application testing based on a Sylius project
Diversified application testing based on a Sylius projectDiversified application testing based on a Sylius project
Diversified application testing based on a Sylius projectŁukasz Chruściel
 
Михаил Крайнюк. Form API: AJAX-commands
Михаил Крайнюк. Form API: AJAX-commandsМихаил Крайнюк. Form API: AJAX-commands
Михаил Крайнюк. Form API: AJAX-commandsDrupalSib
 
Oracle - Program with PL/SQL - Lession 13
Oracle - Program with PL/SQL - Lession 13Oracle - Program with PL/SQL - Lession 13
Oracle - Program with PL/SQL - Lession 13Thuan Nguyen
 
SPS Stockholm: PowerApps Jumpstart
SPS Stockholm: PowerApps JumpstartSPS Stockholm: PowerApps Jumpstart
SPS Stockholm: PowerApps JumpstartSandy Ussia
 
BDD in practice based on an open source project
BDD in practice based on an open source projectBDD in practice based on an open source project
BDD in practice based on an open source projectŁukasz Chruściel
 
Oracle Forms- key triggers
Oracle Forms- key triggersOracle Forms- key triggers
Oracle Forms- key triggersSekhar Byna
 
Oracle - Program with PL/SQL - Lession 10
Oracle - Program with PL/SQL - Lession 10Oracle - Program with PL/SQL - Lession 10
Oracle - Program with PL/SQL - Lession 10Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Thuan Nguyen
 
What's New in newforms-admin
What's New in newforms-adminWhat's New in newforms-admin
What's New in newforms-adminbrosner
 
Introduction To Angular's reactive forms
Introduction To Angular's reactive formsIntroduction To Angular's reactive forms
Introduction To Angular's reactive formsNir Kaufman
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScriptRavi Bhadauria
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsManuel Lemos
 
Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Thuan Nguyen
 

What's hot (20)

The EffiChange XPager Suite: Understanding XPages Scaffolding
The EffiChange XPager Suite: Understanding XPages ScaffoldingThe EffiChange XPager Suite: Understanding XPages Scaffolding
The EffiChange XPager Suite: Understanding XPages Scaffolding
 
Exercise in alv
Exercise in alvExercise in alv
Exercise in alv
 
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with Angular
 
Applet
AppletApplet
Applet
 
Best Practices for Magento Debugging
Best Practices for Magento Debugging Best Practices for Magento Debugging
Best Practices for Magento Debugging
 
Diversified application testing based on a Sylius project
Diversified application testing based on a Sylius projectDiversified application testing based on a Sylius project
Diversified application testing based on a Sylius project
 
Showroom create flow
Showroom create flowShowroom create flow
Showroom create flow
 
Михаил Крайнюк. Form API: AJAX-commands
Михаил Крайнюк. Form API: AJAX-commandsМихаил Крайнюк. Form API: AJAX-commands
Михаил Крайнюк. Form API: AJAX-commands
 
Oracle - Program with PL/SQL - Lession 13
Oracle - Program with PL/SQL - Lession 13Oracle - Program with PL/SQL - Lession 13
Oracle - Program with PL/SQL - Lession 13
 
SPS Stockholm: PowerApps Jumpstart
SPS Stockholm: PowerApps JumpstartSPS Stockholm: PowerApps Jumpstart
SPS Stockholm: PowerApps Jumpstart
 
BDD in practice based on an open source project
BDD in practice based on an open source projectBDD in practice based on an open source project
BDD in practice based on an open source project
 
Oracle Forms- key triggers
Oracle Forms- key triggersOracle Forms- key triggers
Oracle Forms- key triggers
 
Oracle - Program with PL/SQL - Lession 10
Oracle - Program with PL/SQL - Lession 10Oracle - Program with PL/SQL - Lession 10
Oracle - Program with PL/SQL - Lession 10
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
 
What's New in newforms-admin
What's New in newforms-adminWhat's New in newforms-admin
What's New in newforms-admin
 
Introduction To Angular's reactive forms
Introduction To Angular's reactive formsIntroduction To Angular's reactive forms
Introduction To Angular's reactive forms
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced Plugins
 
Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03
 

Similar to e computer notes - Creating views

e computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql pluse computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql plusecomputernotes
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueriesecomputernotes
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle databaseSalman Memon
 
e computer notes - Enhancements to the group by clause
e computer notes - Enhancements to the group by clausee computer notes - Enhancements to the group by clause
e computer notes - Enhancements to the group by clauseecomputernotes
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCMaarten Balliauw
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objectsSyed Zaid Irshad
 
Chapter 07 ddl_sql
Chapter 07 ddl_sqlChapter 07 ddl_sql
Chapter 07 ddl_sqlNazir Ahmed
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
e computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statementse computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statementsecomputernotes
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankpptnewrforce
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sqlN.Jagadish Kumar
 

Similar to e computer notes - Creating views (20)

Les11
Les11Les11
Les11
 
e computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql pluse computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql plus
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
 
e computer notes - Enhancements to the group by clause
e computer notes - Enhancements to the group by clausee computer notes - Enhancements to the group by clause
e computer notes - Enhancements to the group by clause
 
Les10
Les10Les10
Les10
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Les07
Les07Les07
Les07
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objects
 
Oracle sql tuning
Oracle sql tuningOracle sql tuning
Oracle sql tuning
 
Chapter 07 ddl_sql
Chapter 07 ddl_sqlChapter 07 ddl_sql
Chapter 07 ddl_sql
 
01 basic orders
01   basic orders01   basic orders
01 basic orders
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
e computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statementse computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statements
 
Les10
Les10Les10
Les10
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
Module05
Module05Module05
Module05
 
MVC Training Part 2
MVC Training Part 2MVC Training Part 2
MVC Training Part 2
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
View
ViewView
View
 

More from ecomputernotes

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30ecomputernotes
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11ecomputernotes
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20ecomputernotes
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraintsecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functionsecomputernotes
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueriesecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objectsecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueriesecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functionsecomputernotes
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36ecomputernotes
 

More from ecomputernotes (20)

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
 

Recently uploaded

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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
 
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.pdfOrbitshub
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
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 REVIEWERMadyBayot
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
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 FMESafe Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
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 FMESafe Software
 
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 businesspanagenda
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
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 challengesrafiqahmad00786416
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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, ...
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
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
 

e computer notes - Creating views

  • 1. Creating Views http://ecomputernotes.com
  • 2. Objectives After completing this lesson, you should be able to do the following: &quot; Describe a view &quot; Create, alter the definition of, and drop a view &quot; Retrieve data through a view &quot; Insert, update, and delete data through a view &quot; Create and use an inline view &quot; Perform ³Top-N´ analysis http://ecomputernotes.com
  • 3. Database Objects Object Description Basic unit of storage; composed of rows Table and columns View Logically represents subsets of data from one or more tables Sequence Generates primary key values Index Improves the performance of some queries Synonym Alternative name for an object http://ecomputernotes.com
  • 4. What is a View? EMPLOYEES Table: http://ecomputernotes.com
  • 5. Why Use Views? &quot; To restrict data access &quot; To make complex queries easy &quot; To provide data independence &quot; To present different views of the same data http://ecomputernotes.com
  • 6. Simple Views and Complex Views Feature Simple Views Complex Views Number of tables One One or more Contain functions No Yes Contain groups of data No Yes DML operations through a view Yes Not always http://ecomputernotes.com
  • 7. Creating a View &quot;Y ou embed a subquery within the C REATE VIEW s tatement. CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view [( alias [, alias ]...) ] AS subquery [WITH CHECK OPTION [CONSTRAINT constraint ]] [WITH READ ONLY [CONSTRAINT constraint ]]; &quot;T he subquery can contain complex S ELECT syntax. http://ecomputernotes.com
  • 8. Creating a View &quot; Create a view, EMPVU80 , that contains details of employees in department 80. CREATE VIEW empvu80 AS SELECT employee_id, last_name, salary FROM employees WHERE department_id = 80; View created. &quot;D escribe the structure of the view by using the i SQL*Plus DESCRIBE command. DESCRIBE empvu80 http://ecomputernotes.com
  • 9. Creating a View &quot;C reate a view by using column aliases in the subquery. CREATE VIEW salvu50 AS SELECT employee_id ID_NUMBER, last_name NAME, salary*12 ANN_SALARY FROM employees WHERE department_id = 50; View created. &quot;S elect the columns from this view by the given alias names. http://ecomputernotes.com
  • 10. Retrieving Data from a View SELECT * FRO M salvu50; http://ecomputernotes.com
  • 11. Querying a View Oracle Server i SQL*Plus USER_VIEWS SELECT * EMPVU80 FROM empvu80; SELECT employee_id, last_name, salary FROM employees WHERE department_id=80; EMPLOYEES http://ecomputernotes.com
  • 12. Modifying a View &quot; Modify the EMPVU80 view by using CREATE OR REPLACE VIEW clause. Add an alias for each column name. CREATE OR REPLACE VIEW empvu80 (id_number, name, sal, department_id) AS SELECT employee_id, first_name || ' ' || last_name, salary, department_id FROM employees WHERE department_id = 80; View created. &quot;C olumn aliases in the C REATE VIEW clause are listed in the same order as the columns in the subquery. http://ecomputernotes.com
  • 13. Creating a Complex View Create a complex view that contains group functions to display values from two tables. CREATE VIEW dept_sum_vu (name, minsal, maxsal, avgsal) AS SELECT d.department_name, MIN(e.salary), MAX(e.salary),AVG(e.salary) FROM employees e, departments d WHERE e.department_id = d.department_id GROUP BY d.department_name; View created. http://ecomputernotes.com
  • 14. Rules for Performing DML Operations on a View &quot; You can perform DML operations on simple views. &quot; You cannot remove a row if the view contains the following: Group functions A GROUP BY clause The DISTINCT keyword The pseudocolumn ROWNUM keyword http://ecomputernotes.com
  • 15. Rules for Performing DML Operations on a View You cannot modify data in a view if it contains: &quot; Group functions &quot; A GROUP BY clause &quot; The DISTINCT keyword &quot; The pseudocolumn ROWNUM keyword &quot; Columns defined by expressions http://ecomputernotes.com
  • 16. Rules for Performing DML Operations on a View You cannot add data through a view if the view includes: &quot; Group functions &quot; A GROUP BY clause &quot; The DISTINCT keyword &quot; The pseudocolumn ROWNUM keyword &quot; Columns defined by expressions &quot; NOT NULL columns in the base tables that are not selected by the view http://ecomputernotes.com
  • 17. Using the WITH CHECK OPTION Clause &quot;Y ou can ensure that DML operations performed on the view stay within the domain of the view by using the WITH CHECK OPTION clause. CREATE OR REPLACE VIEW empvu20 AS SELECT * FROM employees WHERE department_id = 20 WITH CHECK OPTION CONSTRAINT empvu20_ck ; View created. &quot;A ny attempt to change the department number for any row in the view fails because it violates the WITH CHECK OPTION constraint. http://ecomputernotes.com
  • 18. Denying DML Operations &quot;Y ou can ensure that no DML operations occur by adding the WITH READ ONLY option to your view definition. &quot;A ny attempt to perform a DML on any row in the view results in an Oracle server error. http://ecomputernotes.com
  • 19. Denying DML Operations CREATE OR REPLACE VIEW empvu10 (employee_number, employee_name, job_title) AS SELECT employee_id, last_name, job_id FROM employees WHERE department_id = 10 WITH READ ONLY; View created. http://ecomputernotes.com
  • 20. Removing a View You can remove a view without losing data because a view is based on underlying tables in the database. DROP VIEW view ;; DROP VIEW empvu80; View dropped. http://ecomputernotes.com
  • 21. Inline Views &quot; An inline view is a subquery with an alias (or correlation name) that you can use within a SQL statement. &quot; A named subquery in the FROM clause of the main query is an example of an inline view. &quot; An inline view is not a schema object. http://ecomputernotes.com
  • 22. Top-N Analysis &quot;T op-N queries ask for the n l argest or smallest values of a column. For example: What are the ten best selling products? &quot; What are the ten worst selling products? Both largest values and smallest values sets are considered Top-N queries. http://ecomputernotes.com
  • 23. Performing Top-N Analysis The high-level structure of a Top-N analysis query is: SELECT [ column_list ], ROWNUM FROM (SELECT [ column_list ] FROM table ORDER BY Top-N_column) WHERE ROWNUM <= N; http://ecomputernotes.com
  • 24. Example of Top-N Analysis To display the top three earner names and salaries from thefrom the EMPLOYEES table:table: 1 2 3 SELECT ROWNUM as RANK, last_name, salary FROM (SELECT last_name,salary FROM employees ORDER BY salary DESC) WHERE ROWNUM <= 3; 1 2 3 http://ecomputernotes.com