I am trying to execute a stored procedure from my .net application, but I get an error
ORA-00900: invalid SQL statement"
Any recommdendations?
await Context.Database.SqlQuery<Equipment>(_execPackage, new OracleParameter("ID", obID),
new OracleParameter("Time", time),
new OracleParameter("rNo", No).ToListAsync();
private readonly string _execPackage = $@" EXEC procedurename(:ID,:Time,:rNo)";
This is worked
await Context.Database.SqlQuery<object>($@" CALL procedurename(:p1,:p2,:p3)",
new OracleParameter("p1", obID),
new OracleParameter("p2", time),
new OracleParameter("p3", Nmbr).ToListAsync();
This might seem verbose, but this is how I prefer setting up calls to stored procedures:
using (var context = new DbContext()) // you don't have to strictly use this to reference the context, it's just what i gravitate towards
{
var in_Id = new OracleParameter("in_ID", OracleDbType.TYPE, obID, ParameterDirection.Input);
var in_time = new OracleParameter("in_time", OracleDbType.TYPE, time, ParameterDirection.Input);
var in_rNo = new OracleParameter("in_rNo", OracleDbType.TYPE, No, ParameterDirection.Input);
await context.Database.SqlQuery<object>("BEGIN procedurename(:in_Id, :in_time, :in_rNo); END;", in_Id, in_time, in_rNo).ToListAsync();
}
One thing to note, if the ID parameter is a PK with a sequence that autogenerates its value, you'll want to reference the sequence instead of passing in a parameter:
context.Database.SqlQuery<object>("BEGIN procedurename(SEQUENCE_NAME.nextval, :in_time, :in_rNo); END;", in_Id, in_time, in_rNo);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.