Oracle-view小结

前端之家收集整理的这篇文章主要介绍了Oracle-view小结前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
--创建视图
/*
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 伪列。

猜你在找的Oracle相关文章