扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:小溪明净 来源:天极开发 2007年10月22日
关键字: Oracle 10g 功能 Ref Cursor ORACLE
create table processing_result ( status varchar2(64) ); create or replace package cursor_in_out as type emp_cur_type is ref cursor return employees%rowtype; procedure process_cursor(p_cursor in emp_cur_type); end; / create or replace package body cursor_in_out as procedure process_cursor(p_cursor in emp_cur_type) is employee employees%rowtype; begin loop fetch p_cursor into employee; exit when p_cursor%notfound; insert into processing_result values('Processed employee #' || employee.employee_id || ': ' || employee.first_name || ' ' || employee.last_name); end loop; end; end; / |
using System; using System.Data; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; namespace CursorInCursorOut { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { // create connection to database // change for your environment string constr = "User Id=hr; Password=hr; Data Source=oramag; Pooling=false"; OracleConnection con = new OracleConnection(constr); con.Open(); // command and parameter objects to get ref cursor OracleCommand cmd = con.CreateCommand(); cmd.CommandText = "begin open :1 for select * from employees where manager_id=101; end;"; OracleParameter p_rc = cmd.Parameters.Add("p_rc", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output); // get the ref cursor cmd.ExecuteNonQuery(); // clear parameters to reuse cmd.Parameters.Clear(); // command and parameter objects to pass ref cursor // as an input parameter cmd.CommandText = "cursor_in_out.process_cursor"; cmd.CommandType = CommandType.StoredProcedure; OracleParameter p_input = cmd.Parameters.Add("p_input", OracleDbType.RefCursor, p_rc.Value, ParameterDirection.Input); // process the input cursor cmd.ExecuteNonQuery(); // clean up objects p_input.Dispose(); p_rc.Dispose(); cmd.Dispose(); con.Dispose(); } } } |
SQL> select * from processing_result; STATUS ---------------------------------------- Processed employee #108: Nancy Greenberg Processed employee #200: Jennifer Whalen Processed employee #203: Susan Mavris Processed employee #204: Hermann Baer Processed employee #205: Shelley Higgins 5 rows selected. |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者