给定自定义游标类型:
create or replace
PACKAGE Types AS
TYPE cursor_type IS REF CURSOR;
END Types;
返回此类型的存储过程:
create or replace
procedure TheProcedure
(RS OUT someSchema.TYPES.CURSOR_type, someCode number)
is
begin
open RS for
--A custom query
select
someTable.field,
anotherTable.field,
from someTable,
anotherTable,
where
anotherTable.code = someTable.code
AND someTable.someFK = someCode;
end TheProcedure;
我需要使用ODP.Net(Oracle.DataAccess.Client)
检索所有数据string connectionString = ConfigurationManager.ConnectionStrings["cnx"].ConnectionString;
using (OracleConnection conn = new OracleConnection(connectionString))
{
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "ASCHEMA.TheProcedure";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
OracleParameter prmCursor = cmd.Parameters.Add("RS", OracleDbType.RefCursor);
prmCursor.Direction = ParameterDirection.Output;
cmd.Parameters.Add("someCode", OracleDbType.NVarchar2).Value = 19685;
//the integrity of the sql query was verified
cmd.ExecuteNonQuery();
OracleDataReader anotherReader = ((OracleRefCursor)prmCursor.Value).GetDataReader();
while (anotherReader.Read())
{
var some = !anotherReader.IsDBNull(0) ? anotherReader.GetValue(0) : 0;
}
}
但是读者anotherReader
永远不会返回数据,我认为我需要为用户定义类型TYPE.cursor_type
做一些特殊的事情,但是如何?
提前致谢。
答案 0 :(得分:0)
您真的需要将其设为用户定义类型吗?只需使用SYS_REFCURSOR即可。以下是一些示例代码:
http://www.oracle.com/technetwork/articles/dotnet/williams-refcursors-092375.html