飞艳小屋

程序--人生--哲学___________________欢迎艳儿的加入

BlogJava 首页 新随笔 联系 聚合 管理
  52 Posts :: 175 Stories :: 107 Comments :: 0 Trackbacks

 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;

posted on 2007-04-23 16:04 天外飞仙 阅读(676) 评论(0)  编辑  收藏 所属分类: Oracle

只有注册用户登录后才能发表评论。


网站导航: