ASP.NET調用oracle存儲過程返回多個遊標

利用oracle可以返回多個記錄集。

首先創建程序包,再創建程序包主體。

利用存儲過程返回多個記錄集。

--創建包

create or replace package pack_siit is
 type t_cursor is ref cursor;--定義遊標變量
 type t_scan is ref cursor;
 type t_send is ref cursor;
 type t_receive is ref cursor;
 type t_review is ref cursor;
 type t_locked is ref cursor;
 type t_confirm is ref cursor;
 procedure getFlowTrack
           (var_barcode in varchar2,
          cur_FirstTrial out t_cursor,
          cur_Scan out t_scan,
          cur_Send out t_send,
          cur_Receive out t_receive,
          cur_Review out t_review,
          cur_Locked out t_locked,
          cur_Confirm out t_confirm);
   end pack_siit;

--創建包主體

create or replace package body pack_siit is
  procedure getFlowTrack
    (var_barcode in varchar2,
    cur_FirstTrial out t_cursor,
    cur_Scan out t_scan,
    cur_Send out t_send,
    cur_Receive out t_receive,
    cur_Review out t_review,
    cur_Locked out t_locked,
    cur_Confirm out t_confirm)
    as
     begin
    open cur_FirstTrial for
     select  * from a where id=var_barcode;  
     -- return 1
     open cur_Scan for
     select  * from b where id=var_barcode;
     --2
     open cur_Send for
    select  * from c where id=var_barcode;
    --3
    open cur_Receive for
    select  * from d where id=var_barcode;
     --4
    open cur_Review for
    select  * from e where id=var_barcode;
     --5
    open cur_Confirm for
    select  * from f where id=var_barcode;
      --6
    open cur_Locked for
    select  * from g where id=var_barcode;

    end getFlowTrack;
   end pack_siit;

 

ASP.NET裏調用

OracleConnection connection = new OracleConnection(connectionString);
                --連接
                connection.Open();
                OracleCommand command = new OracleCommand();
                command.Connection = connection;
                command.CommandText = "PACK_SIIT.getFlowTrack";--存儲過程名
                command.CommandType = CommandType.StoredProcedure;--設置執行爲存儲過程
                command.Parameters.Add("var_barcode", OracleType.VarChar, 50);
                command.Parameters.Add("cur_FirstTrial", OracleType.Cursor).Direction = ParameterDirection.Output;
                command.Parameters.Add("cur_Scan", OracleType.Cursor).Direction = ParameterDirection.Output;
                command.Parameters.Add("cur_Send", OracleType.Cursor).Direction = ParameterDirection.Output;
                command.Parameters.Add("cur_Receive", OracleType.Cursor).Direction = ParameterDirection.Output;
                command.Parameters.Add("cur_Review", OracleType.Cursor).Direction = ParameterDirection.Output;
                command.Parameters.Add("cur_Confirm", OracleType.Cursor).Direction = ParameterDirection.Output;
                command.Parameters.Add("cur_Locked", OracleType.Cursor).Direction = ParameterDirection.Output;
                command.Parameters["var_barcode"].Value = stBarcode;// "DH448400001308120004CB1";
                OracleDataAdapter daReader = new OracleDataAdapter(command);
                DataSet ds = new DataSet();
                daReader.Fill(ds);

 

操作返回的DataSet

對DataSet裏的7張表創建新列在賦值

DataSet setDs=null;

 if (ds.Tables[0].Rows.Count > 0)
                {
                    setDs.Tables.Add(ds.Tables[0].Copy());

                    DataColumn taColumn = new DataColumn("IMGTATUS", System.Type.GetType("System.String"));
                    setDs.Tables[0].Columns.Add(taColumn);
                    setDs.Tables[0].Rows[0]["IMGTATUS"] = "新列";
                    if (ds.Tables[1].Rows.Count > 0)
                    {
                        DataColumn taColumn1 = new DataColumn("IMGTATUS", System.Type.GetType("System.String"));
                        taColumn1.DefaultValue = "新列";
                        ds.Tables[1].Columns.Add(taColumn1);
                        setDs.Tables[0].ImportRow(ds.Tables[1].Rows[0]);
                    }
                    if (ds.Tables[2].Rows.Count > 0)
                    {
                        DataColumn taColumn2 = new DataColumn("IMGTATUS", System.Type.GetType("System.String"));
                        //taColumn2.DefaultValue = "新列";
                        ds.Tables[2].Columns.Add(taColumn2);
                        for (int i = 0, length = ds.Tables[2].Rows.Count; i < length; i++)
                        {
                           
                            if (i > 0)
                            {
                                ds.Tables[2].Rows[i]["IMGTATUS"] = "值1";
                            }
                            else
                            {
                                ds.Tables[2].Rows[i]["IMGTATUS"] = "值2";
                            }
                            setDs.Tables[0].ImportRow(ds.Tables[2].Rows[i]);
                        }
                    }

                    ..........等等

        return setDs;

}

得到DataSet後在排序,綁定在GridView上

                    DataView view = ds.Tables[0].DefaultView;
                        view.Sort = "CREATE_TIME ASC";//根據列排序
                        gridView.DataSource = view;
                        gridView.DataBind();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章