sql >> Databasteknik >  >> RDS >> Oracle

Returvärde för Oracle.DataAccess kör icke-fråga (lagrad proc)

den returnerar -1 för lagrade procedurer oavsett vilken åtgärd som sp:n utför (ganska lätt att testa)

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

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




  1. Topp 10 bästa praxis i MySQL

  2. Spring JDBC-mall- Hur man hämtar flera resultat med flera parametrar med en enda fråga

  3. Oracle-leverantör för Oledb saknas i VS 2015 Shell

  4. TSQL DATETIME ISO 8601