我正在尝试从.net应用程序执行存储过程,但出现错误
ORA-00900:无效的SQL语句”
有什么建议吗?
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)";
答案 0 :(得分:0)
这可行
await Context.Database.SqlQuery<object>($@" CALL procedurename(:p1,:p2,:p3)",
new OracleParameter("p1", obID),
new OracleParameter("p2", time),
new OracleParameter("p3", Nmbr).ToListAsync();
答案 1 :(得分:0)
这似乎很冗长,但这是我更喜欢设置对存储过程的调用的方式:
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();
}
要注意的一件事是,如果ID参数是具有自动生成其值的序列的PK,则您需要引用该序列而不是传递参数:
context.Database.SqlQuery<object>("BEGIN procedurename(SEQUENCE_NAME.nextval, :in_time, :in_rNo); END;", in_Id, in_time, in_rNo);