ODP传递整数数组

本文关键字:数组 整数 ODP | 更新日期: 2023-09-27 17:58:33

这个问题让我抓狂。我试图将一个整数数组传递给ORACLE函数,但没有成功。

我有一个scada_stops_header表,其中有列:

 1. ST_EVENTGROUPID NUMBER(15,0) 
 2. ST_CATEG        NUMBER(6,0)
 3. ST_SUBCATEG     NUMBER(6,0)

这是包裹代码:

create or replace package scada as
....
  type stopid_record is record(stop_id scada_stops_header.st_eventgroupid%type);
  type stopid_table is table of stopid_record INDEX BY BINARY_INTEGER;
....
  function stops_set(fids_table in stopid_table,
                 fcateg     in scada_stops_header.st_categ%type,
                 fsubcateg  in scada_stops_header.st_subcateg%type,
                 ferrmsg    out nvarchar2) return number;

这是C#代码:

using (OracleCommand cmd = new OracleCommand("scada.stops_set", con))
{
    cmd.CommandType = CommandType.StoredProcedure;
    var pResult = new OracleParameter("return", OracleDbType.Int32);
    pResult.Direction = ParameterDirection.ReturnValue;
    var pIDs = new OracleParameter("fids_table", OracleDbType.Decimal);
    pIDs.Direction = ParameterDirection.Input;
    pIDs.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    pIDs.Value = stops.Stops;
    var pCategory = new OracleParameter("fcateg", OracleDbType.Int32);
    pCategory.Direction = ParameterDirection.Input;
    pCategory.Value = stops.TypeID;
    var pSubcategory = new OracleParameter("fsubcateg", OracleDbType.Int32);
    pSubcategory.Direction = ParameterDirection.Input;
    pSubcategory.Value = stops.SubtypeID;
    var pError = new OracleParameter("ferrmsg", OracleDbType.NVarchar2, 500);
    pError.Direction = ParameterDirection.Output;
    cmd.Parameters.Add(pIDs);
    cmd.Parameters.Add(pCategory);
    cmd.Parameters.Add(pSubcategory);
    cmd.Parameters.Add(pError);
    cmd.Parameters.Add(pResult);
    con.Open();
    cmd.ExecuteNonQuery();
}

我得到了例外:

Oracle.ManagedDataAccess.Client.Oracle异常(0x00001996):ORA-06550:第1行第15列:PLS-00306:错误的编号或类型对"STOPS_SET"ORA-06550:第1行第7列的调用中的参数:PL/SQL:语句忽略

我试过通过Int32Int64Decimal。。。

ODP传递整数数组

看起来我不能将复杂类型用作表参数。我已将类型定义更改为:

type stopid_table is table of 
   scada_stops_header.st_eventgroupid%type INDEX BY BINARY_INTEGER;

现在它起作用了。