国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

在Oracle中返回多個結果集

2024-08-29 13:36:02
字體:
來源:轉載
供稿:網友

  Oracle 不支持批量查詢,因此無法從一個命令返回多個結果集。使用存儲過程時,返回多個結果集類似于返回單個結果集;必須使用 REF CURSOR 輸出參數。要返回多個結果集,請使用多個 REF CURSOR 輸出參數。
  
  以下是返回兩個結果集(全部 EMPLOYEES 和 JOBS 記錄)的包規范:
  
  CREATE OR new PACKAGE SELECT_EMPLOYEES_JOBS AS
  TYPE T_CURSOR IS REF CURSOR;
  PROCEDURE GetEmployeesAndJobs (
  cur_Employees OUT T_CURSOR,
  cur_Jobs OUT T_CURSOR
  );
  END SELECT_EMPLOYEES_JOBS;
  
  包正文如下所示:
  
  CREATE OR new PACKAGE BODY SELECT_EMPLOYEES_JOBS AS
  PROCEDURE GetEmployeesAndJobs
  (
  cur_Employees OUT T_CURSOR,
  cur_Jobs OUT T_CURSOR
  )
  IS
  BEGIN
  -- return all EMPLOYEES records
  OPEN cur_Employees FOR
  SELECT * FROM Employees;
  
  -- return all JOBS records
  OPEN cur_Jobs FOR
  SELECT * FROM Jobs;
  END GetEmployeesAndJobs;
  END SELECT_EMPLOYEES_JOBS;
  
  以下代碼顯示了如何使用從上述包中返回的兩個結果集來填充 DataSet 中的兩個相關表:
  
  // create the connection
  OracleConnection conn = new OracleConnection("Data Source=oracledb;
  User Id=UserID;PassWord=Password;");
  
  // define the command for the stored procedure
  OracleCommand cmd = new OracleCommand();
  cmd.Connection = conn;
  cmd.CommandText = "SELECT_EMPLOYEES_JOBS.GetEmployeesAndJobs";
  
  // add the parameters including the two REF CURSOR types to retrieve
  // the two result sets
  cmd.Parameters.Add("cur_Employees", OracleType.Cursor).Direction =
  ParameterDirection.Output;
  cmd.Parameters.Add("cur_Jobs", OracleType.Cursor).Direction =
  ParameterDirection.Output;
  cmd.CommandType = CommandType.StoredProcedure;
  
  // create the DataAdapter and map tables
  OracleDataAdapter da = new OracleDataAdapter(cmd);
  da.TableMappings.Add("Table", "EMPLOYEES");
  da.TableMappings.Add("Table1", "JOBS");
  
  // create and fill the DataSet
  DataSet ds = new DataSet();
  da.Fill(ds);
  
  // create a relation
  ds.Relations.Add("EMPLOYEES_JOBS_RELATION",
  ds.Tables["JOBS"].Columns["JOB_ID"],
  ds.Tables["EMPLOYEES"].Columns["JOB_ID"]);
  
  // output the second employee (zero-based array) and job title
  // based on the relation
  Console.WriteLine("Employee ID: " +
  ds.Tables["EMPLOYEES"].Rows[1]["EMPLOYEE_ID"] +
  "; Job Title: " +
  ds.Tables["EMPLOYEES"].Rows[1].GetParentRow(
  "EMPLOYEES_JOBS_RELATION")["JOB_TITLE"]);
  
  控制臺輸出顯示了第二個員工的職務:
  
  Employee ID: 101; Job Title: Administration Vice President
  
  來自于:http://www.microsoft.com/china/MSDN/library/data/dataaccess/DMSDNorsps.mspx
  
  碰到的錯誤:在開發時碰到了未處理的句柄錯誤,其原因是沒有為所有的輸出參數返回值。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 攀枝花市| 建瓯市| 清水河县| 石门县| 丰县| 修武县| 华宁县| 綦江县| 龙陵县| 蚌埠市| 嘉黎县| 磴口县| 达拉特旗| 来宾市| 平果县| 昌图县| 兖州市| 定安县| 墨竹工卡县| 武乡县| 榆林市| 耒阳市| 什邡市| 中山市| 蓝山县| 托里县| 松滋市| 麦盖提县| 永胜县| 义乌市| 南岸区| 正安县| 丰原市| 阳泉市| 婺源县| 阿荣旗| 沐川县| 安康市| 景谷| 永康市| 武陟县|