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#变量小例子:模拟用户登入
    防盗监控系统小程序端
    java入门学习
    JAVA字符串处理函数汇总
    Freemarker学习
    监听器(Listener)
    正则表达式
    过滤器(Filter)
    HTML百宝箱(1从0开始)
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/3798083.html
Copyright © 2011-2022 走看看