Passing array to Oracle procedure from c#

前端 未结 1 1879
迷失自我
迷失自我 2020-12-09 23:19

I\'m trying to pass an array to oracle procedure. I searched about it and firstly i created a type named \'dizi\' (like here enter link description here). So it works in ora

相关标签:
1条回答
  • 2020-12-09 23:28
    1. Define an array type and a procedure:

      CREATE or replace PACKAGE Testpackage AS 
        TYPE Areas_t is table of VARCHAR(100) index by BINARY_INTEGER;
        PROCEDURE TESTPROCEDURE(Areas IN Areas_t);       
      END Testpackage; 
      
    2. C# routine:

      public void InsertQuestion(IEnumerable<string> area_list)
      {
          var connect = new OracleConnection("YOUR CONNECTION STRING");
      
          var command = new OracleCommand("BEGIN Testpackage.Testprocedure(:Areas); END;", connect);
      
          connect.Open();
      
          var arry = command.Parameters.Add("Areas", OracleDbType.Varchar2);
      
          arry.Direction = ParameterDirection.Input;
          arry.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
          arry.Value = area_list.ToArray();
          arry.Size = area_list.Count();
          arry.ArrayBindSize = area_list.Select(_ => _.Length).ToArray();
          arry.ArrayBindStatus = Enumerable.Repeat(OracleParameterStatus.Success, area_list.Count()).ToArray();
      
          command.ExecuteNonQuery();
      
          connect.Close();
      }
      
    0 讨论(0)
提交回复
热议问题