当前位置:网站首页>Oracle - views and sequences
Oracle - views and sequences
2022-07-07 04:42:00 【Climbing procedural ape】
View definition
It is a virtual table exported from one or more data tables ( Virtual table ), The data corresponding to the view is not really stored in the database , For example, define the result of a query as a view , Then you can query the view directly
advantage :
(1) Simplify the operation of data : Views can simplify the way users work with data
(2) Focus on specific data : Unnecessary or sensitive data may not appear in the view
(3) Security mechanism , Different users have different access rights to data
(4) Provide backward monitoring , Table change , The view can remain unchanged
View operation
characteristic :
(1) Views are not actually stored , When the view allows modification , Modify the data in the view , The data in the table is also modified
(2) Read only view does not allow data modification
(3) Views with constraints
(4) Multi table association can also modify data , The data of the base table will be modified
create VIEW classstudent AS SELECT * FROM TBL_STUDENTS
// or replace When the view exists , Replace with a new ,with check option Is a view with check constraints
create OR REPLACE VIEW classstudent AS SELECT * FROM TBL_STUDENTS WITH CHECK OPTION
// Create a read-only view
create OR REPLACE VIEW classstudent AS SELECT * FROM TBL_STUDENTS WITH READ ONLY
// Force view , That is, the view created when the table does not exist , Scenarios for dynamically generating tables
CREATE force VIEW view_test as SELECT * from tbl_test
// Complex view Multi-table query , Allow to modify data , Key retention table
CREATE VIEW view_student_class AS
SELECT * FROM TBL_STUDENTS JOIN TBL_CLASSES ON TBL_STUDENTS.STU_CID = TBL_CLASSES.CLASS_ID
// Aggregate view , Aggregate functions must have column names
CREATE VIEW view_student as
SELECT COUNT(*) as count,STU_AGE as age FROM TBL_STUDENTS GROUP BY STU_AGEnotes :
(1) Key retention table , For updatable views , There must be a one-to-one relationship between the rows in the view and the rows in the base table , Because only in this way can we reverse map to the original base table
(2) The aggregate function must have column names when making views
(3) The view of the aggregate function cannot be modified
Materialized view
Materialized view is to create a copy of the query results , Occupied storage space , Query efficiency will be high , But it will take up space , The permission problem is not solved , Follow up learning .
Update the way :
COMPLETE Completely updated
FAST Incremental updating , According to the update log of the base table , Determine whether the view needs to be updated
ON COMMIT Is to refresh the materialized view when the base table changes
ON COMMON It's a manual refresh
BUILD IMMEDIATE Generate data when creating views
ORA-01031: insufficient privileges

Sequence
Create a series of numbers ,mysql The primary key autoincrement of is written directly ,oracle You need to create a sequence
-- Create a simple sequence
CREATE sequence seq1;
-- The next value of the query sequence , Execute one increment at a time
SELECT seq1.NEXTval from dual;
-- The current value of the query sequence
select seq1.currval from dual;
CREATE sequence seq_withMax
maxvalue 20; -- Create a
SELECT seq_withMax.nextval FROM dual; -- from the beginning , Each increment 1, Maximum to 20
-- Jumping sequence
CREATE sequence seq3
INCREMENT BY 2 -- The default is 1
START WITH 1000 -- The default is MaxValue, Decreasing is minvalue
maxvalue 1002
minvalue 100
cycle -- Whether to circulate nocycle
cache 10; -- Put it into memory every time 10 It's worth , By default cache 20, Don't use cache Is configured as nocache, Save on disk to 10 了 , The cache to 20 了 , At this time, restarting the service will start from 21 Start , Cause punctuation , There must be a cycle with cache less than once , namely cache Default 20*INCREMENT by = 200 individual , Debi cache yes 10, Less than 200
select seq3.nextval from dual; -- from 1000 Start , Each increment 2, To 1002 after , From again 100 Start
CREATE sequence seq4
INCREMENT BY -2
START WITH 1000
maxvalue 1001;
SELECT seq4.nextval FROM dual; -- from 1000 Start , Decrease each time 2alter sequenct You can modify the sequence , Do not modify start with
边栏推荐
- Detect when a tab bar item is pressed
- What is JVM? What are the purposes of JVM tuning?
- True global ventures' newly established $146million follow-up fund was closed, of which the general partner subscribed $62million to invest in Web3 winners in the later stage
- Highly paid programmers & interview questions. Are you familiar with the redis cluster principle of series 120? How to ensure the high availability of redis (Part 1)?
- mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi
- 九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
- EasyCVR无法使用WebRTC进行播放,该如何解决?
- Tiktok may launch an independent grass planting community platform: will it become the second little red book
- 九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
- ESG全球领导者峰会|英特尔王锐:以科技之力应对全球气候挑战
猜你喜欢

Programmers go to work fishing, so play high-end!

NTU notes 6422quiz review (1-3 sections)

The request request is encapsulated in uni app, which is easy to understand

Optimization of channel status offline of other server devices caused by easycvr cluster restart

Dab-detr: dynamic anchor boxes are better queries for Detr translation

Introduction to the PureMVC series

Lessons and thoughts of the first SQL injection

buildroot的根文件系统提示“depmod:applt not found”

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

The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?
随机推荐
Easycvr cannot be played using webrtc. How to solve it?
SQL where multiple field filtering
ACL2022 | 分解的元学习小样本命名实体识别
论文上岸攻略 | 如何快速入门学术论文写作
Have you got the same "artifact" of cross architecture development praised by various industry leaders?
Wechat can play the trumpet. Pinduoduo was found guilty of infringement. The shipment of byte VR equipment ranks second in the world. Today, more big news is here
Five years of automated testing, and finally into the ByteDance, the annual salary of 30W is not out of reach
架构实战训练营|课后作业|模块 6
Depth first traversal template principle of tree and graph
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
Vscode 如何使用内置浏览器?
Unit test asp Net MVC 4 Application - unit testing asp Net MVC 4 apps thoroughly
C # use Siemens S7 protocol to read and write PLC DB block
[team learning] [phase 34] Baidu PaddlePaddle AI talent Creation Camp
A detailed explanation of head pose estimation [collect good articles]
《原动力 x 云原生正发声 降本增效大讲堂》第三讲——Kubernetes 集群利用率提升实践
NanopiNEO使用开发过程记录
EasyCVR视频广场点击播放时,主菜单高亮效果消失问题的修复
Network Security Learning - Information Collection
英特尔David Tuhy:英特尔傲腾技术成功的原因