Oracle views and sequences

Oracle views and sequences

sequence

序列是按照一定规则提供连续数字的对象
序列可以是升序的,也可以是降序的

More simple narrative, the sequence is sql server and mysql in the increment

Creating a Sequence

Create a sequence from using the CREATE SEQUENCE statement? Start

CREATE SEQUENCE 序列名 START  WITH 1;--序列从1开始

1 start with 1- starts from the initial value (i.e., generating a first value) is defined sequences, the default is 1

  1. increment by 1 - incremented by 1 each time, if omitted, it defaults to 1, if the value is negative, the emergence of the sequence in steps of decreasing.
  2. MAXVALUE 2000 - 2000 maximum, the maximum value defined sequence generator can produce. NOMAXVALUE option is the default option, representing no maximum is defined, then the system can generate a maximum of 10 ^ 27, the maximum decrement is -1 sequence.
  3. MINVALUE 10 - Minimum 10, MINVALUE defined sequence generator to produce the minimum. NOMAXVALUE option is the default option, representing no defined minimum, the minimum time a descending sequence can be generated by the system 10 to the power 26; 1 is the minimum for increasing sequence.
  4. NOCYCLE - indicates whether the cycle after the sequence generator when the value reaches the limit value. CYCLE behalf cycle, the cycle is not representative of NOCYCLE
  5. CACHE - the size of the memory block storing the sequence defined, the default is 20. NOCACHE not expressed sequence buffer memory. : Sequence of memory buffer, sequence performance can be improved.
  6. NEXTVAL - the sequence of the next valid value
  7. CURRVAL - the current value
To access the value sequence by the pseudo-column sequence
SELECT sext_id.NEXTVAL FROM dual;--查询下一个值
SELECT sext_id.CURRVAL FROM dual;--查询当前值
Use sequence
INSERT INTO 表名 VALUES (序列名.nextval,name,age);
Change the sequence

Step 3 of the sequence to

 ALTER SEQUENCE 序列名 increment by 3;
Delete sequence
  DROP SEQUENCE 序列名;

view

Create the view must be assigned to user rights
视图以经过定制的方式显示来自一个或多个表的数据
视图可以视为'虚拟表'或'存储的查询'
创建视图所依据的表称为'基表'
视图的优点有
    --提供了另外一种级别的表安全性
    --隐藏的数据的复杂性
    --简化的用户的SQL命令
    --隔离基表结构的改变
    --通过重命名列,另一个角度提供数据
Create a view

Simple view is: is to a table or multiple-table query side, and then saved, directly after the query view, do not check more than one table in the.

  CREATE VIEW 视图名 AS SELECT * from 表名;
Create a view with a check constraint
 使用WITH CHECK OPTION 选项创建视图,当通过试图对底层表进行的 insert ,update 操作必须保证操作结果也在视图中,不允许操作后使视图中的数据减少
  CREATE VIEW 视图名 AS SELECT * from 表名 WITH CHECK OPTION 
ORDER BY clause to create a view
  CREATE VIEW 视图名 AS SELECT * from 表名 ORDER BY 字段名;
Create a read-only view, which can only be used to query
  CREATE VIEW 视图名 AS SELECT * from 表名 WITH READ ONLY;
Create a Link View
 创建链接视图,注意:主键表中的列不能修改,主键表称为建保留表是指基于多个表所创建的视图,即定义视图的查询是一个连接查询。     
 主要目的是为了简化连接查询;
 更新基表,视图也发生相应的更改
create view 视图名 as 两表联合查询;   
Published 68 original articles · won praise 7 · views 2538

Guess you like

Origin blog.csdn.net/Cui6023056/article/details/103858429