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 ;
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;
recreate:
SQL> the Create or the replace View mypp AS the SELECT * from emp the WHERE deptno = 10;
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
this time emp table department number originally No. 10 of 7782 employees of related data have also changed
go back to the data:
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;
try again to create the conditions change:
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
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
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;
for which data is updated, you will find can not be updated because the data in this view is based on statistics obtained by
deleting the view:
SQL> drop view myview; View dropped.