Welcome 微信登录

首页 / 数据库 / MySQL / Oracle 中序列使用详解

Oracle 中序列使用详解:create table test 
(pid integer primary key, 
  name varchar(20) 
  ); 
   
  select * from test; 
  insert into test values(1,"Jack"); 
 
create sequence test_seq;--创建序列  
select test_seq.nextval from dual;--每次使用后序列加一  
select test_seq.currval from dual;--查询当前序列的值  
insert into test values(test_seq.nextval,"Jack Or Duck?");--序列的使用  
drop sequence test_seq;--删除序列  
create sequence test_seq start with 8;--指定序列的初始值  
alter sequence test_seq minvalue 9;--设置序列的最小值  
alter sequence test_seq maxvalue 9999;--设置序列的最大值  
alter sequence test_seq increment by 1;--设置序列的步长  
drop sequence test_seq_1; 
create sequence test_seq_1 start with 3 minvalue 1 maxvalue 30 increment by 1; 
select test_seq_1.nextval from dual; 
alter sequence test_seq_1 cycle; 
alter sequence test_seq_1 nocycle;--关闭循环取值功能  
alter sequence test_seq_1 cache 10; 
 
--设置序列缓存大小的作用,注:序列缓存默认为20  
create sequence test_seq_2 start with 1 minvalue 1 maxvalue 20 increment by 3; 
alter sequence test_seq_2 cycle; 
 
--上述语句会报错:Cache值必须小于cycle值  
 
alter sequence test_seq_2 increment by 2; 
alter sequence test_seq_2 cycle; 
--还是报错  
alter sequence test_seq_2 increment by 1; 
alter sequence test_seq_2 cycle; 
--还是报错  
alter sequence test_seq_2 maxvalue 21; 
alter sequence test_seq_2 cycle; 
--不报错了  
 
--或者修改  
alter sequence test_seq_1 cache 5; 
--start with 1 and maxvalue 10 step 1 then 10 times cycle and bigger than 5   了解Oracle权限管理Oracle PL/SQL之对象权限与系统权限的撤销差异相关资讯      Oracle教程 
  • Oracle中纯数字的varchar2类型和  (07/29/2015 07:20:43)
  • Oracle教程:Oracle中查看DBLink密  (07/29/2015 07:16:55)
  • [Oracle] SQL*Loader 详细使用教程  (08/11/2013 21:30:36)
  • Oracle教程:Oracle中kill死锁进程  (07/29/2015 07:18:28)
  • Oracle教程:ORA-25153 临时表空间  (07/29/2015 07:13:37)
  • Oracle教程之管理安全和资源  (04/08/2013 11:39:32)
本文评论 查看全部评论 (0)
表情: 姓名: 字数