4

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.

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?

SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195
  • 1
    your question is "a stored proc would return -1"? why you don't test that? you tested CREATE TABLE and DROP TABLE statements, inserts, updates... – Florin Ghita Aug 05 '11 at 12:02
  • Well, it says for all other statements, the return value is -1? I was assuming that included stored procs... I haven't been able to confirm yet. I was hoping someone on here had some experience calling a stored proc using ODP.Net. – SoftwareSavant Aug 05 '11 at 12:54

1 Answers1

7

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;
*/

reference: http://download.oracle.com/docs/cd/E11882_01/win.112/e18754/OracleCommandClass.htm#i998363 http://forums.oracle.com/forums/thread.jspa?threadID=636182

Harrison
  • 8,970
  • 1
  • 32
  • 28