存储过程可以执行,转成sql语句就不行,求解!
存储过程如下:
create or replace procedure test_milo_add(in_testname in test_milo.testname%type, out_testid out test_milo.testid%type) is
begin
insert into test_milo (testid,testname) values (test_milo_testid.nextval,in_testname);
select crm.test_milo_testid.currval into out_testid from dual;
end test_milo_add;
用.net代码执行该过程,完全正常。
OracleCommand oc = c.CreateCommand();
oc.CommandText = "test_milo_add";
oc.Parameters.Add("in_testname", OracleDbType.Varchar2, entity.TESTNAME, ParameterDirection.Input);
oc.Parameters.Add("out_testid", OracleDbType.Int32,ParameterDirection.Output);
oc.CommandType = CommandType.StoredProcedure;
var rowaffected=oc.ExecuteNonQuery();
但是我想将存储过程中的代码搬到sql语句里直接执行,像这样:
OracleCommand oc = c.CreateCommand();
oc.CommandText = "insert into test_milo (testid,testname) values (test_milo_testid.nextval,:in_testname);select crm.test_milo_testid.currval into :out_testid from dual;";
oc.Parameters.Add("in_testname", OracleDbType.Varchar2, entity.TESTNAME, ParameterDirection.Input);
oc.Parameters.Add("out_testid", OracleDbType.Int32,ParameterDirection.Output);
var rowaffected=oc.ExecuteNonQuery();
就不行了,报错:Oracle.DataAccess.Client.OracleException: ORA-00911: invalid character
求解,应该怎么写才对?前提是我不想使用存储过程,希望直接运行sql语句。