I have a stored procedure called MY_STORED_PROC
. It has an integer input parameter and an integer output parameter.
I've tried all manner of DECLARE
s, BEGIN
s and END
s and call
s, and I've started to look into changing statement terminators (??), and I can't for the life of me get it to work in raw SQL (LINQPad in my case).
This answer gives
DECLARE outParam NUMBER;
BEGIN
TP.MY_STORED_PROC(26431414, outParam);
END;
which returns
ERROR [42601] [IBM][DB2/SUN64] SQL0104N An unexpected token "DECLARE OUTPARAM NUMBER@ BEGIN" was found following " ". Expected tokens may include: "
<values>
".
I have also tried setting the terminator/delimeter:
--#SET DELIMITER @
DECLARE outParam NUMBER@
BEGIN
TP.MY_STORED_PROC(26431414, outParam);
END@
--#SET TERMINATOR @
DECLARE outParam NUMBER@
BEGIN
TP.MY_STORED_PROC(26431414, outParam);
END@
both return
ERROR [42601] [IBM][DB2/SUN64] SQL0104N An unexpected token "DECLARE OUTPARAM NUMBER@ BEGIN" was found following " ". Expected tokens may include: "
<values>
".
call
gives the same thing.
Calling it via OdbcCommand
works fine with call
:
var input = 789;
var sql = "call TP.MY_STORED_PROC (?, ?);";
using (var tx = new TransactionScope(TransactionScopeOption.Suppress))
using (var connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
using (var command = new OdbcCommand(sql, connection))
{
command.Parameters.Add("@input_param", OdbcType.Int, 32).Value = input;
command.Parameters.Add("@output_param", OdbcType.Int, 32).Direction = System.Data.ParameterDirection.Output;
connection.Open();
command.ExecuteNonQuery();
object output = command.Parameters["@output_param"].Value;
if (output is DBNull)
return null;
int output = Convert.ToInt32(output);
return output;
}
How can I call this thing and get a meaningful result in the output parameter, which I then stuff in a result set and echo to the screen?