From Stored Procedure, return OUT parameter & OUT cursor & parse result (Oracle)

前端 未结 5 2108
走了就别回头了
走了就别回头了 2021-01-01 02:36

Question : Is it possible to return using OUT :

Both : A variable & A cursor, from my code below ??


I saw a similar question for SqlDB but after

5条回答
  •  青春惊慌失措
    2021-01-01 02:47

    Thank you for the answers

    I was really desperate to get a working result & somehow came across a solution & after reading a bit found out why it worked :


    Oracle Stored Procedure as is with no change.


    Code Behind - Changed as follows :

    Database db = DBSingleton.GetInstance();
    using (DbCommand command = db.GetStoredProcCommand(spName))
    {
        //The three Add In Parameters... & then the Add out Parameter as below
        db.AddOutParameter(command, "myFlag", System.Data.DbType.Int32, LocVariable );
        using ( IDataReader reader = db.ExecuteReader(command))
        {
             //Loop through cursor values & store them in code behind class-obj(s)
             //The reader must be closed before trying to get the "OUT parameter"
             reader.Close();
    
             //Only after reader is closed will any parameter result be assigned
             //So now we can get the parameter value.
             //if reader was not closed then OUT parameter value will remain null
             //Getting the parameter must be done within this code block
             //I could not get it to work outside this code block
              result = (typecast)command.Parameters["OUT_parameter_name"];
        }
    }
    //I USED THIS APPROACH TO RETURN MULTIPLE PARAMETERS ALONG WITH THE CURSOR READ
    

提交回复
热议问题