- 0
- 0
- 约3.66万字
- 约 31页
- 2023-06-13 发布于北京
- 举报
第十三章:视图
视图本身是一个不包含任何真实数据,只存放视图的定义的虚拟表,数据仍存放在原来的实体表中。
创建视图
create [or replace]
[force | noforce]
view 视图名称
as
子查询
[with check option]
[with read only]
force:表示要创建视图的表存在也可以创建视图。
noforce:表示要创建视图的表必须存在,否则无法创建。
or replace:表示视图的替换,如果创建的视图不存在,则创建新的而试图,如果视图已经存在,则将其替换。
视图的作用
可以加强数据的保密性
可以减少查询的复杂性
视图的DML操作
简单视图的DML操作(一个表)
复杂视图的DML操作(多张表)
[with check option]选项
[with read only]选项
实例13.1 授权scott用户有视图的权限
//登录sys,授权scott有建立视图的权限
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as sys@BEDU AS SYSDBA
SQL grant create any view to scott;
Grant succeeded
SQL
实例13.2 视图实现过程
步骤1:查询部门表
select d.deptno,d.dname,d.loc
from dept d
步骤2:查询员工表部分统计信息
select e.deptno,count(*) num,round(avg(e.sal)) avg_sal
from emp e
group by e.deptno
步骤3:查询员工表信息
select * from emp;
步骤4:删除之前的测试数据
delete from emp where empno in(1111,2222,8888,9999);
步骤5:再次查询员工表信息
select * from emp;
步骤6:笛卡尔查询
select d.deptno, d.dname, d.loc,f.num,f.avg_sal
from dept d,
(select e.deptno, count(*) num, round(avg(e.sal)) avg_sal
from emp e
group by e.deptno) f
where d.deptno = f.deptno
步骤7:将步骤6的笛卡尔查询写入视图
create or replace view v_dept_statics
as
select d.deptno, d.dname, d.loc,f.num,f.avg_sal
from dept d,
(select e.deptno, count(*) num, round(avg(e.sal)) avg_sal
from emp e
group by e.deptno) f
where d.deptno = f.deptno(+)
步骤8:查询视图
select * from v_dept_statics;
步骤9:实体表不存在的时候,报错
create or replace view v_emp
as
select * from emps;
步骤10:先建立视图,不管是否有实体表
create or replace force view v_emp
as
select * from emps;
步骤11:查询视图v_emp
select * from v_emp;
步骤12:创建emps表
create table emps
as
select * from emp;
步骤13:右键重新编译v_emp视图
步骤14:再次查询视图v_emp
select * from v_emp;
步骤15:限制信息显示,提高数据安全性
create or replace force view v_emp
as
select empno,ename,job,mgr,hiredate,deptno from emps where deptno=30;
步骤16:再次查询视图v_emp
select * from v_emp;
实例13.3简单视图的DML操作
步骤1:查看视图
select * from v_emp;
步骤2:查看视图对应的实体表
select * from emps;
步骤3:简单视图增加记录
insert into v_emp(empno,ename,
您可能关注的文档
- 第五章 急救与手术设备_医疗设备原理与临床应用.pptx
- 第一章 绪论_医疗设备原理与临床应用.pptx
- 第八章 外科手术器械_医疗设备质量检测与校准.pptx
- 第二章 医疗器械标准体系_医疗设备质量检测与校准.pptx
- 第九章 医用光学器具及内镜设备_医疗设备质量检测与校准.pptx
- 第六章 放射治疗设备_医疗设备质量检测与校准.pptx
- 第七章 医用超声设备 _医疗设备质量检测与校准.pptx
- 第三章 医用X线诊断设备_医疗设备质量检测与校准.pptx
- 第十一章 临床检验分析设备_医疗设备质量检测与校准.pptx
- 第十章 生命支持与监护设备_医疗设备质量检测与校准.pptx
- 聚焦2025,线上职业技能培训资源库建设现状与挑战报告.docx
- 聚焦2025,职业技能培训课程平台用户留存策略报告.docx
- 康复医疗连锁化扩张政策环境变化与应对措施.docx
- 康复医疗连锁化扩张中的服务模式创新与市场拓展.docx
- 深度解析(2026)《GBT 27570-2011室温硫化甲基硅橡胶》.pptx
- 聚焦2025,职业技能培训课程平台用户满意度提升策略报告.docx
- 创新科技项目申请管理操作规范.docx
- 深度解析(2026)《GBT 27571-2011输送混凝土用橡胶软管及软管组合件》.pptx
- 康复医疗连锁化扩张中的患者满意度提升与医疗服务创新.docx
- 历年高考真题——2002年河北高考语文试卷真题(含答案).doc
原创力文档

文档评论(0)