gpt4 book ai didi

oracle - Oracle.DataAccess 执行非查询的返回值(存储过程)

转载 作者:行者123 更新时间:2023-12-02 09:51:15 26 4
gpt4 key购买 nike

返回值对于 UPDATE、INSERT 和 DELETE 语句,返回值是受命令影响的行数。对于 CREATE TABLE 和 DROP TABLE 语句,返回值为 0。对于所有其他类型的语句,返回值为 -1。

这就是微软文档中关于该函数返回值的说明...这是否意味着如果我调用存储过程,它将返回 -1?

要明确的是,我应该期望从存储过程的成功执行中收到什么返回值,或者如果存储过程由于某种原因未能执行......

我确信它会抛出某种错误,但是是否有一个实例它不会执行并且会给我一个返回值?

最佳答案

无论 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

关于oracle - Oracle.DataAccess 执行非查询的返回值(存储过程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6955632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com