当前位置:网站首页>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_AGE
notes :
(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 2
alter sequenct You can modify the sequence , Do not modify start with
边栏推荐
- JS form get form & get form elements
- Zero knowledge private application platform aleo (1) what is aleo
- VM virtual machine operating system not found and NTLDR is missing
- 主设备号和次设备号均为0
- NanopiNEO使用开发过程记录
- The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?
- Organize five stages of actual attack and defense drill
- Gpt-3 is a peer review online when it has been submitted for its own research
- Win11远程桌面连接怎么打开?Win11远程桌面连接的五种方法
- EasyCVR无法使用WebRTC进行播放,该如何解决?
猜你喜欢
Win11截图键无法使用怎么办?Win11截图键无法使用的解决方法
Oracle -- 视图与序列
Video fusion cloud platform easycvr video Plaza left column list style optimization
Basic idea of counting and sorting
Vscode 如何使用内置浏览器?
What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III
[ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
随机推荐
Advertising attribution: how to measure the value of buying volume?
Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
ESG Global Leaders Summit | Intel Wang Rui: coping with global climate challenges with the power of science and technology
The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly
namespace基础介绍
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
MySQL forgot how to change the password
SQL where multiple field filtering
Basic idea of counting and sorting
Organize five stages of actual attack and defense drill
每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报
How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
【实践出真理】import和require的引入方式真的和网上说的一样吗
案例大赏:英特尔携众多合作伙伴推动多领域AI产业创新发展
jvm是什么?jvm调优有哪些目的?
Poor math students who once dropped out of school won the fields award this year
ESG全球领导者峰会|英特尔王锐:以科技之力应对全球气候挑战
[on automation experience] the growth path of automated testing
B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
A detailed explanation of head pose estimation [collect good articles]