SqlSugar调用Oracle包体 返回

SqlSugar 沟通中
7 195
该叫什么 发布于2周前
悬赏:0 飞吻

请教一下大佬们怎么调用 Oracle的包体返回的数据 大致代码如下


    var parameters = new List<SugarParameter>();

    parameters.Add(new SugarParameter("@p_detailid", model.Id, System.Data.DbType.Decimal));

    parameters.Add(new SugarParameter("@p_cursor", "") 

    { IsRefCursor=true,Direction=System.Data.ParameterDirection.Output});


    db.Ado.UseStoredProcedure().ExecuteCommand("cux_biddingcarrier_pkg.proc_carrieritem_info", parameters);



包体代码如下

   procedure proc_carrieritem_info(p_detailid      in number,

                               p_cursor         out cux_biddingcarrier_pkg.page_cursor --返回的记录集

                               ) is

  begin

           open p_cursor for

         select item.*

         from

          T_Bidcrl  item       

            where item.MASTER_ID=p_detailid;

  end;


热忱回答7

  • 写一个ADO.NET调用,不要封装。全部原生。我一眼看出所有代码 

    我这边给你转成sqlsugar

    0 回复
  • ✨ VIP0
    2周前

    @fate sta:这个原生的ado.net能获取




      using (OracleConnection connection = new OracleConnection(connectionString))

      {

          using (OracleCommand command = new OracleCommand("cux_biddingcarrier_pkg.proc_carrieritem_info", connection))

          {

              command.CommandType = CommandType.StoredProcedure;


              // 添加输入参数

              OracleParameter pDetailId = new OracleParameter("p_detailid", OracleDbType.Int32);

              pDetailId.Value = detailId;

              pDetailId.Direction = ParameterDirection.Input;

              command.Parameters.Add(pDetailId);


              // 添加输出游标参数

              OracleParameter pCursor = new OracleParameter("p_cursor", OracleDbType.RefCursor);

              pCursor.Direction = ParameterDirection.Output;

              command.Parameters.Add(pCursor);


              connection.Open();


              // 执行存储过程

              command.ExecuteNonQuery();


              // 获取游标数据

              OracleDataReader reader = ((OracleRefCursor)pCursor.Value).GetDataReader();


              // 将结果加载到DataTable

              resultTable.Load(reader);

          }

      }


    0 回复
  • var p = new SugarParameter("@name"""); //有的传null报错,这边可以换了试试 null和""
    p.IsRefCursor = true;// 游标
     
    //如果是output还需要加下面一行
    p.Direction = System.Data.ParameterDirection.Output;
    //执行SQL后p.Value 就会返回值


    就游标参数注意一下 ,其他正常操作

    0 回复
  • 你是报错还是什么问题,看你的代码没什么问题

    0 回复
  •  new OracleParameter("p_detailid", OracleDbType.Int32); 和ORM传的不一样

    0 回复
  • ORM应该也传int

    0 回复
  • ✨ VIP0
    2周前

    @fate sta:现在问题是执行完

       db.Ado.UseStoredProcedure().ExecuteCommand("cux_biddingcarrier_pkg.proc_carrieritem_info", parameters);

     怎么获取返回的值呢?

    0 回复