我正在尝试在oracle中添加一个新行并获取新插入行的ID,这是我的代码看起来像
cmd.CommandText = "insert into table1 (id,col2) values (id_seq.NEXTVAL,'abc') returning id into :new_id";
OracleParameter objParameter = new OracleParameter("new_id", OracleDbType.Varchar2);
objParameter.Direction = ParameterDirection.Output;
cmd.Parameters.Add(objParameter);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
newID = objParameter.Value;
我做错了什么?
答案 0 :(得分:0)
尝试将插入查询更改为:
insert into table1 (id,col2) values (id_seq.NEXTVAL,'abc') returning id into new_id