- Creating a simple view
- the establishment of employee number, name, salary views for queries.
View emp_view Create
AS
SELECT EMPNO, ename, SAL from EMP;
- Query view
select * from emp_view;
- specify the view when you create a view column alias
create view emp_view2 (employee number, name, salary)
AS
the SELECT empno, ename, SAL from emp;
- Query view
select * from emp_view2;
- Connection View
- established for acquiring the department number for the department number 10, the name of the department and employee information.
View dept_emp_view Create
AS
SELECT d.deptno, d.dname, e.empno, e.ename, e.job
from Dept D, E EMP
WHERE d.deptno = e.deptno and d.deptno = 10;
- Query view
select * from dept_emp_view;
- read-only view
- to see the establishment of 10 departments of the view employee information.
View emp_view3 Create
AS
SELECT * from EMP WHERE DEPTNO = 10
with Read only;
- View the query
SELECT * from emp_view3;
- Test
Update emp_view3 SET SAL SAL = +50;
- the DML operations on a view
- Create view
the Create View empnew_view
AS
the SELECT empno, ename, SAL from empnew;
--select
select * from empnew_view;
--insert
insert into empnew_view(empno,ename,sal) values(8888,'LAYNA',6666);
select * from empnew;
--update
update empnew_view set sal = sal + 100 where empno = 8888;
--delete
delete from empnew_view where empno = 8888;
commit;
- check constraints defined on the view
Create View empnew_view2
AS
SELECT * WHERE DEPTNO = 20 is from empnew
with check constraint ck_view Option;
- Query view
select * from empnew_view2;
--测试
--insert或update
update empnew_view2 set deptno = 30 where empno = 7566;
- Modify the view
- before modifying the query
select * from empnew_view;
--修改empnew_view视图
create or replace view empnew_view
as
select * from emp where job = 'SALESMAN';
- After modifying the query
select * from empnew_view;
- Delete view
drop view empnew_view;
select * from emp;
- creating complex view
Create View job_view (Job, avgsal, sumsal, maxsal, minsal)
AS
SELECT Job, AVG (SAL), SUM (SAL), max (SAL), min (SAL) from EMP by Job Group;
- View complex view
select * from job_view;
- with read only by a complex view of the shield clause DML operations
Create View job_view
AS
SELECT Job, AVG (SAL) avgsal, SUM (SAL) sumsal, max (SAL) maxsal, min (SAL) from EMP Group minsal by Job
with read only;