欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

oracle 存儲(chǔ)過(guò)程返回 結(jié)果集 table形式的案例

 更新時(shí)間:2021年01月25日 11:50:43   投稿:jingxian  
這篇文章主要介紹了oracle 存儲(chǔ)過(guò)程返回 結(jié)果集 table形式的案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

--sys_refcursor 和 cursor 優(yōu)缺點(diǎn)比較

優(yōu)點(diǎn)比較

優(yōu)點(diǎn)一:

sys_refcursor,可以在存儲(chǔ)過(guò)程中作為參數(shù)返回一個(gè)table格式的結(jié)構(gòu)集(我把他認(rèn)為是table類型,容易理解,其實(shí)是一個(gè)游標(biāo)集), cursor 只能用在存儲(chǔ)過(guò)程,函數(shù),包等的實(shí)現(xiàn)體中,不能做參數(shù)使用。

優(yōu)點(diǎn)二:

sys_refcursor 這東西可以使用在包中做參數(shù),進(jìn)行數(shù)據(jù)庫(kù)面向?qū)ο箝_放。哈哈。我喜歡。cursor就不能。

create or replace procedure p_test(p_cur out sys_refcursor) 
as 
begin 
   open p_cur for select * from emp; 
end p_test; 
declare
p_cur sys_refcursor;
i emp%rowtype;
begin
 p_test(p_cur);
 loop fetch p_cur 
  into i;
  exit when p_cur%notfound;
  DBMS_OUTPUT.PUT_LINE('---'||i.ename||'---'||i.empno);
  end loop;
  close p_cur;
end;

補(bǔ)充:Oracle存儲(chǔ)過(guò)程返回select * from table結(jié)果

1.首先建立一個(gè)包

create or replace package LogOperation is
 type listLog is ref cursor;
 procedure PCenterExamine_sel(listCenterExamine out listlog,testlist out listLog,numpage in decimal);
end;

2.建立包中的主體

create or replace package body LogOperation is
 procedure PCenterExamine_sel
 (
  listCenterExamine out listlog,
  testlist out listlog,
  numpage in decimal
 ) 
 as
 begin
  open listCenterExamine for select * from Log_CenterExamine;
  open testlist for select * from Log_CenterExamine;
 end;
end;

3.在程序中調(diào)用存儲(chǔ)過(guò)程的值

public static DataSet RunProcedureGetDataSet(string storedProcName, OracleParameter[] parameters)
    {
      string connectionString ="192.168.1.1/db";
      using (OracleConnection connection = new OracleConnection(connectionString))
      {
        DataSet dataSet = new DataSet();
        connection.Open();
        OracleDataAdapter sqlDA = new OracleDataAdapter();
        sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters);
        sqlDA.Fill(dataSet, "dt");
        connection.Close();
        return dataSet;
      }
    }
private static OracleCommand BuildQueryCommand(OracleConnection connection, string storedProcName, IDataParameter[] parameters)
    {
      OracleCommand command = new OracleCommand(storedProcName, connection);
      command.CommandType = CommandType.StoredProcedure;
      foreach (OracleParameter parameter in parameters)
      {
        command.Parameters.Add(parameter);
      }
      return command;
    }

4.有幾個(gè)out的ref cursor,變量ds中就用幾個(gè)DataTable。并且輸入?yún)?shù) indecimal也不會(huì)受影響,并且可以參加存儲(chǔ)過(guò)程的運(yùn)算

OracleParameter[] paramDic = { 
          new OracleParameter("listCenterExamine",OracleType.Cursor),
          new OracleParameter("testlist",OracleType.Cursor),
          new OracleParameter("numpage",OracleType.Int32)};
        paramDic[0].Direction = ParameterDirection.Output;
        paramDic[1].Direction = ParameterDirection.Output;
        paramDic[2].Value = 1;
        ds = Model.OracleHelper.RunProcedureGetDataSet("LogOperation.PCenterExamine_sel", paramDic);

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評(píng)論