我一直在试着从一个返回引用游标的oracle存储函数中获取结果集。
以下是Oracle存储功能的声明:
TYPE GetInspectorCursor IS REF CURSOR;
FUNCTION GetInspectorInformation
(inUserID IN inspectortable.userid%type,
inPassword IN inspectortable.password%type,
inCompanyID IN inspectortable.cid%type,
inSubCompanyID in inspectortable.scid%type,
outErrorcode OUT NUMBER)
RETURN GetInspectorCursor;
这是我的c#程序来获取结果集:
String connString = "DATA SOURCE=PEOPLE.WORLD;PASSWORD=password;PERSISTSEC CURITY INFO=True;USER ID=userid";
DataSet ds;
OracleDataAdapter myAdapter = null;
Oracle.DataAccess.Types.OracleRefCursor refCursor = null;
OracleConnection myCon = new OracleConnection(connString);
String commandText = "schema.package.GetInspectorInformation";
OracleCommand cmd = new OracleCommand(commandText, myCon);
cmd.CommandType = CommandType.StoredProcedure;
// inpectorID
OracleParameter param = new OracleParameter();
param.OracleDbType = OracleDbType.Char;
param.Direction = ParameterDirection.Input;
param.Value = "JOHN";
cmd.Parameters.Add(param);
// inspector Password
OracleParameter param2 = new OracleParameter();
param2.OracleDbType = OracleDbType.Char;
param2.Direction = ParameterDirection.Input;
param2.Value = "12345";
cmd.Parameters.Add(param2);
// VALUE 1
OracleParameter param3 = new OracleParameter();
param3.OracleDbType = OracleDbType.Char;
param3.Direction = ParameterDirection.Input;
param3.Value = "VA1";
cmd.Parameters.Add(param3);
// VALUE 2
OracleParameter param4 = new OracleParameter();
param4.OracleDbType = OracleDbType.Char;
param4.Direction = ParameterDirection.Input;
param4.Value = "VA2";
cmd.Parameters.Add(param4);
// outParam Error Code
OracleParameter param5 = new OracleParameter();
param5.OracleDbType = OracleDbType.Decimal;
param5.Direction = ParameterDirection.Output;
//param5.IsNullable = true;
cmd.Parameters.Add(param5);
OracleParameter param6 = new OracleParameter();
param.ParameterName = "RefCursor";
param6.OracleDbType = OracleDbType.Object;
param6.OracleDbTypeEx = OracleDbType.RefCursor;
param6.Direction = ParameterDirection.ReturnValue;
///param6.IsNullable = false;
cmd.Parameters.Add(param6);
myCon.Open();
cmd.ExecuteNonQuery();
refCursor = (Oracle.DataAccess.Types.OracleRefCursor)cmd.Parameters["RefCursor"].Value;
myAdapter = new OracleDataAdapter("", myCon);
ds = new DataSet("testDS");
myAdapter.Fill(ds, refCursor);
// Clean up
cmd.Dispose();
myCon.Close();
myCon.Dispose();
在myCon.Open()上调用我得到:
ORA-06550: line 1, column 15:
PLS-00306: wrong number or types of arguments in call to 'GETINSPECTORINFORMATION'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
有人会非常友好地备用一些脑细胞,而且我会告诉错误传递的是什么/哪个参数?
感谢!!!!
答案 0 :(得分:0)
我不知道如何通过函数返回一个,但是你可以通过一个程序返回一个REF CURSOR。试试这个 - 它在很多项目之前对我有用:
首先,将功能更改为过程:
PROCEDURE GetInspectorInformation
(inUserID IN inspectortable.userid%type,
inPassword IN inspectortable.password%type,
inCompanyID IN inspectortable.cid%type,
inSubCompanyID in inspectortable.scid%type,
outErrorcode OUT NUMBER,
retCursor getInspectorCursor OUT);
然后在您的C#代码中,更改此...
param6.Direction = ParameterDirection.ReturnValue;
......对此...
param6.Direction = ParameterDirection.Output;
然后使用以下内容替换以myCon.Open()
开头的所有内容来填充数据集:
ds = new DataSet("testDS");
new OracleDataAdapter(cmd).Fill(ds);
如果您遇到此问题,请注意,每当我执行此操作时,我的代码与您发布的内容存在以下差异:
OUT
参数SYS_REFCURSOR
adapter.Fill
已到达数据集(new OracleDataAdapter(cmd).Fill(ds.myTableName)
所以你可能仍需要进行一些实验,但正如我所说,这对我有用。