1

I have a CSV file I am parsing out data from which I then need to run against a Oracle database. I have followed along an Oracle tutorial for creating the cursor, but I am not quite sure how change the parameter that I am passing in each time. Do I need to open and close the cursor for each new parameter or could I use an array? I am referring to accountNumber below.

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 specification:

PACKAGE "x"."REJECTS_DATA" IS

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

END "REJECTS_DATA";

Package body:

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";
4

0 回答 0