一 sequence的定义
oracle中定义:
create sequence test minvalue 1 maxvalue 1000 start with 1 increment by 1 cache 20 nocycle order;
DB2中定义:
create sequence test as bigint start with 1 increment by 1 minvalue 1 nomaxvalue nocycle cache 20 order;
二 sequence 的读取
oracle中读取
select test.nextValue from dual;
db2 中读取
select next value for seq_logid from Sysibm.sysdummy1
三 sequence的作为字段插入
oracle中插入
insert into test_table(id ,name) values(test.nextvalue,"testName");
db2中插入
insert into test _table(id,name) values(next value for test,"testName")
四 java调用sequence方法
Connection conn;
PreparedStatement ps=null;
try{
conn=this.getConnection();//此方法自己实现
String insSql="insert into test_table(uid,name) VALUES(NEXT VALUE FOR test,?)";
ps=conn.prepareStatement(insSql);
ps.setString(1, “test name”);
ps.execute();
ps.close();
ps=null
}catch(Exception e) {
//......
}finally{
//....
}