返回值对于UPDATE、INSERT和DELETE语句,返回值是受命令影响的行数。对于CREATE TABLE和DROP TABLE语句,返回值为0。对于所有其他类型的语句,返回值为-1。
这就是microsofts文档对该函数返回值的描述...这是否意味着如果我调用一个存储的proc,它将返回一个-1?
要明确的是,我应该期望从存储过程的成功执行中接收到什么返回值,或者如果存储过程由于某种原因而无法执行...
我确信它会抛出某种类型的错误,但是有没有一个实例不会执行,它会给我一个返回值?
发布于 2011-08-05 21:23:16
无论sp执行什么操作,它都会为存储过程返回-1 (非常容易测试)
create procedure test1 as
begin
null ; --do nothing
end test1 ;
/
create table testtable(a number);
/
create procedure test2 as
begin
insert into testtable(a) select level from dual connect by level < 5;
end test2 ;
/
create procedure test3 as
begin
update testtable set a = a-1;
end test3;
/
create procedure test4 as
begin
delete testtable;
end test4;
/ static int executeProc(string procName,OracleConnection connection ){
OracleCommand cmd= new OracleCommand(procName, connection);
cmd.CommandType = CommandType.StoredProcedure;
return cmd.ExecuteNonQuery();
}
static void Main(string[] args)
{
Console.WriteLine("what does ExecuteNonQuery return?");
// Connect
string connectStr = getConnection();
OracleConnection connection = new OracleConnection(connectStr);
connection.Open();
try{
Console.WriteLine("test1 =>" + executeProc("test1",connection));
Console.WriteLine("test2 =>" + executeProc("test2",connection));
Console.WriteLine("test3 =>" + executeProc("test3",connection));
Console.WriteLine("test4 =>" + executeProc("test4",connection));
}
catch (Exception e){
Console.WriteLine(e.Message);
}
Console.WriteLine("Done");
}what does ExecuteNonQuery return?
test1 =>-1
test2 =>-1
test3 =>-1
test4 =>-1/*
drop table testtable;
drop procedure test1;
drop procedure test2;
drop procedure test3;
drop procedure test4;
*/参考:http://download.oracle.com/docs/cd/E11882_01/win.112/e18754/OracleCommandClass.htm#i998363 http://forums.oracle.com/forums/thread.jspa?threadID=636182
https://stackoverflow.com/questions/6955632
复制相似问题