Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return Oracle Sequence Nextval into C# Variable

Tags:

c#

oracle

I'm trying to return the nextval from an oracle sequence and save the value into a variable, I´m not expert using Oracle with C# until now I have the connection done and I've used some Oracle packages with c#.

I know that I can use the [sequence_name].nextval into the insert query but for bussiness logic I need the same sequence number for many records and the idea is store the nextval into a variable and pass it like parameter to another c# function that will gonna be the responsible to insert the "n" records into the table.

Any hint or code example gonna be helpful, thanks a lot for the help.

like image 951
Mitch3091 Avatar asked Apr 25 '17 14:04

Mitch3091


1 Answers

You can get nextval with an OracleCommand

OracleCommand loCmd = Connection.CreateCommand();
loCmd.CommandType = CommandType.Text;
loCmd.CommandText = "select seqname.nextval from dual";
long lnNextVal = Convert.ToInt64(loCmd.ExecuteScalar());
like image 143
PinBack Avatar answered Sep 22 '22 15:09

PinBack