您将无法轻松地使用已弃用 System.Data.OracleClient但你可以利用甲骨文的ODP使用 UDT。如果这不是一个选项,我不确定如何通过 C# 中的参数和 System.Data 来完成此操作。
ODP 确实附带了很多示例,上面的链接中有示例。
我将添加更多链接,希望能有所帮助:
- 视觉工作室 ODP 指数
-
这准确地向您展示了如何
利用 ODT 创建您的自定义
类包装并调用它们(做
请注意,这是中途,
他们使用该工具逐步完成
在其上方创建自定义类型
示例——本演练是
非常彻底,应该可以让你
直接到达您需要去的地方)
-
Download: 现在这家伙也
安装示例文件,这是
另一个很好的例子
你需要做什么:安装后
goto [您的目录路径
安装]..\product\11.2.0\client_1\odp.net\samples\4\UDT\object1.cs
让 Visual Studio 的 ODT 工具为您的 UDT 创建类(例如 IOracleCustomType 等)确实值得。然后您可以深入研究并修改它们以满足您的需要。然后,一旦一切都说完了(来自 object1.cs 的片段):
Person p1 = new Person();
p1.Name = "John";
p1.Address = "Address1";
p1.Age = 20;
// Establish a connection to Oracle
OracleConnection con = new OracleConnection(constr);
con.Open();
// Update Person object and insert it into a database table
OracleCommand cmd = new OracleCommand(sql1, con);
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter param1 = new OracleParameter();
param1.OracleDbType = OracleDbType.Object;
param1.Direction = ParameterDirection.InputOutput;
// Note: The UdtTypeName is case-senstive
param1.UdtTypeName = "SCOTT.ODP_OBJ1_SAMPLE_PERSON_TYPE";
param1.Value = p1;
cmd.Parameters.Add(param1);
另请注意,Person 类必须实现IOracle自定义类型(可以通过#2 中的链接创建)
/* Person Class
An instance of a Person class represents an ODP_OBJ1_SAMPLE_PERSON_TYPE object
A custom type must implement INullable and IOracleCustomType interfaces
*/
public class Person : INullable, IOracleCustomType
上面是完整的自定义类型,但您需要的是关联数组 ODP 绑定:
http://weblogs.asp.net/ricardoperes/archive/2009/05/14/odp-net-associative-arrays.aspx
你会想要使用
param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
一切都应该就位