12-1 Copyright  Oracle Corporation, 1998. All rights reserved. What Is a View? EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ----- ------- --------- -----

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 4 Aggregating Data Using Group Functions.
Advertisements

Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
Subqueries 11. Objectives After completing this lesson, you should be able to do the following: Describe the types of problems that subqueries can solve.
Bogdan Shishedjiev SQL1 SQL Reminder of SQL. Bogdan Shishedjiev SQL 2 Subsets of language Data definition language (DDL) –Domain definition –Schema definition.
1Eyad Alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
SQL: Part 4 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
Copyright  Oracle Corporation, All rights reserved. 6 Subqueries.
6 6 Subqueries Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan (1999), published.
Copyright  Oracle Corporation, All rights reserved. 6 Writing Correlated Subqueries.
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Copyright  Oracle Corporation, All rights reserved. 9 Manipulating Data: INSERT, UPDATE, DELETE.
Session 3: SQL (B): Parts 3 & 4 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
Logical Operators Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns.
Copyright  Oracle Corporation, All rights reserved. Introduction.
o At the end of this lesson, you will be able to:  Describe the life-cycle development phases  Discuss the theoretical and physical aspects of a relational.
Copyright  Oracle Corporation, All rights reserved. I Introduction.
4-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language (DML)
Copyright  Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Dr. Philip Cannata 1 Programming Languages Prolog Part 3 SQL & Prolog.
Copyright © 2004, Oracle. All rights reserved. Lecture 3: Creating Other Schema Objects Lecture 3: Creating Other Schema Objects ORACLE.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join Displaying Data from.
Displaying Data from Multiple Tables (Join). EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
Subqueries.
Subqueries.
2 Writing Basic SELECT Statements. 1-2 Copyright  Oracle Corporation, All rights reserved. Capabilities of SQL SELECT Statements Selection Projection.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
RELATSIOONILISED ANDMEBAASID(alg) SQLi VÕIMALUSED.
7 Multiple-Column Subqueries. 7-2 Objectives At the end of this lesson, you should be able to: Write a multiple-column subquery Describe and explain the.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
SQL- DQL (Oracle Version). 2 SELECT Statement Syntax SELECT [DISTINCT] column_list FROM table_list [WHERE conditional expression] [GROUP BY column_list]
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
Chapter 2 Views. Objectives ◦ Create simple and complex views ◦ Creating a view with a check constraint ◦ Retrieve data from views ◦ Data manipulation.
Copyright  Oracle Corporation, All rights reserved. 4 Introduction.
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
SQL: Part 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
Manipulating Data. Objectives After completing this lesson, you should be able to do the following: Describe each DML statement Insert rows into a table.
Copyright  Oracle Corporation, All rights reserved. 12 Creating Views.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
Oracle CONNECT BY function JAVA WEB Programming. Emp 테이블의 내용 ( 상 / 하급자 계층구조 ) SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
2-1 Limiting Rows Using a Selection “…retrieve all employees in department 10” EMP EMPNO ENAME JOB... DEPTNO 7839KINGPRESIDENT BLAKEMANAGER CLARKMANAGER.
6 Subqueries. 6-2 Objectives At the end of this lesson, you should be able to: Describe the types of problems that subqueries can solve Define subqueries.
Creating Views Database Systems Objectives Explain the concept of a view. Create simple and complex views. Retrieve data through a view. Alter the.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
1-1 Copyright  Oracle Corporation, All rights reserved. Logging In to SQL*Plus From Windows environment:From Windows environment: From command line:From.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join Displaying Data from.
Defining a Column Alias
Copyright  Oracle Corporation, All rights reserved. Introduction.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
Communicating with a RDBMS Using SQL Database SQL> SELECT loc 2 FROM dept; SQL> SELECT loc 2 FROM dept; SQL statement is entered Statement is sent to database.
Relational Normalization Theory
Subqueries.
Subqueries Schedule: Timing Topic 25 minutes Lecture
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Chapter 2 Views.
Chapter 2 Views.
Subqueries Schedule: Timing Topic 25 minutes Lecture
Restricting and Sorting Data
IST 318 Database Administration
Subqueries Schedule: Timing Topic 25 minutes Lecture
Presentation transcript:

12-1 Copyright  Oracle Corporation, All rights reserved. What Is a View? EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO KING PRESIDENT 17-NOV BLAKE MANAGER MAY CLARK MANAGER JUN JONES MANAGER APR MARTIN SALESMAN SEP ALLEN SALESMAN FEB TURNER SALESMAN SEP JAMES CLERK DEC WARD SALESMAN FEB FORD ANALYST DEC SMITH CLERK DEC SCOTT ANALYST DEC ADAMS CLERK JAN MILLER CLERK JAN EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO KING PRESIDENT 17-NOV BLAKE MANAGER MAY CLARK MANAGER JUN JONES MANAGER APR MARTIN SALESMAN SEP ALLEN SALESMAN FEB TURNER SALESMAN SEP JAMES CLERK DEC WARD SALESMAN FEB FORD ANALYST DEC SMITH CLERK DEC SCOTT ANALYST DEC ADAMS CLERK JAN MILLER CLERK JAN EMP Table EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO KING PRESIDENT 17-NOV CLARK MANAGER JUN MILLER CLERK JAN JONES MANAGER APR SCOTT ANALYST DEC ADAMS CLERK JAN SMITH CLERK DEC FORD ANALYST DEC BLAKE MANAGER MAY MARTIN SALESMAN SEP ALLEN SALESMAN FEB TURNER SALESMAN SEP JAMES CLERK DEC WARD SALESMAN FEB EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO KING PRESIDENT 17-NOV CLARK MANAGER JUN MILLER CLERK JAN JONES MANAGER APR SCOTT ANALYST DEC ADAMS CLERK JAN SMITH CLERK DEC FORD ANALYST DEC BLAKE MANAGER MAY MARTIN SALESMAN SEP ALLEN SALESMAN FEB TURNER SALESMAN SEP JAMES CLERK DEC WARD SALESMAN FEB EMPNO ENAME JOB KING PRESIDENT 7782 CLARK MANAGER 7934 MILLER CLERK EMPVU10 View EMPVU10 View

12-2 Copyright  Oracle Corporation, All rights reserved. Simple Views and Complex Views FeatureSimple ViewsComplex Views Number of tablesOneOne or more Contain functionsNoYes Contain groups of dataNoYes DML through viewYesNot always FeatureSimple ViewsComplex Views Number of tablesOneOne or more Contain functionsNoYes Contain groups of dataNoYes DML through viewYesNot always

12-3 Copyright  Oracle Corporation, All rights reserved. Creating a View You embed a subquery within the CREATE VIEW statement. The subquery can contain complex SELECT syntax. The subquery cannot contain an ORDER BY clause. You embed a subquery within the CREATE VIEW statement. The subquery can contain complex SELECT syntax. The subquery cannot contain an ORDER BY clause. CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view [(alias[, alias]...)] AS subquery [WITH CHECK OPTION [CONSTRAINT constraint]] [WITH READ ONLY] CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view [(alias[, alias]...)] AS subquery [WITH CHECK OPTION [CONSTRAINT constraint]] [WITH READ ONLY]

12-4 Copyright  Oracle Corporation, All rights reserved. Creating a View Create a view, EMPVU10, that contains details of employees in department 10. Describe the structure of the view by using the SQL*Plus DESCRIBE command. SQL> DESCRIBE empvu10 SQL> CREATE VIEW empvu10 2 AS SELECTempno, ename, job 3 FROMemp 4 WHEREdeptno = 10; View created.

12-5 Copyright  Oracle Corporation, All rights reserved. Querying a View USER_VIEWS USER_VIEWS EMPVU10 SELECTempno, ename, job FROMemp WHEREdeptno = 10; USER_VIEWS USER_VIEWS EMPVU10 SELECTempno, ename, job FROMemp WHEREdeptno = 10; SQL*Plus SELECT * FROM empvu10; EMP 7839KINGPRESIDENT 7782CLARKMANAGER 7934MILLERCLERK

12-6 Copyright  Oracle Corporation, All rights reserved. Modifying a View Modify the EMPVU10 view by using CREATE OR REPLACE VIEW clause. Add an alias for each column name. Column aliases in the CREATE VIEW clause are listed in the same order as the columns in the subquery. Modify the EMPVU10 view by using CREATE OR REPLACE VIEW clause. Add an alias for each column name. Column aliases in the CREATE VIEW clause are listed in the same order as the columns in the subquery. SQL> CREATE OR REPLACE VIEW empvu10 2 (employee_number, employee_name, job_title) 3 AS SELECT empno, ename, job 4 FROMemp 5 WHEREdeptno = 10; View created.

12-7 Copyright  Oracle Corporation, All rights reserved. Creating a Complex View Create a complex view that contains group functions to display values from two tables. SQL> CREATE VIEWdept_sum_vu 2 (name, minsal, maxsal, avgsal) 3 AS SELECTd.dname, MIN(e.sal), MAX(e.sal), 4AVG(e.sal) 5 FROMemp e, dept d 6 WHEREe.deptno = d.deptno 7 GROUP BY d.dname; View created.

12-8 Copyright  Oracle Corporation, All rights reserved. Using the WITH CHECK OPTION Clause You can ensure that DML on the view stays within the domain of the view by using the WITH CHECK OPTION clause. Any attempt to change the department number for any row in the view will fail because it violates the WITH CHECK OPTION constraint. SQL> CREATE OR REPLACE VIEW empvu20 2 AS SELECT* 3 FROM emp 4 WHERE deptno = 20 5 WITH CHECK OPTION CONSTRAINT empvu20_ck; View created.

12-9 Copyright  Oracle Corporation, All rights reserved. Denying DML Operations You can ensure that no DML operations occur by adding the WITH READ ONLY option to your view definition. SQL> CREATE OR REPLACE VIEW empvu10 2 (employee_number, employee_name, job_title) 3 AS SELECTempno, ename, job 4 FROMemp 5 WHEREdeptno = 10 6 WITH READ ONLY; View created. Any attempt to perform a DML on any row in the view will result in Oracle Server error.

12-10 Copyright  Oracle Corporation, All rights reserved. Removing a View Remove a view without losing data because a view is based on underlying tables in the database. SQL> DROP VIEW empvu10; View dropped. DROP VIEW view;