1. 程式人生 > >在delphi中呼叫結果集的辦法

在delphi中呼叫結果集的辦法

create or replace package mypk
as
type t_cursor is ref cursor;
function func(a number) return t_cursor;
procedure proc(name varchar2,c out t_cursor,a number);
end;
/

create or replace package body mypk
as
function func(a number) return t_cursor
as
   v_temp t_cursor;
begin
   open v_temp for select * from test where id=a;
   return v_temp;
end func;
procedure proc(name varchar2,c out t_cursor,a number)
as
begin
open c for select * from test where id=a and name=name;
end proc;
end;
/
注意:ref cursor一定要在包中以type宣告,因為無法直接在func或proc中宣告ref cursor型別.

在delphi中呼叫時,除了要設定擴充套件屬性為PLSQLRSET=1外:
1.用adoquery時語句應該寫為query.sql.text:='{call mypk.func()}';其中'()'可以省略;
2.用adostoredproc時procedurename='mypk.func';
3.使用儲存過程返回結果集時在text中應該填入'{call mypk.proc(?,?)}',注意引數個數是除游標型別外的個數,順序是除游標型別外的變數次序.
4.對於過程或函式呼叫的寫法只能是'{call func/proc(?,?)}';