当前位置:网站首页>Oracle -- 视图与序列
Oracle -- 视图与序列
2022-07-06 22:12:00 【攀登程序猿】
视图定义
是从一个或者多个数据表中导出的虚表(虚拟表),视图所对应的数据并不真正的存储在数据库中,比如将一个查询的结果定义为视图,则直接查询视图即可
优点:
(1)简化数据的操作:视图可以简化用户处理数据的方式
(2)着重与特定数据:不必要的数据或敏感数据可以不出现在视图中
(3)安全机制,不同的用户对数据访问权限不一样
(4)提供向后监控性,表改变,视图可以不变
视图操作
特点:
(1)视图不会实际存储,当视图允许修改时,修改视图中的数据,则表中的数据也被修改
(2)只读视图不允许修改数据
(3)带约束的视图
(4)多表关联也可以修改数据,基表的数据会跟随修改
create VIEW classstudent AS SELECT * FROM TBL_STUDENTS
// or replace是视图存在时,替换成新的,with check option是带检查约束的视图
create OR REPLACE VIEW classstudent AS SELECT * FROM TBL_STUDENTS WITH CHECK OPTION
// 创建只读视图
create OR REPLACE VIEW classstudent AS SELECT * FROM TBL_STUDENTS WITH READ ONLY
// 强制视图,即表不存在时创建的视图,用于动态生成表的场景
CREATE force VIEW view_test as SELECT * from tbl_test
// 复杂视图 多表查询,允许修改数据,会键保留表
CREATE VIEW view_student_class AS
SELECT * FROM TBL_STUDENTS JOIN TBL_CLASSES ON TBL_STUDENTS.STU_CID = TBL_CLASSES.CLASS_ID
// 聚合视图,聚合函数必须有列名
CREATE VIEW view_student as
SELECT COUNT(*) as count,STU_AGE as age FROM TBL_STUDENTS GROUP BY STU_AGE注:
(1)键保留表,对于可更新的视图,在视图中的行和基表中的行之间必须具有一对一的关系,因为这样才能够反向映射到原基础表
(2)聚合函数做视图必须有列名
(3)聚合函数的视图无法修改
物化视图
物化视图是将查询的结果建立副本,占用存储空间,查询效率会高,但是会占用空间,未解决权限问题,后续学习。
更新方式:
COMPLETE 完全更新
FAST 增量更新,根据基表的更新日志,判断视图是否需要更新
ON COMMIT是在基表变化时刷新物化视图
ON COMMON是手动刷新
BUILD IMMEDIATE 创建视图时生成数据
ORA-01031: insufficient privileges

序列
创建一系列数字,mysql的主键自增是直接写的,oracle是需要创建序列的
--创建简单序列
CREATE sequence seq1;
--查询序列的下一个值,执行一次递增一个
SELECT seq1.NEXTval from dual;
--查询序列的当前值
select seq1.currval from dual;
CREATE sequence seq_withMax
maxvalue 20; --创建带有最大值的
SELECT seq_withMax.nextval FROM dual; -- 从一开始,每次递增1,最大到20
-- 跳跃的序列
CREATE sequence seq3
INCREMENT BY 2 -- 默认是1
START WITH 1000 --递增默认是MaxValue,递减是minvalue
maxvalue 1002
minvalue 100
cycle --是否循环 nocycle
cache 10; -- 每次放到内存中10个值,默认使用cache 20,不使用cache时配置为nocache,磁盘中保存到10了,缓存到20了,此时重启服务会从21开始,造成断号,有缓存必须小于一次的循环,即cache默认20*INCREMENT by = 200个,得比cache是10,小于200
select seq3.nextval from dual; -- 从1000开始,每次递增2,到1002后,重新从100开始
CREATE sequence seq4
INCREMENT BY -2
START WITH 1000
maxvalue 1001;
SELECT seq4.nextval FROM dual; -- 从1000开始,每次递减2alter sequenct可以修改序列,不能修改start with
边栏推荐
- Golang compresses and decompresses zip files
- 英特尔David Tuhy:英特尔傲腾技术成功的原因
- The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?
- Digital chemical plant management system based on Virtual Simulation Technology
- Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
- Fix the problem that the highlight effect of the main menu disappears when the easycvr Video Square is clicked and played
- sscanf,sscanf_s及其相关使用方法「建议收藏」
- Mathematical analysis_ Notes_ Chapter 10: integral with parameters
- 两个div在同一行,两个div不换行「建议收藏」
- kivy教程之设置窗体大小和背景(教程含源码)
猜你喜欢
![[team learning] [34 sessions] Alibaba cloud Tianchi online programming training camp](/img/50/bfe7229d380a514c40f9f6822381c7.jpg)
[team learning] [34 sessions] Alibaba cloud Tianchi online programming training camp

树与图的深度优先遍历模版原理

Intel and Xinbu technology jointly build a machine vision development kit to jointly promote the transformation of industrial intelligence

Video fusion cloud platform easycvr video Plaza left column list style optimization

How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection

Intel David tuhy: the reason for the success of Intel aoten Technology

namespace基础介绍

AI 落地新题型 RPA + AI =?

What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash

The request request is encapsulated in uni app, which is easy to understand
随机推荐
Gpt-3 is a peer review online when it has been submitted for its own research
EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
How to write a resume that shines in front of another interviewer [easy to understand]
True Global Ventures新成立的1.46亿美元后续基金关账,其中普通合伙人认缴6,200万美元以对后期阶段的Web3赢家进行投资
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
【自动化经验谈】自动化测试成长之路
EasyCVR集群版本添加RTSP设备提示服务器ID错误,该如何解决?
NFT meta universe chain diversified ecosystem development case
Poor math students who once dropped out of school won the fields award this year
【实践出真理】import和require的引入方式真的和网上说的一样吗
JetBrain Pycharm的一系列快捷键
MySQL null value processing and value replacement
Digital chemical plant management system based on Virtual Simulation Technology
Win11玩绝地求生(PUBG)崩溃怎么办?Win11玩绝地求生崩溃解决方法
MySQL forgot how to change the password
Mathematical analysis_ Notes_ Chapter 10: integral with parameters
Win11图片打不开怎么办?Win11无法打开图片的修复方法
Nanopineo use development process record
This "advanced" technology design 15 years ago makes CPU shine in AI reasoning