oracle自定义的记录类型,Oracle存储过程和自定义数据类型

你不可能轻易地

deprecated System.Data.OracleClient

但你可以利用

oracle's ODP

使用UDTs。如果这不是一个选项,我不确定如何通过C中的参数来使用System.Data。

ODP确实附带了很多例子,上面的链接中也有一些例子。

我将添加更多链接,希望对您有所帮助:

Download

安装示例文件,这是

另一个很好的例子

你需要做的:一旦安装

安装]…\product\11.2.0\client\u 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类必须实现

(可按照#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

你会想用

param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;

一切都应该到位

你可能感兴趣的:(oracle自定义的记录类型)