如何将变量传递给Oracle引用游标

时间:2013-01-17 01:38:48

标签: c# oracle odp.net

我有一个CSV文件我正在解析数据,然后我需要针对Oracle数据库运行。我已经跟着一个用于创建游标的Oracle教程,但我不太确定如何更改我每次传递的参数。我是否需要为每个新参数打开和关闭光标,还是可以使用数组?我指的是下面的accountNumber。

string oradb = "connection string here";

OracleConnection conn = new OracleConnection(oradb);

OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "X.REJECTS_DATA.GETCURSORS";
cmd.CommandType = CommandType.StoredProcedure;

OracleParameter ACTNUM = new OracleParameter();
ACTNUM.OracleDbType = OracleDbType.Decimal;
ACTNUM.Direction = ParameterDirection.Input;
ACTNUM.Value = accountNumber;
cmd.Parameters.Add(ACTNUM);

OracleParameter REJECTS_C = new OracleParameter();
REJECTS_C.OracleDbType = OracleDbType.RefCursor;
REJECTS_C.Direction = ParameterDirection.Output;
cmd.Parameters.Add(REJECTS_C);


try
{
    conn.Open();
    OracleDataReader objReader = cmd.ExecuteReader();
    Label3.Text = objReader.ToString();
}
catch (Exception ex)
{
    Label3.Text = string.Format("Exception: {0}", ex.ToString());

}

包装规格:

PACKAGE "x"."REJECTS_DATA" IS

PROCEDURE "GETCURSORS" (
"ACTNUM" IN NUMBER, 
"REJECTS_C" OUT SYS_REFCURSOR);

END "REJECTS_DATA";

包体:

PACKAGE BODY "X"."REJECTS_DATA" IS

PROCEDURE "GETCURSORS" (
"ACTNUM" IN NUMBER, 
"REJECTS_C" OUT SYS_REFCURSOR) IS

BEGIN

OPEN REJECTS_C FOR SELECT * FROM X.A    WHERE  X.A.ACCOUNT = ACTNUM;

END "GETCURSORS";

END "REJECTS_DATA";

0 个答案:

没有答案