0

我一直在努力从返回引用光标的 oracle 存储函数中获取结果集。

以下是 Oracle 存储函数的声明:

TYPE GetInspectorCursor IS REF CURSOR;
FUNCTION GetInspectorInformation
   (inUserID IN inspectortable.userid%type,
    inPassword IN inspectortable.password%type,
    inCompanyID IN inspectortable.cid%type,
    inSubCompanyID in inspectortable.scid%type,
    outErrorcode OUT NUMBER)
RETURN GetInspectorCursor;

这是我获取结果集的 c# 程序:

        String connString = "DATA SOURCE=PEOPLE.WORLD;PASSWORD=password;PERSISTSEC CURITY INFO=True;USER ID=userid";


        DataSet ds;
        OracleDataAdapter myAdapter = null;
        Oracle.DataAccess.Types.OracleRefCursor refCursor = null;

        OracleConnection myCon = new OracleConnection(connString);

        String commandText = "schema.package.GetInspectorInformation";

        OracleCommand cmd = new OracleCommand(commandText, myCon);
        cmd.CommandType = CommandType.StoredProcedure;


        // inpectorID
        OracleParameter param = new OracleParameter();
        param.OracleDbType = OracleDbType.Char;
        param.Direction = ParameterDirection.Input;
        param.Value = "JOHN";
        cmd.Parameters.Add(param);

        // inspector Password
        OracleParameter param2 = new OracleParameter();
         param2.OracleDbType = OracleDbType.Char;
         param2.Direction = ParameterDirection.Input;
         param2.Value = "12345";
        cmd.Parameters.Add(param2);

        // VALUE 1
        OracleParameter param3 = new OracleParameter();
         param3.OracleDbType = OracleDbType.Char;
         param3.Direction = ParameterDirection.Input;
         param3.Value = "VA1";
        cmd.Parameters.Add(param3);

        // VALUE 2
        OracleParameter param4 = new OracleParameter();
         param4.OracleDbType = OracleDbType.Char;
         param4.Direction = ParameterDirection.Input;
         param4.Value = "VA2";
        cmd.Parameters.Add(param4);

        // outParam Error Code
        OracleParameter param5 = new OracleParameter();
         param5.OracleDbType = OracleDbType.Decimal;
         param5.Direction = ParameterDirection.Output;
         //param5.IsNullable = true;
        cmd.Parameters.Add(param5);


        OracleParameter param6 = new OracleParameter();
         param.ParameterName = "RefCursor";
         param6.OracleDbType = OracleDbType.Object;
         param6.OracleDbTypeEx = OracleDbType.RefCursor;
         param6.Direction = ParameterDirection.ReturnValue;
         ///param6.IsNullable = false;
         cmd.Parameters.Add(param6);


         myCon.Open();

         cmd.ExecuteNonQuery();


        refCursor = (Oracle.DataAccess.Types.OracleRefCursor)cmd.Parameters["RefCursor"].Value;
        myAdapter = new OracleDataAdapter("", myCon);
        ds = new DataSet("testDS");
        myAdapter.Fill(ds, refCursor);

        // Clean up
        cmd.Dispose();
        myCon.Close();
        myCon.Dispose();

在 myCon.Open() 调用中,我得到:

 ORA-06550: line 1, column 15:
 PLS-00306: wrong number or types of arguments in call to 'GETINSPECTORINFORMATION'
 ORA-06550: line 1, column 7:
 PL/SQL: Statement ignored

有人会善意地节省一些脑细胞,然后告诉我错误传递了什么/哪个参数吗?

谢谢!!!!

4

1 回答 1

0

我不知道如何通过函数返回一个,但你可以通过一个过程返回一个 REF CURSOR。试试这个 - 它在许多项目上都对我有用:

首先,将函数更改为过程:

PROCEDURE GetInspectorInformation
   (inUserID IN inspectortable.userid%type,
    inPassword IN inspectortable.password%type,
    inCompanyID IN inspectortable.cid%type,
    inSubCompanyID in inspectortable.scid%type,
    outErrorcode OUT NUMBER,
    retCursor getInspectorCursor OUT);

然后在你的 C# 代码中,改变这个......

param6.Direction = ParameterDirection.ReturnValue;

……到这……

param6.Direction = ParameterDirection.Output;

然后通过替换myCon.Open()以以下内容开头的所有内容来填充数据集:

ds = new DataSet("testDS");
new OracleDataAdapter(cmd).Fill(ds);

如果您对此有疑问,请注意,每当我这样做时,我的代码与您发布的代码有以下不同:

  • 参考光标一直是唯一 OUT的参数
  • ref 游标是通用的SYS_REFCURSOR
  • adapter.Fill已经到数据集中的一个数据表(new OracleDataAdapter(cmd).Fill(ds.myTableName)

因此,您可能仍需要进行一些实验,但正如我所说,这对我之前有用。

于 2013-03-15T19:17:17.717 回答