序列sequence中的cache问题

序列sequence中的cache问题,第1张

概述Oracle中序列Sequence的创建语法如下:CREATE SEQUENCE [ schema. ] sequence [ { INCREMENT BY | START WITH } intege

Oracle中序列Sequence的创建语法如下:

CREATE SEQUENCE [ schema. ] sequence   [ { INCREMENT BY | START WITH } integer   | { MAXVALUE integer | NOMAXVALUE }   | { MINVALUE integer | NOMINVALUE }   | { CYCLE | NOCYCLE }   | { CACHE integer | NOCACHE }   | { ORDER | NOORDER }   ]...;

在sequence的创建语句中,

The CACHE clause preallocates a set of sequence numbers and keeps them in memory so that sequence numbers can be accessed faster. When the last of the sequence numbers in the cache has been used,the database reads another set of numbers into the cache.

The database might skip sequence numbers if you choose to cache a set of sequence numbers. For example,when an instance abnormally shuts down (for example,when an instance failure occurs or a SHUTDOWN ABORT statement is issued),sequence numbers that have been cached but not used are lost.

--下面我们来做个试验测试一下,创建序列如下:

sql> create sequence s1 
2 start with 10
3 increment by 10
4 maxvalue 1000000000000000000000
5 cycle 
6 cache 10;

sql> select s1.nextval from dual;

NEXTVAL
----------
         10

sql> shutdown abort

sql> startup

sql> select s1.nextval from dual;

NEXTVAL
----------
       110

sql> /

NEXTVAL
----------
        120

sql> shutdown immediate

sql> startup

sql> select s1.nextval from dual;

NEXTVAL
----------
        130

由此可见,在数据库异常关闭时,cache中预存的序列值全部丢失,在本例中预存了10个值,从10到100,。重新启动数据库后,下一个序列值从120开始。而数据库在正常关闭时,cache中预存的序列值不会丢失。

总结

以上是内存溢出为你收集整理的序列sequence中的cache问题全部内容,希望文章能够帮你解决序列sequence中的cache问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1153740.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存