-- Drop function top100cur (refcursor); Create Function top100cur (refcursor) returns refcursor as $ beginopen $1 for select * From person limit 100; return $1; end $ language plpgsql; ---------- test cursor ----------- select top100cur ('abc'); -- fetch all from ABC; -- drop function from2cur (refcursor, Int, INT ); -- This is a function that returns records within a certain range in the cursor -- create function from2cur (refcursor, Int, INT) returns setof text as $ declare -- declare some subscript variables PNAM text; PNO text; index int; lower int; upper int; beginindex: = 1; lower: = $2; upper: = $3; fetch $1 into PNAM, PNO; -- one item must be fetch first; otherwise, the found is falsewhile found loop -- only in [lower, upper] interval records are returned -- if lower <= index and upper> = index thenreturn next PNAM | PNO; end if; fetch $1 into PNAM, PNO; index: = index + 1; -- If index> upper then return; end if; end loop; end $ language plpgsql; select top100cur ('abc '); -- create a cursor named ABC -- fetch all in ABC; -- test the cursor select * From from2cur ('abc', 2, 5 );