oracle怎么生成sequence
1个回答
展开全部
创建:
create sequence seq_test
minvalue 1
maxvalue 21
start with 1
increment by 1
cache 20
cycle
order;
minvalue 1 / nominvalue:最小值为1
maxvalue 21 / nomaxvalue:最大值为21
start with 1:从1开始计数
increment by 1:每次增加1
cache 20 / nocache:
缓存20个sequence值 / 不缓存
如果缓存,则会有跳号的危险:如果指定cache值,oracle就可以预先在内存里面放置一些sequence,这样存取的快些。内存里面的取完后,oracle自动再取一组到内存。数据库突然不正常down掉,内存中的sequence就会丢失
cycle / nocycle:
cycle,即如果到达最大值21后,再次从1开始
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
21
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
1
nocycle:
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
21
SQL> select seq_test.nextval from dual;
select seq_test.nextval from dual
ORA-08004: sequence SEQ_TEST.NEXTVAL exceeds MAXVALUE and cannot be instantiated
order / noorder:
order:guarantees sequence numbers are generated in order of request,按照请求的顺序生成sequence值。如果sequence值为时间戳比较重要,作为主键order选项没什么用
noorder:does not guarantee sequence numbers are generated in order of
request.
查询:
currval=返回sequence的当前值
nextval=增加sequence的值,然后返回sequence 值
在使用currval之前必须先使用nextval:
SQL> select seq_test.currval from dual;
select seq_test.currval from dual
ORA-08002: sequence SEQ_TEST.CURRVAL is not yet defined in this session
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
1
SQL> select seq_test.currval from dual;
CURRVAL
----------
1
第一次使用nextval返回的是初始值,以后再使用nextvl返回的是currval+'increment by'的值:
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
1
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
2
删除:
SQL> drop sequence seq_test;
Sequence dropped
create sequence seq_test
minvalue 1
maxvalue 21
start with 1
increment by 1
cache 20
cycle
order;
minvalue 1 / nominvalue:最小值为1
maxvalue 21 / nomaxvalue:最大值为21
start with 1:从1开始计数
increment by 1:每次增加1
cache 20 / nocache:
缓存20个sequence值 / 不缓存
如果缓存,则会有跳号的危险:如果指定cache值,oracle就可以预先在内存里面放置一些sequence,这样存取的快些。内存里面的取完后,oracle自动再取一组到内存。数据库突然不正常down掉,内存中的sequence就会丢失
cycle / nocycle:
cycle,即如果到达最大值21后,再次从1开始
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
21
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
1
nocycle:
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
21
SQL> select seq_test.nextval from dual;
select seq_test.nextval from dual
ORA-08004: sequence SEQ_TEST.NEXTVAL exceeds MAXVALUE and cannot be instantiated
order / noorder:
order:guarantees sequence numbers are generated in order of request,按照请求的顺序生成sequence值。如果sequence值为时间戳比较重要,作为主键order选项没什么用
noorder:does not guarantee sequence numbers are generated in order of
request.
查询:
currval=返回sequence的当前值
nextval=增加sequence的值,然后返回sequence 值
在使用currval之前必须先使用nextval:
SQL> select seq_test.currval from dual;
select seq_test.currval from dual
ORA-08002: sequence SEQ_TEST.CURRVAL is not yet defined in this session
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
1
SQL> select seq_test.currval from dual;
CURRVAL
----------
1
第一次使用nextval返回的是初始值,以后再使用nextvl返回的是currval+'increment by'的值:
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
1
SQL> select seq_test.nextval from dual;
NEXTVAL
----------
2
删除:
SQL> drop sequence seq_test;
Sequence dropped
TableDI
2024-07-18 广告
2024-07-18 广告
VLOOKUP是Excel中用于垂直查找的函数,其基本用法包括四个参数:1. 查找值:即在数据表首列中需要搜索的值。2. 数据表:包含查找值的单元格区域或数组。3. 返回值所在列数:指定返回查询区域中第几列的值。4. 查找方式:选择精确匹配...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询