当前位置:网站首页>c#使用oracle存储过程获取结果集实例

c#使用oracle存储过程获取结果集实例

2022-07-06 12:44:00 51CTO


存储过程:

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#代码:

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://blog.51cto.com/u_15708803/5447149