Creating Views: Dept. of Computer Science Faculty of Science and Technology
Creating Views: Dept. of Computer Science Faculty of Science and Technology
Object Description
EMPNO 7876
7499
7499 ADAMS
ENAME
7876 ALLEN
ALLEN SALESMAN
ADAMS CLERK
JOB
SALESMAN
CLERK 7788
7698
7698 12-JAN-83
7788 20-FEB-81
12-JAN-83
20-FEB-81 1600
1100
1100 300
1600 300 30
20
30
20
------ 7369
--------
7369
7844 SMITH
TURNER
7844 SMITH -----------
SALESMAN
CLERK
TURNER SALESMAN
CLERK 7902
7698
7902 17-DEC-80
08-SEP-81
7698 17-DEC-80
08-SEP-81 1500
800
1500
800 00 30
20
30
20
7902
7900
7900 FORD
JAMES
JAMES CLERK
ANALYST
ANALYST 7566
7698
7698 03-DEC-81 3000
950 30
20
7839 7698
KING
7902
7521
FORD
PRESIDENT
CLERK 7566 03-DEC-81 3000
950 30
20
7521 BLAKE
7698 WARD
BLAKE
WARD SALESMAN
MANAGER
MANAGER 7839
SALESMAN 7698
7698 01-MAY-81
7839 22-FEB-81
01-MAY-81
22-FEB-81 1250
2850
2850 500
1250 500 30
30
30
30
7782 7654
CLARK
7902
7902 MARTIN
7654 FORD
MARTIN
FORD MANAGER
ANALYST
SALESMAN
ANALYST
SALESMAN 7698
7566
7566 28-SEP-81
7698 03-DEC-81
28-SEP-81
03-DEC-81 3000
1250
1250 1400
3000 1400 20
30
20
30
7934 7499
MILLER
7499
7369 ALLEN
SMITH
7369 ALLEN
SMITH CLERK7698
CLERK
SALESMAN
CLERK
SALESMAN 7698
7902 20-FEB-81
17-DEC-80
7902 20-FEB-81
17-DEC-80 1600
800
1600
800 300
300 20
30
20
30
7844
7788
7788 TURNER
7844 SCOTT
SCOTT ANALYST
TURNER SALESMAN
SALESMAN 7698
ANALYST 7566
7566 08-SEP-81
7698 09-DEC-82
09-DEC-82 3000
08-SEP-81 1500
3000
1500 00 20
30
20
30
7900
7876
7876 JAMES
7900 ADAMS
ADAMS CLERK
JAMES CLERK
CLERK
CLERK 7698
7788
7788 03-DEC-81
7698 12-JAN-83
12-JAN-83 1100
03-DEC-81 950
1100
950 20
30
20
30
7521
7934
7934 WARD
7521 MILLER
MILLER CLERK
WARD SALESMAN
SALESMAN 7698
CLERK 7782
7782 22-FEB-81
7698 23-JAN-82
23-JAN-82 1300
22-FEB-81 1250
1300
1250 500
500 10
30
10
30
Why Use Views?
To restrict database access
To make complex queries easy
To allow data independence
To present different views of the same data
Simple Views and Complex Views
Feature Simple Views Complex Views
CREATE
CREATE [OR
[OR REPLACE]
REPLACE] [FORCE|NOFORCE]
[FORCE|NOFORCE] VIEW
VIEW view
view
[(alias[,
[(alias[, alias]...)]
alias]...)]
AS
AS subquery
subquery
[WITH
[WITH CHECK
CHECK OPTION
OPTION [CONSTRAINT
[CONSTRAINT constraint]]
constraint]]
[WITH
[WITH READ
READ ONLY]
ONLY]
Creating a View
Create a view, EMPVU10, that contains details of
employees in department 10.
•• Describe
Describe the
the structure
structure of
of the
the view
view by
by
using
using the
the SQL*Plus
SQL*Plus DESCRIBE
DESCRIBE
command.
command.
SQL>
SQL> DESCRIBE
DESCRIBE empvu10
empvu10
Creating a View
Create a view by using column aliases in the subquery.
EMPLOYEE_NUMBER
EMPLOYEE_NUMBER NAME
NAME SALARY
SALARY
---------------
--------------- ----------
---------- ---------
---------
7698
7698 BLAKE
BLAKE 2850
2850
7654
7654 MARTIN
MARTIN 1250
1250
7499
7499 ALLEN
ALLEN 1600
1600
7844
7844 TURNER
TURNER 1500
1500
7900
7900 JAMES
JAMES 950
950
7521
7521 WARD
WARD 1250
1250
66 rows
rows selected.
selected.
Modifying a View
Modify the EMPVU10 view by using CREATE OR REPLACE
VIEW clause. Add an alias for each column name.
•• Any
Any attempt
attempt to
to change
change the
the department
department number
number for
for any
any row
row
in
in the
the view
view will
will fail
fail because
because itit violates
violates the
the WITH
WITH CHECK
CHECK
OPTION
OPTION constraint.
constraint.
Denying DML Operations
You can ensure that no DML operations occur by
adding the WITH READ ONLY option to your view
definition.
•• Any
Any attempt
attempt to
to perform
perform aa DML
DML on
on any
any row
row in
in
the
the view
view will
will result
result in
in Oracle
Oracle Server
Server error.
error.
Removing a View
Remove a view without losing data because a view is
based on underlying tables in the database.
DROP
DROP VIEW
VIEW view;
view;
1. https://www.db-book.com/db6/slide-dir/index.html
2. https://docs.oracle.com/en/database/oracle/oracle-database/20/sqlrf/SQL-
Standards.html#GUID-BCCCFF75-D2A4-43AD-8CAF-C3C97D92AC63
3. https://www.slideshare.net/HaaMeemMohiyuddin1/data-knowledge-and-
information
4. https://www.slideshare.net/tabinhasan/from-data-to-wisdom
5. https://www.slideshare.net/thinnaphat.bo/