Oracle视图

来源:互联网 发布:手机电量显示软件 编辑:程序博客网 时间:2024/05/18 01:06

视图并不真正存储数据,其数据来自引用的表,oracle只在数据字典中存储视图的定义信息。

创建视图:                                                                                                        

create[or replace] view <view_name> [alias[,alias]...]--alias别名,若子查询包含函数和表达式必须定义

as <subquery>                                                              --subquery 子查询语句

[with check option] [constraint constraint_name]      --with check option 指定在视图上的check约束

[with read only]                                                  --with read only 只读视图

 

建立只读视图:

create or replace  view stu_view as

select  * from stu  where classid=4

with read only;

用户只能对该视图进行select操作,不能dml

 

建立复杂视图:

create or replace view emp_view as

select deptno 部门编号,max(sal) 最高工资 avg(平均工资)  from emp group by deptno;

select * from emp_view order by 部门编号;

 

管理视图:                                                                                             

查看视图定义:

desc stu_view;

select  text from user_views where view_name='STU_VIEW';

重新编译视图:

当引用表的定义改变后,视图标记为无效。当调用该视图时oracle重新编译。也可以手动编译

alter view stu_view compile;

删除视图:

drop view stu_view; 

 

 

原创粉丝点击