--创建视图
/*
create view empview2
as
select employee_id,last_name,salary from employees where department_id = 80
*/
--修改视图
/*
create or replace view empview2
as
select employee_id,salary from employees where department_id = 80
*/
--创建复杂视图
/*
create or replace view empview3
as
select department_name,avg(salary) avg_sal from employees e,departments d
where e.department_id = d.department_id group by department_name
*/
--删除视图
drop view empview3
--屏蔽视图的DML操作
/*
create view empview4
as
select employee_id,salary from employees where department_id = 80
with read only
*/
--对视图数据进行修改和删除
update empview4 set salary = 1200 where employee_id = 179;
delete from empview4 where employee_id = 179;
PS:视图中使用DML的规定
1.当视图定义中包含以下元素之一时不能使用insert:
组函数;group by 子句;distinct 关键字;rownum 伪列;列的定义为表达式;表中非空的列在视图定义中未包括。
2.当视图定义中包含以下元素之一时不能使用update:
group by 子句;distinct 关键字;rownum伪列;列的定义为表达式;
3.当视图定义中包含以下元素之一时不能使用update:
组函数;group by 子句;distinct 关键字;rownum 伪列。