将数组从 C# 传递给 Oracle 过程 [英] Passing array to Oracle procedure from c#
本文介绍了将数组从 C# 传递给 Oracle 过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数组传递给 oracle 过程.我搜索了它,首先我创建了一个名为dizi"的类型(就像这里 在此处输入链接描述).所以它适用于oracle开发者.问题是;我无法将我的 c# 数组作为参数传递给程序.那么如何将我的数组传递给我的程序?
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 oracle developer. The problem is; i can't pass my c# array to procedure as a parameter. So how can i pass my array to my procedure?
这是我的代码(当我执行时,oracle 错误说:并非所有变量都绑定)
Here is my code (When i execute, oracle error says: Not all variables bound)
public void InsertQuestion(List<string> area_list)
{
quest_areas = area_list.ToArray();
command.Connection = connect;
connect.Open();
var arry = command.Parameters.Add("Areas", OracleDbType.Varchar2);
arry.Direction = ParameterDirection.Input;
arry.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
arry.Value = quest_areas;
command.CommandText ="TESTPROCEDURE(:Areas)";
command.CommandType = CommandType.StoredProcedure;
command.ExecuteNonQuery();
connect.Close();
}
推荐答案
定义一个数组类型和一个过程:
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;
C# 例程:
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();
}
这篇关于将数组从 C# 传递给 Oracle 过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文