Oracle.DataAccess的返回值执行非查询(存储的proc) [英] Return Value of Oracle.DataAccess execute non-query (stored proc)

查看:106
本文介绍了Oracle.DataAccess的返回值执行非查询(存储的proc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Return Value For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For CREATE TABLE and DROP TABLE statements, the return value is 0. For all other types of statements, the return value is -1.

这是microsofts docs关于该函数的返回值的声明...这是否意味着如果我调用存储的proc,它将返回-1?

That is what microsofts docs states about the return value of that function... Does that mean that if I call a stored proc, it would return a -1?

需要明确的是,我期望成功执行存储过程或者如果存储过程由于某种原因执行失败而应该获得什么返回值...

To be clear, what return value should I expect to receive from a successful execution of a stored procedure or if the stored Procedure failed to execute for some reason...

我确定它会引发某种错误,但是是否有一个实例无法执行,并且会给我返回值?

I am sure that it would throw me an error of some kind, but is there an instance where it wouldn't execute and it would give me a return value?

推荐答案

无论sp执行什么操作(非常容易测试),它都会为存储过程返回-1.

it returns -1 for stored procedures regardless of the action that the sp performs (pretty easy to test)

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.DataAccess的返回值执行非查询(存储的proc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆