在一般的數據存取操作過程中
現在遇到一個問題是
先建立一個班級表和一個學生表
CREATE TABLE CLASS
(
CLASSID NUMBER (
CLASSNAME VARCHAR
)
CREATE TABLE STUDENT
(
STUID NUMBER(
CLASSID NUMBER(
STUNAME NVARCHAR
STUGENDER CHAR(
STUBIRTHDAY DATE
DESCRIPTION NVARCHAR
)
CREATE SEQUENCE CLASSID
CREATE SEQUENCE STUDENTID
首先我們需要在Oracle中創建一個學生的對象類型
CREATE OR REPLACE type StudentType as object
(
StuName nvarchar
StuGender char(
StuBirthday date
StuDescription nvarchar
);
接下來是將這個學生類型創建成表類型
CREATE OR REPLACE type StuList as table of StudentType;
接下來就是寫我們的一個插入存儲過程
CREATE OR REPLACE PROCEDURE ZY
ClassName in varchar
Students in StuList
) IS
BEGIN
insert into Class values(classid
insert into Student(StuID
select studentid
from TABLE(Students);
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
RAISE;
END AddClassStudent;
現在Oracle服務器上的各個對象已經創建完成
在C#項目中添加Oracle
using Oracle
using Oracle
然後再創建Student對應的類
public class Student : IOracleCustomType
{
#region IOracleCustomType Members
public void FromCustomObject(Oracle
{
if (StudentName != null)
OracleUdt
else
throw new NullReferenceException(
OracleUdt
OracleUdt
OracleUdt
}
public void ToCustomObject(Oracle
{
StudentName = (String)OracleUdt
Gender = (String)OracleUdt
Birthday = (DateTime)OracleUdt
Description = (String)OracleUdt
}
#endregion
[OracleObjectMappingAttribute(
public String StudentName { get; set; }
[OracleObjectMapping(
public string Gender { get; set; }
[OracleObjectMapping(
public DateTime Birthday { get; set; }
[OracleObjectMapping(
public string Description { get; set; }
}
並添加Student類對應Oracle對象類型的映射
[OracleCustomTypeMappingAttribute(
public class StudentFactory : IOracleCustomTypeFactory
{
#region IOracleCustomTypeFactory Members
public IOracleCustomType CreateObject()
{
return new Student();
}
#endregion
}
現在StudentType類型已經創建完成
[OracleCustomTypeMappingAttribute(
public class StudentList_TabFactory : IOracleArrayTypeFactory
{
#region IOracleArrayTypeFactory Members
public Array CreateArray(int numElems)
{
return new Student[numElems];
}
public Array CreateStatusArray(int numElems)
{
return null;
}
#endregion
}
這裡可以看到
Student s
Student s
Student s
Student s
List<Student> ss
ss
ss
ss
ss
string conn =
using (OracleConnection oc = new OracleConnection(conn))
{
oc
OracleCommand cmd = oc
cmd
cmd
OracleParameter p
p
p
p
p
cmd
OracleParameter p
p
p
p
p
cmd
int count = cmd
Console
oc
}
以此類推
From:http://tw.wingwit.com/Article/program/Oracle/201311/16524.html