oracle|遊標 本例在VS2005+Oracle 92010 + WindowsXp Sp2測試通過1、建立一個遊標變數,為傳回值使用
create or replace package types as
type cursorType is ref cursor;
end;2、建立函數(或者預存程序)
create or replace function testpro return types.cursorType is
lc types.cursorType;
begin
open lc for select * from test;
return lc;
end testpro;3、編寫C#程式(注意:要先應用System.Data.OracleClient)
OracleConnection conn = new OracleConnection("YourConnectString"); OracleCommand cmd = new OracleCommand("testpro", conn); cmd.CommandType = CommandType.StoredProcedure; OracleParameter op = new OracleParameter("c", OracleType.Cursor); op.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(op); DataSet ds = new DataSet(); OracleDataAdapter da = new OracleDataAdapter(cmd); da.Fill(ds,"test"); this.dataGridView1.DataSource = ds.Tables["test"];PS:使用儲過程方法類似。