zoukankan      html  css  js  c++  java
  • sequence使用

    SQL> create sequence seq1
    minvalue 1
    maxvalue 999999999999999999999999999
    start with 0
    increment by 1
    cache 20;  2    3    4    5    6 
    create sequence seq1
    *
    ERROR at line 1:
    ORA-04006: START WITH cannot be less than MINVALUE

    提示 起始值不能小于最小值

    SQL> create sequence seq1
    minvalue 1
    maxvalue 999999999999999999999999999
    start with 1
    increment by 1
    cache 20;  2    3    4    5    6 

    Sequence created.

    SQL> select sequence_name,cache_size,last_number  from dba_sequences where sequence_name='SEQ1';

    SEQUENCE_NAME         CACHE_SIZE LAST_NUMBER
    ------------------------------ ---------- -----------
    SEQ1           20     1

    SQL>  select seq1.nextval from dual;

       NEXTVAL
    ----------
      1

    SQL> /

       NEXTVAL
    ----------
      2

    SQL> select sequence_name,cache_size,last_number  from dba_sequences where sequence_name='SEQ1';

    SEQUENCE_NAME         CACHE_SIZE LAST_NUMBER
    ------------------------------ ---------- -----------
    SEQ1           20    21

    SQL>  select seq1.nextval from dual;

       NEXTVAL
    ----------
      3

    SQL> select sequence_name,cache_size,last_number  from dba_sequences where sequence_name='SEQ1';

    SEQUENCE_NAME         CACHE_SIZE LAST_NUMBER
    ------------------------------ ---------- -----------
    SEQ1           20    21


    一次分配20到shared pool中

    last_number:
    Last sequence number written to disk. If a sequence uses caching, the number written to disk is the last number placed in the sequence cache. This number is

    likely to be greater than the last sequence number that was used.

    修改cahce大小对sequence的影响呢?

    SQL> alter sequence seq1 cache 1000;

    Sequence altered.

    SQL> select sequence_name,cache_size,last_number  from dba_sequences where sequence_name='SEQ1';

    SEQUENCE_NAME         CACHE_SIZE LAST_NUMBER
    ------------------------------ ---------- -----------
    SEQ1         1000     4

    SQL>  select seq1.nextval from dual;

       NEXTVAL
    ----------
      4

    SQL> select sequence_name,cache_size,last_number  from dba_sequences where sequence_name='SEQ1';

    SEQUENCE_NAME         CACHE_SIZE LAST_NUMBER
    ------------------------------ ---------- -----------
    SEQ1         1000  1004

    那么使用cache是否会导致断号呢?
    重启数据库后:
    SQL>  select seq1.nextval from dual;

       NEXTVAL
    ----------
      5

    SQL> select sequence_name,cache_size,last_number  from dba_sequences where sequence_name='SEQ1';

    SEQUENCE_NAME         CACHE_SIZE LAST_NUMBER
    ------------------------------ ---------- -----------
    SEQ1         1000  1005

    居然没有断号,再次重启数据库

    SQL> select seq1.nextval from dual;

       NEXTVAL
    ----------
          1005

    SQL> select sequence_name,cache_size,last_number  from dba_sequences where sequence_name='SEQ1';

    SEQUENCE_NAME         CACHE_SIZE LAST_NUMBER
    ------------------------------ ---------- -----------
    SEQ1         1000  2005
    此时已经断号

  • 相关阅读:
    C#调用webservice 时如何传递实体对象
    Gridview实现突出显示某一单元格的方法
    oracle数据库存储过程分页
    GridView合并表头多重表头
    Gridview中实现求和统计功能
    C#封装的一个JSON操作类
    C#通过StreamWriter对象实现把数值内容写到记事本
    Android CTS
    离线安装eclipse maven插件
    selenium2 页面对象模型Page Object
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/3798083.html
Copyright © 2011-2022 走看看