We are trying out the Devart Oracle adapter but are having problems with existing code that worked with the Oracle's DataAccess DLL. We get the following example error on command.ExecuteNonQuery()
:
ORA-01400: cannot insert NULL into ("DatabaseName"."table_name"."col3")
Here is some example code:
const string query = @"INSERT INTO table_name (table_name_id, col1, col2, col3)
VALUES(table_name_id_seq.nextval, :col1, :col2, :col3)
RETURNING table_name_id INTO :output_id";
OracleParameter outputParam = new OracleParameter(":output_id", OracleDbType.Long, ParameterDirection.Output);
OracleParameter[] parameters = new OracleParameter[]
{
outputParam,
new OracleParameter(":col1", OracleDbType.VarChar, col1, ParameterDirection.Input),
new OracleParameter(":col2", OracleDbType.VarChar, col2, ParameterDirection.Input),
new OracleParameter(":col3", OracleDbType.Long, col3, ParameterDirection.Input)
}
using (OracleCommand command = connection.CreateCommand())
{
command.CommandText = query;
command.CommandType = CommandType.Text;
command.Parameters.AddRange(parameters);
command.ExecuteNonQuery();
int outputId = Convert.ToInt32(outputParam.Value.ToString());
}
What are we doing wrong? We are trying to insert a row using a sequence for the PK, and return the PK for that row all in one query.
Also, the query runs fine if I remove the output parameter and the returning line in the query.