posts - 325,  comments - 25,  trackbacks - 0
          mysql:   select LAST_INSERT_ID() as lastid
          mssqlsever:  
          public int updatePara(String sql) {
            int id = 0;
            try {
             st = con.createStatement();
             if (st.executeUpdate(sql) == 1) {
              rs = st.executeQuery("SELECT @@IDENTITY AS IDX_NO");
              if (rs.next()) {
               id = rs.getInt(1);
              }
              con.commit();
             } else {
              con.rollback();
             }
            } catch (Exception e) {
             e.printStackTrace();
            }
            return id;
           }

          oracle:
          $query="select seq_atable.currval from dual";
          seq_atable.currval 的值只有在同一次會話中,發生seq_atable.nextval后有效:) 所以不會存在取錯值的問題。

          oracle創建觸發器,不用管ID
          使用序列+觸發器實現自增,插入語句不需要管自增字段
          如:create or replace trigger trg_atable before insert on atable for each row begin select seq_atable.nextval into :new.id from dual; end;

          插入數據:
          create or replace trigger TRG_SEO_ONLINE_PHOTO
            before insert on SEO_ONLINE_PHOTO
            for each row
          begin
            select SEQ_ONLINE_PHOTO.nextval into :new.ONPHOTO_ID from dual;
          end;

          posted on 2008-12-16 13:34 長春語林科技 閱讀(639) 評論(0)  編輯  收藏 所屬分類: util
          <2008年12月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 旬阳县| 广宁县| 蒙城县| 贵定县| 凤城市| 黔西| 安康市| 大邑县| 淮南市| 类乌齐县| 汝州市| 偏关县| 汤阴县| 松潘县| 延川县| 徐汇区| 沂水县| 秭归县| 星子县| 宜州市| 昭平县| 陆河县| 辉县市| 都江堰市| 临安市| 五常市| 吴江市| 周宁县| 四平市| 沙雅县| 三门峡市| 新建县| 横山县| 乳山市| 临江市| 盐亭县| 临西县| 九江县| 大悟县| 黄陵县| 高阳县|