這是創(chuàng)建了一個sequence create sequence S_S_DEPART minvalue 1 maxvalue 999999999999999999999999999 start with 1 increment by 1 nocache; SQL> create sequence S_S_DEPART 2 minvalue 1 3 maxvalue 999999999999999999999999999 4 start with 1 5 increment by 1 6 nocache; Sequence created SQL> select S_S_DEPART.nextval from dual; NEXTVAL ---------- 1 SQL> SQL> select S_S_DEPART.nextval from dual; NEXTVAL ---------- 2 以上是測試代碼: 在java中的應用如下: /** * 獲取項目的序列號 * @author 劉威 * @return 項目序列號str */ public String getProjectSn(){ String snNum = "P20"; Session session = this.getSession(); String sql="select PROJECT_SEQ.nextval from dual"; Query query = session.createSQLQuery(sql); snNum = snNum + query.uniqueResult().toString(); return snNum; } |
|
來自: 走墨 > 《hibernate》