Chapter 11-Creating Other Schema Objects ---Sequence
2013-04-10 13:58
295 查看
Sequences
A sequence:Can automatically generate unique numbers
Is a shareable object
Can be used to create a primary key value
Replace application code
Speeds up the efficiency of accessing sequence values when cached in memory.
CREATE SEQUENCE Statement Syntax
Define a sequence to generate sequential numbers automatically:CREATE SEQUENCE sequence [INCREMENT BY n] [START WIT n] [{MAXVALUE n | NOMAXVALUE}] [{MINVALUE n | NOMINVALUE}] [{CYCLE | NOCYCLE}] [{CACHE n | NOCACHE}]
Creating a Sequence
Create a sequence named DEPT_DEPTID_SEQ to be used for the primary key of the DEPARTMENTS table,and Do not use the CYCLE optionCREATE SEQUENCE dept_deptid_seq INCREMENT BY 10 START WITH 120 MAXVALUE 9999 NOCACHE NOCYCLE;
NEXTVAL and CURRVAL Pseudocolumns
NEXTVAL returns the next available sequence value.It returns a unique value every time it is referenced,even for different users.
CURRVAL obtains the current sequence value.
NEXTVAL must be issued for that sequence before CURRVAL contains a value.
使用SEQUENCE
如果首次创建SEQUENCE dept_deptid_seq,执行SELECT dept_deptid_seq.CURRVAL FROM DUAL;会报错SQL> select dept_deptid_seq.currval from dual; select dept_deptid_seq.currval from dual * ERROR at line 1: ORA-08002: sequence DEPT_DEPTID_SEQ.CURRVAL is not yet defined in this session
必须先执行SELECT dept_deptid_seq.NEXTVAL FROM DUAL;然后再执行SELECT dept_deptid_seq.CURRVAL FROM DUAL;
Caching Sequence Values
Caching sequence values in memory gives faster access to those valuesGaps in sequence values can occur when:
-A rollback occurs
-The system crashes
-A sequence is used in another table
Modifying a Sequence
Change the increment value,maximum value,minimum value,cycle option,or cache option,but you can not modify the start with keywordALTER SEQUENCE dept_deptid_seq INCREMENT BY 20 MAXIMUM 999999 NOCACHE NOCYCLE;
Guidelines for Modifying a Sequence
You must be the owner or have the ALTER privilege for the sequenceOnly future sequence numbers are affected
The sequence must be dropped and re-created to restart the sequence at a different number
Some validation is performed
Drop Sequence
To remove a sequence ,use the DROP SEQUENCE statementDROP SEQUENCE dept_deptid_seq;
相关文章推荐
- Chapter 11-Creating Other Schema Objects ---Synonym
- Chapter 11-Creating Other Schema Objects ---View
- Chapter 11-Creating Other Schema Objects ---Index
- Learning C++ by Creating Games With UE4(15.05.21)(Chapter 11-4)Monster
- Data Structures and Other Objects Using C++ (Chapter 1) 学习笔记三
- Data Structures and Other Objects Using C++ (Chapter 1) 学习笔记一
- Data Structures and Other Objects Using C++ (Chapter 2) 学习笔记四
- advanced dom scripting dynamic web design techniques Chapter 2 CREATING YOUR OWN REUSABLE OBJECTS
- Imperfect C++:Chapter 11 Statics:11.3Function-Local static objects
- Learning C++ by Creating Games With UE4(15.05.21)(Chapter 11-2)Monster
- Learning C++ by Creating Games With UE4(15.05.20)(Chapter 11-1)Monster
- 11G Concept 第四章翻译 Partitions, Views, and Other Schema Objects(分区,视图,以及其他Schema Objects)
- 【Chapter-1】Creating and destorying objects
- Data Structures and Other Objects Using C++ (Chapter 2) 学习笔记五
- Data Structures and Other Objects Using C++ (Chapter 1) 学习笔记二
- Learning C++ by Creating Games With UE4(15.05.21)(Chapter 11-3)Monster
- 钱能第二版 chapter 2 10 11 答案
- 零元学Expression Blend 4 - Chapter 11 用实例了解布局容器系列-「Border」
- !!!Obj-C 2.0 -- Chapter 1 Objects, Classes, and Messaging
- accelerated cpp chapter 11 定义抽象数据类型