【单个记录集】
-- FUNCTION: public.sp_testrecord(integer)
-- DROP FUNCTION public.sp_testrecord(integer);
CREATE OR REPLACE FUNCTION public.sp_testrecord(
p1 integer DEFAULT 0)
RETURNS SETOF record
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query select rid,game_id,game_name,is_show,order_id from game_list order by order_id asc limit p1;
end
$BODY$;
ALTER FUNCTION public.sp_testrecord(integer)
OWNER TO postgres;
select * from sp_testrecord(3)
as t(rid integer,game_id integer,game_name character varying,is_show integer,order_id integer);
【多个记录集】
-- FUNCTION: public.sp_testmultirecord(integer)
-- DROP FUNCTION public.sp_testmultirecord(integer);
CREATE OR REPLACE FUNCTION public.sp_testmultirecord(
p1 integer DEFAULT 0)
RETURNS SETOF refcursor
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
ref1 refcursor:='ref_version';
ref2 REFCURSOR:='ref_gamelist';
begin
open ref1 for select version();
return next ref1;
open ref2 for select * from game_list order by order_id asc limit p1;
return next ref2;
end
$BODY$;
ALTER FUNCTION public.sp_testmultirecord(integer)
OWNER TO postgres;
begin;
select sp_testmultirecord(3);
fetch all from "ref_version";
fetch all from "ref_gamelist";
commit;