对于已经创建的表,在特殊需求下,需要增加一个自增长列步骤:
--1. 增加 自增长列 Alter Table Limsbusinessenregisterinfo Add IdNum Number(18); --2. 程序方式更新设置 IdNum 列 值 --3.查询最大 Select (Max(IdNum)+1) From Limsbusinessenregisterinfo; --4. 创建 自增长初始种子值 序列 Create sequence seq_beReg_IdNum start with 2417 increment by 1; --5. 创建触发器,插入时 自增长的值 CREATE OR REPLACE TRIGGER trg_beReg_IdNum Before Insert On Limsbusinessenregisterinfo FOR EACH ROW Begin select seq_beReg_IdNum.nextval into :new.IdNum from dual; END;
第2步 C#代码:
Console.WriteLine("开始设置:"); string sel_sql = "Select Id,code From Limsbusinessenregisterinfo a Order By added Asc "; DBUtil.DBSession db = new DBUtil.DBSession(DBUtil.DataBaseType.Oracle); DataTable data = db.QueryTable(sel_sql); for (int j = 0; j < data.Rows.Count; j++) { Console.WriteLine("设置:" + data.Rows[j]["code"].ToString()); string id = data.Rows[j]["Id"].ToString(); Hashtable ht = new Hashtable(); ht.Add("IdNum", (j + 1)); ht.Add("Id", id); db.Update(ht, "Limsbusinessenregisterinfo", "id", null); } Console.WriteLine("设置完成。。。"); Console.ReadKey();