当前位置:网站首页>C # use Oracle stored procedure to obtain result set instance

C # use Oracle stored procedure to obtain result set instance

2022-07-06 20:57:00 51CTO


stored procedure :

create or replace PACKAGE FIRSTPAGE AS

  /* TODO enter package declarations (types, exceptions, methods etc) here */
   type v_cursor is REF CURSOR;
   procedure getnumber(re_cursor out v_cursor);
END FIRSTPAGE;

create or replace PACKAGE BODY FIRSTPAGE AS

  procedure getnumber(re_cursor out v_cursor) AS
  BEGIN
    /* TODO implementation required */
   open re_cursor for
     select * from testable;
  END getnumber;

END FIRSTPAGE;

C# Code :

public DataSet GetTableByProcedure()
        {
            OracleConnection con = new OracleConnection(_connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "firstpage.getnumber";

            OracleParameter sp = new OracleParameter("re_cursor", OracleType.Cursor);
            sp.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(sp);

            OracleDataAdapter da = new OracleDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);

            cmd.Dispose();
            con.Close();
            con.Dispose();

            return ds;

        }

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061233057842.html