--- oracle database view

Permission to create a view to the user scott
[Oracle @ localhost ~] $ sqlplus / AS SYSDBA
the SQL> Grant Create View to C ## scott;
then connect scott user creating the view
the SQL> Conn C ## scott / Oracle
the SQL> Create View MyView AS SELECT D .deptno, d.dname, d.loc, COUNT (e.empno) COUNT, NVL (AVG (e.sal), 0) AVG
2 EMP from E, D Dept
. 3 WHERE e.deptno (+) = d.deptno
4 group by d.deptno, d.dname, d.loc ;
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
and the view can not be duplicate names , if an error occurs in the creation of a named myview of view
with the same name to be deleted before the view

If the view exists to replace, if it does not exist create
replacement:
SQL> the Create or the replace View MyView AS the SELECT * from emp the WHERE deptno = 10;
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
recreate:
SQL> the Create or the replace View mypp AS the SELECT * from emp the WHERE deptno = 10;
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:

Two options to create a view

Option 1: WITH CHECK OPTION not represent the view update to create conditions
such as the creation of conditions myview view deptno = 10;
to create a condition update:
the SQL> Update myview SET = DEPTNO 20 is WHERE EMPNO = 7782;
visible after updating the user information but not
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
this time emp table department number originally No. 10 of 7782 employees of related data have also changed
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
go back to the data:
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
coverage myview view, add a condition to create conditions so that he can not change:
SQL> or the replace the create view myview aS
2 the SELECT * from emp where deptno = 10 with check option;
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
try again to create the conditions change:
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
prompt error can not modify the view to create conditions.
Option 2: WITH READ ONLY
the above options make creating a condition that can not be updated, but other fields can still update
SQL> update myview set sal = 9999 where empno = 7782
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
it will change its read-only mode, the other fields can not be modified
SQL > or the replace the create view MyView aS
2 the SELECT * from emp the WHERE deptno = 10
3 with the Read only;
you will be prompted to view a read-only view of the modified again this time, can not be updated
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
to create a query to view statistical operations
The SQL> Create View MyView Replace or AS
2 SELECT d.dname, d.deptno, d.loc, COUNT (e.ename) COUNT, AVG (e.sal) AVG
. 3 EMP from E, D Dept
. 4 WHERE e.deptno ( +) = d.deptno
5 Group by d.deptno, d.dname, d.loc;
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
for which data is updated, you will find can not be updated because the data in this view is based on statistics obtained by
Hypertext Transfer Protocol http + ssl certification --- https - between the application layer and the transport layer plus Ssl built on tcp, three characteristics:
deleting the view:
SQL> drop view myview; View dropped.

Published 31 original articles · won praise 19 · views 1449

Guess you like

Origin blog.csdn.net/Alkaid__3/article/details/104314825