创建返回结果集类型的存储过程:
CREATE OR REPLACE FUNCTION public.f_get_member_info(
id integer,
productname character)
RETURNS SETOF record
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
DECLARE
rec record;
BEGIN
for rec in EXECUTE 'select id, "productName" from "Products";'
loop
return next rec;
end loop;
return;
END;
$BODY$;
ALTER FUNCTION public.f_get_member_info(integer, character)
OWNER TO postgres;
如何调用存储过程返回结果集:
select * from f_get_member_info(4, 1, '', 'xxxx')
as member(member_num text,mname text,name text,discount_rate real,account numeric(16,2),integral int,phone text,birthday date,qq int,email text,onAccount int,status int,address text,tip text,start_date date,valid_date int,store_nam text);