开发者博客:www.developsearch.com
序列是oracle特有一个对象,用于产生一系列不重复的数字。
创建序列
- create sequence 序列名
increment by 1 start with 1
nomaxvalue minvalue 1;
删除序列
- drop sequence 序列名;
使用Oracle序列
- 序列.nextval --生成并返回下一个值
- 序列.currval --返回当前序列值
create table t_dept9(
nid number(18) primary key, --部门编号
sname varchar2(30), --部门名称
sdes varchar2(2000) --部门描述
);
create sequence seq_t_dept9 increment by 1 start with 1 nomaxvalue minvalue 1;
insert into t_dept9(nid,sname) values (seq_t_dept9.nextval,’开发部’);
insert into t_dept9(nid,sname) values (seq_t_dept9.nextval,’设计部’);
insert into t_dept9(nid,sname) values (seq_t_dept9.nextval,’实施部’);
-- 创建一个名为SY_NOTE_SALES_INFO_ID的sequence
CREATESEQUENCEECOLOGY.SY_NOTE_SALES_INFO_ID
STARTWITH1
MAXVALUE999999999999999999999999999
MINVALUE1
NOCYCLE
CACHE20
NOORDER;
-- Create sequence
create sequence SEQ_CDH_NEWRBT_SET
minvalue 100000
maxvalue 999999999
start with 100000
increment by 1
cache 20;
// jdbc调用sequence
public long getNextSequenceValue(String sequenceName){
return getJdbcTemplate().queryForLong("select " + sequenceName + ".NEXTVAL from dual");
}
开发者博客:www.developsearch.com