The previous period was a select last_number-1 from user_sequences where sequence_name= ' sequence name '. This method is a hidden problem. Error values may occur when there is a large number of concurrent access inserts. A new method was found today. Use the Select Sequence name after the insert. Currval from dual can also get the value. And this currval is only retained in the Operation dialog after the insert, which means that each user will see a different currval after the insert. Not affected by other users, And when you make another insert in the current operation, the Currval also refreshes. There is no reason to take the wrong number. You can use it safely.
Attach an example to it:
Background a stored procedure
Create or Replace procedure Newarchfileid (insert_sql varchar, seq_name out number) is
Str_sql varchar (100);
Begin
Execute immediate insert_sql;
Str_sql: = ' SELECT ' | | seq_name| | '. Currval from dual ';
Execute immediate str_sql into newid;
End Newarchfileid;
To invoke the C # code of a stored procedure:
String ConnectionString = "Connection string";
OracleConnection conn = new OracleConnection (ConnectionString);//Create a connection
OracleCommand cmd = new OracleCommand ("Newarchfileid", conn);
Cmd.commandtype = CommandType.StoredProcedure;
Cmd. Parameters.Add ("Insert_sql", Oracletype.varchar);
Cmd. Parameters.Add ("Seq_name", Oracletype.varchar);
Cmd. Parameters.Add ("newid", oracletype.number);
Cmd. Parameters[0]. Value = "specific INSERT statement";
Cmd. PARAMETERS[1]. Value = "sequence name";
Cmd. PARAMETERS[2]. Direction = ParameterDirection.Output;
Cmd. ExecuteNonQuery ();
Output a new ID
Fileid = cmd. parameters["newid"]. Value.tostring ();
Response.Write (Fileid);