1. Why Use views
(1) Restricting access to data: Users can only see part of the information in the base table.
(2) Making complex queries easy: The data in the view may come from multiple tables.
(3) Make the data relatively independent: from the perspective of project development, the module corresponding to the view, the module contains more than one table, the module changes only to modify the corresponding view, the corresponding table structure without modification.
(4) representing different perspectives on the same data: employees from different departments can only see the information in the department.
2. Create a View
CREATE VIEW Empvu10
As SELECT empno, ename, Job
From EMP1
WHERE deptno=30
/(The ORDER BY clause cannot be used in queries that define views)
3. Query view
The SELECT statement for the view definition is saved in the Long text field.
Use set long 150 to increase the LONG maximum display width, default to 80
SELECT * FROM User_views
/
Syntax description
CREATE [OR REPLACE] [force| Noforce] View View
[(alias[, alias] ...)]
As subquery
[With CHECK OPTION [CONSTRAINT CONSTRAINT]]
[with READ only];
Or REPLACE If the view already exists, it is equivalent to modifying the view
FORCE | [Noforce] Create a view regardless of whether the base table exists [only base table existence can be created]
With CHECK OPTION the INSERT and update operations performed through the view cannot create rows of data that are not retrieved by the view
With READ only disables DML operations on the view
4. Create a complex view
You cannot modify the data of a base table by modifying the view
CREATE VIEW Dept_sum_vu
(dname,minsal,maxsal,avgsal)
As SELECT d.dname,min (e.sal),
MAX (SAL), AVG (SAL)
From EMP e,dept D
WHERE E.deptno=d.deptno
GROUP by D.dname
/
Data comes from multiple tables, using grouping functions in queries