select lpad(to_char(SEQ_jxuser.nextval),8,'0') from dual
SEQ_jxuser为所建的sequences名称
/**
* 产生序列号
* @param tableName SEQ_名称
* @return String 序列号
* @throws SQLException SQL异常
*/
public synchronized String getSequenceId(String tableName)
throws SQLException {
StringBuffer sequenceBuffer = new StringBuffer();
sequenceBuffer.append("SELECT ");
sequenceBuffer.append("lpad(to_char(");
sequenceBuffer.append(tableName);
sequenceBuffer.append(".nextval)");
sequenceBuffer.append(",8,'0'");
sequenceBuffer.append(") ");
sequenceBuffer.append("FROM ");
sequenceBuffer.append("dual");
Statement sequenceMent = connection.createStatement();
ResultSet sequenceRs = null;
try {
sequenceRs = sequenceMent.executeQuery(sequenceBuffer.toString());
if (sequenceRs == null ||!sequenceRs.next()) {
return null;
} else {
return sequenceRs.getString(1);
}
} finally {
if (sequenceRs != null) {
try {
sequenceRs.close();
} catch (SQLException e) {
log.error("SQLException", e);
}
}
}
}
-- Create sequence
create sequence SEQ_JXUSER
minvalue 1
maxvalue 99999999
start with 5941
increment by 1
cache 20;