plpgsql - 如何从存储过程中返回参数和引用游标?

时间:2015-05-11 14:03:31

标签: postgresql stored-procedures plpgsql out-parameters ref-cursor

我想在我的应用程序中实现分页。 我创建了存储过程,返回记录数作为输出参数和ref游标数据本身(带限制和偏移) 但结果 - 我得到了 - "由于OUT参数"

功能结果类型必须为bigint

据我所知 - 它抱怨 out" _count" BIGINT 即可。

是否有从同一存储过程返回 out 参数和参考光标的情况?

  CREATE OR REPLACE FUNCTION aggr."GetPromotionsFull"("_limit" bigint, "_offset" bigint, out "_count" bigint)
  RETURNS refcursor AS   
$BODY$
DECLARE
      ref refcursor;    
BEGIN   

select count(1) into "_count" from aggr."Promotion" t 
inner join aggr."Company" c on t."CompanyId"=c."Id"  
   where 
   t."isDeleted"=false
  and c."isDeleted"=false;


  OPEN ref FOR
  SELECT t."Id",
  t."CompanyId",
  t."PromoName",
  t."Description",
  t."Url",
  t."ImgPath",
  t."CreatedDate",
  t."IsEnabled",
  t."isDeleted",
  c."Name"as "CompanyName"
  FROM aggr."Promotion" t
  inner join aggr."Company" c on t."CompanyId"=c."Id"  
   where 
   t."isDeleted"=false
   and c."isDeleted"=false
   limit "_limit" offset "_offset";

    RETURN ref;     
END
$BODY$
  LANGUAGE plpgsql VOLATILE

0 个答案:

没有答案