views:

61

answers:

1

I use DB2 9.7 for Linux. The stored procedure is implemented in PL/SQL (Oracle's programming language), so, the record set is an output parameter (SYS_REFCURSOR).

CREATE OR REPLACE PROCEDURE TEST_CURSOR (
  CV_1 OUT SYS_REFCURSOR
) IS
BEGIN
    OPEN CV_1 FOR
    SELECT 1 COLUMN
      FROM DUAL;
END TEST_CURSOR;

I don't know how to declare this parameter in my C# code.

DB2Parameter parameter = ((DB2Command)command).CreateParameter();

parameter.ParameterName = "cv_1";
parameter.Direction = ParameterDirection.Output;
parameter.DbType = ...
+1  A: 

There is no DB2Type enumeration for result sets. In their API the way you do this is to execute the command with the DB2Command.ExecuteReader method. You may have to change the PL/SQL to a function which returns a sys_refcursor rather than a procedure which has a sys_refcursor parameter.

Adam Hawkes
I've tried this, but I don't how to call a function from C#. I've got this error:DB2: ERROR [42884] [IBM][DB2/LINUXX8664] SQL0440N No authorized routine named "FUN_TEST" of type "PROCEDURE" having compatible arguments was found. SQLSTATE=42884
Jorge
A function returns a value and is declared with the keyword 'FUNCTION' instead of 'PROCEDURE'. Check the PL/SQL docs you have handy for more info.
Adam Hawkes