代码之家  ›  专栏  ›  技术社区  ›  Omar

过程参数中的Oracle UDT绑定无效

  •  5
  • Omar  · 技术社区  · 13 年前

    我正试图调用一个采用自定义数据类型 table of numbers 作为参数之一。

    以下是类型的定义:

    create type num_list as table of number;
    

    以及程序的定义:

    create or replace procedure my_procedure
        (listofnumbers num_list,
                      v_value char)
    is
    begin
    
      update my_table
         set my_column = v_value
       where my_row_id in (select column_value
                             from table(listofnumbers));
    
    end;
    

    使用odp.net和c,我声明如下:

    var row_ids = new int[] { 1, 2 };
    
    using (var oracleConn = new Oracle.DataAccess.Client.OracleConnection(myConnectionString))
    {
        oracleConn.Open();
        var cmd = new Oracle.DataAccess.Client.OracleCommand("my_procedure", oracleConn);
        cmd.CommandType = CommandType.StoredProcedure;
    
        var param1 = new Oracle.DataAccess.Client.OracleParameter("listofnumbers", Oracle.DataAccess.Client.OracleDbType.Array, ParameterDirection.Input);
        param1.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
        param1.UdtTypeName = "num_list";
        param1.Value = row_ids;
        cmd.Parameters.Add(param1);
    
        var param2 = new Oracle.DataAccess.Client.OracleParameter("v_value ", Oracle.DataAccess.Client.OracleDbType.Char, ParameterDirection.Input);
        param2.Value = "Y";
        cmd.Parameters.Add(param2);
    
        cmd.ExecuteNonQuery();
    }
    

    引发的异常说明:

    无效的参数绑定参数 姓名:号码列表

    定义参数时缺少哪些属性?

    1 回复  |  直到 10 年前
        1
  •  2
  •   Stephen Drew    10 年前

    http://developergeeks.com/article/35/working-with-user-defined-type-oracle-udt-and-custom-type-using-odp-net-11g


    param1.Size = row_ids.Length;
    

    TYPE t_stringlist IS TABLE OF VARCHAR2(4000);
    
    
                string[] values = new string[] { "AAA", "BBB" };
    
                OracleParameter parameter = new OracleParameter();
                parameter.Name = "my_param";
                parameter.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
                parameter.OracleDbType = OracleDbType.Varchar2;
                parameter.ArrayBindSize = new int[values.Length];
                parameter.ArrayBindStatus = new OracleParameterStatus[values.Length];
                parameter.Size = values.Length;
    
                for (int i = 0; i < values.Length; ++i)
                {
                    parameter.ArrayBindSize[i] = 4000;
                    parameter.ArrayBindStatus[i] = OracleParameterStatus.Success;
                }
    
                parameter.Value = values;
    

    http://download.oracle.com/docs/html/E15167_01/featUDTs.htm