从Oracle Output参数中获取新插入的行ID

时间:2014-05-13 02:37:19

标签: sql oracle rowid

我正在尝试在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;

我做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试将插入查询更改为:

insert into table1 (id,col2) values (id_seq.NEXTVAL,'abc') returning id into new_id